Home > NoiseTools > nt_mmat.m

# nt_mmat

## PURPOSE

y=nt_mmat(x,m) - matrix multiplication (with convolution)

## SYNOPSIS

function y=nt_mmat(x,m)

## DESCRIPTION

    y=nt_mmat(x,m) -  matrix multiplication (with convolution)

      y: result

      x: input data (2D or more)
      m: matrix to apply (2D: right multiply, 3D: same with convolution)

      If m is 3D, the last index (k) is lag.

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_fold y=fold(x,epochsize) - fold 2D to 3D
- nt_mmat y=nt_mmat(x,m) - matrix multiplication (with convolution)
- nt_unfold y=nt_fold(x) - unfold 3D to 2D

This function is called by:

- nt_bias_cluster [c0,c1,A,todss,pwr0,pwr1]=nt_bias_cluster(x,dsr,flags) - cluster covariance
- nt_cca_aad [D,E,R]=nt_cca_match_aad(xA,xB,y,ssize) - calculate metrics for match-mismatch task
- nt_cca_crossvalidate [AA,BB,RR,iBest]=nt_cca_crossvalidate(xx,yy,shifts,ncomp,A0,B0) - CCA with cross-validation
- nt_cca_crossvalidate2 [A,B,RR]=nt_cca_crossvalidate2(xx,yy,shifts) - CCA with cross-validation
- nt_cca_mm [D,E,R]=nt_cca_match_mm3(x,y,ssize) - calculate metrics for match-mismatch task
- nt_cluster_jd [IDX,todss,SCORE,COVS]=nt_cluster_jd(x,dsr,smooth,flags,init,verbose) - cluster with joint diagonalization
- nt_dprime [d,e]=nt_dprime(x,y,jd_flag) - calculate d' (discriminability) of two distributions
- nt_dprime_old [d,err_rate,perm]=nt_dprime(x,y,jd_flag) - calculate d' (discriminability) of two distributions
- nt_dss1 [todss,pwr0,pwr1]=nt_dss1(x,w,keep1,keep2) - evoked-biased DSS denoising
- nt_dss_repeat_cluster y=nt_dss_repeat_cluster(x,nkeep,cluster_size) - dss within clusters
- nt_mmat y=nt_mmat(x,m) - matrix multiplication (with convolution)
- nt_narrowband_scan A=nt_narrowband_scan(x,freqs,sr,Q,plotflag) - scan for narrowband components using DSS
- nt_pca0 [topcs,pwr,y]=nt_pca0(x,shifts,nkeep,threshold,w) - time-shift pca
- nt_pca_kmeans [topcs,pwr]=nt_pca_kmeans(x,nkeep) - PCA preceded by kmeans for speed
- nt_qca [squares,quads,D]=nt_qca(x,npcs,nsmooth,nquads) - maximize induced power using quadratic component analysis
- nt_qca0 [tosquares,quads,D]=nt_qca0(x,npcs,nsmooth,nquads) - maximize induced power using quadratic component analysis
- nt_qca02 [tosquare,quad,tosquare2,quad2,D]=nt_qca02(x,npcs,nsmooth) - maximize induced power using quadratic component analysis
- nt_qca2 [square,quad,square2,quad2,D]=nt_qca(x,npcs,nsmooth) - maximize induced power using quadratic component analysis
- nt_qpca [squares,quads]=nt_qpca(x,npcs,nsmooth,nquads) - quadratic PCA
- nt_qpca0 [tosquares,quads,D]=nt_qpca0(x,npcs,nsmooth,nquads) - quadratic PCA
- nt_split_jd [idx,score_vector,todss]=nt_split_dss(x,thresh,depth) - segmentation based on joint diagonalization
- nt_zapline [y,yy]=nt_zapline(x,fline,nremove,p,plotflag) - remove power line artifact

## SUBFUNCTIONS

- function x=nt_mmat0(x,m)

## SOURCE CODE

    0001 function y=nt_mmat(x,m)
    0002 %y=nt_mmat(x,m) -  matrix multiplication (with convolution)
    0003 %
    0004 %  y: result
    0005 %
    0006 %  x: input data (2D or more)
    0007 %  m: matrix to apply (2D: right multiply, 3D: same with convolution)
    0008 %
    0009 %  If m is 3D, the last index (k) is lag.
    0010
    0011 if nargin<2; error('!'); end
    0012
    0013 if iscell(x)
    0014     for iCell=1:length(x)
    0015         y{iCell}=nt_mmat(x{iCell},m);
    0016     end
    0017     return;
    0018 end
    0019
    0020 if ndims(x)>3
    0021     % concatenate the last dimensions, process, then de-concatenate
    0022     sz=size(x);
    0023     x=reshape(x,[sz(1),sz(2),prod(sz(3:end))]);
    0024     x=nt_mmat(x,m);
    0025     x=reshape(x,[size(x,1),sz(2),sz(3:end)]);
    0026
    0027 else
    0028
    0029     if ndims(m)==2;
    0030         % no convolution
    0031         y=nt_mmat0(x,m);
    0032
    0033     else
    0034
    0035 % does anyone use this ?????
    0036
    0037         [nRows,nCols,nLags]=size(m);
    0038         [nSamples,nChans,nTrials]=size(x);
    0039         if nChans~=nRows;
    0040             error('ncols(x) ~= nrows(m)');
    0041         end
    0042         % convolution: for each k, multiply x by m(:,:,k) and add with
    0043         % shift of (k-1)
    0044         y=zeros(nSamples+nLags-1,nCols,nTrials);
    0045         for iLag=1:nLags
    0046             y(iLag:iLag+nSamples-1,:,:) = y(iLag:iLag+nSamples-1,:,:) + nt_mmat0(x,m(:,:,iLag));
    0047         end
    0048
    0049     end
    0050 end
    0051
    0052 function x=nt_mmat0(x,m)
    0053 x=nt_fold(nt_unfold(x)*m,size(x,1));