Home > NoiseTools > nt_qpca.m

# nt_qpca

## PURPOSE

[squares,quads]=nt_qpca(x,npcs,nsmooth,nquads) - quadratic PCA

## SYNOPSIS

function [squares,quads,D]=nt_qpca(x,npcs,nsmooth,nquads)

## DESCRIPTION

    [squares,quads]=nt_qpca(x,npcs,nsmooth,nquads) - quadratic PCA

      squares: linear components closest to largest quadratic component
      quads: largest quadratic component(s)
      D: eigenvalues

      x: data (time*channel*trial)
      npcs: maximum number of data PCs to use [default: all]
      nsmooth: square smoothing window to apply to xproducts [default: 1]
      nquads: number of quadratic components to return [default: 1]

     NoiseTools.

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_demean2 y=nt_demean2(x,w) - remove mean of each row and page
- nt_mmat y=nt_mmat(x,m) - matrix multiplication (with convolution)
- nt_qpca0 [tosquares,quads,D]=nt_qpca0(x,npcs,nsmooth,nquads) - quadratic PCA

This function is called by:

## SOURCE CODE

    0001 function [squares,quads,D]=nt_qpca(x,npcs,nsmooth,nquads)
    0002 %[squares,quads]=nt_qpca(x,npcs,nsmooth,nquads) - quadratic PCA
    0003 %
    0004 %  squares: linear components closest to largest quadratic component
    0005 %  quads: largest quadratic component(s)
    0006 %  D: eigenvalues
    0007 %
    0008 %  x: data (time*channel*trial)
    0009 %  npcs: maximum number of data PCs to use [default: all]
    0010 %  nsmooth: square smoothing window to apply to xproducts [default: 1]
    0011 %  nquads: number of quadratic components to return [default: 1]
    0012 %
    0013 % NoiseTools.
    0014
    0015
    0016 if nargin<4||isempty(nquads); nquads=1; end
    0017 if nargin<3||isempty(nsmooth); nsmooth=1; end
    0018 if nargin<2; error('!'); end
    0019 [nsamples,nchans,ntrials]=size(x);
    0020
    0021 x=[x,ones(nsamples,1,ntrials)*max(abs(x(:)))]; % append a DC component to absorb DC
    0022
    0023 if nargout==1;
    0024     tosquares=nt_qpca0(x,npcs,nsmooth,nquads);
    0025 else
    0026     [tosquares,quads,D]=nt_qpca0(x,npcs,nsmooth,nquads);
    0027     quads=quads(:,2:end,:); % discard first (DC)
    0028 end
    0029
    0030 squares=nt_mmat(x,tosquares);
    0031 squares=nt_demean2(squares);
    0032
    0033
    0034
    0035
    0036