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 ndims(x)>3
0014     % concatenate the last dimensions, process, then de-concatenate
0015     sz=size(x);
0016     x=reshape(x,[sz(1),sz(2),prod(sz(3:end))]);
0017     x=nt_mmat2(x,m);
0018     x=reshape(x,[size(x,1),sz(2),sz(3:end)]);
0019 
0020 else
0021 
0022     if ndims(m)==2;
0023         % no convolution
0024         y=nt_mmat0(x,m); 
0025     
0026     else
0027 
0028         [nRows,nCols,nLags]=size(m);
0029         [nSamples,nChans,nTrials]=size(x);
0030         if nChans~=nRows; 
0031             error('ncols(x) ~= nrows(m)');
0032         end
0033         % convolution: for each k, multiply x by m(:,:,k) and add with
0034         % shift of (k-1)
0035         y=zeros(nSamples+nLags-1,nCols,nTrials);
0036         for iLag=1:nLags
0037             y(iLag:iLag+nSamples-1,:,:) = y(iLag:iLag+nSamples-1,:,:) + nt_mmat0(x,m(:,:,iLag));
0038         end
0039         
0040     end
0041 end    
0042 
0043 function x=nt_mmat0(x,m)
0044 x=nt_fold(nt_unfold(x)*m,size(x,1));

Generated on Mon 10-Nov-2014 14:40:42 by m2html © 2005