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: This function is called by:

SUBFUNCTIONS ^

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));

Generated on Mon 28-Nov-2016 20:12:47 by m2html © 2005