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         
0031         % no convolution
0032         y=nt_mmat0(x,m); 
0033     
0034     else
0035         
0036 % does anyone use this ?????
0037 
0038         [nRows,nCols,nLags]=size(m);
0039         [nSamples,nChans,nTrials]=size(x);
0040         if nChans~=nRows; 
0041             error('ncols(x) ~= nrows(m)');
0042         end
0043         % convolution: for each k, multiply x by m(:,:,k) and add with
0044         % shift of (k-1)
0045         y=zeros(nSamples+nLags-1,nCols,nTrials);
0046         for iLag=1:nLags
0047             y(iLag:iLag+nSamples-1,:,:) = y(iLag:iLag+nSamples-1,:,:) + nt_mmat0(x,m(:,:,iLag));
0048         end
0049         
0050     end
0051 end    
0052 
0053 function x=nt_mmat0(x,m)
0054 x=nt_fold(nt_unfold(x)*m,size(x,1));

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005