mtfftc.m 1.0 KB

1234567891011121314151617181920212223
  1. function J=mtfftc(data,tapers,nfft,Fs)
  2. % Multi-taper fourier transform - continuous data
  3. %
  4. % Usage:
  5. % J=mtfftc(data,tapers,nfft,Fs) - all arguments required
  6. % Input:
  7. % data (in form samples x channels/trials or a single vector)
  8. % tapers (precalculated tapers from dpss)
  9. % nfft (length of padded data)
  10. % Fs (sampling frequency)
  11. %
  12. % Output:
  13. % J (fft in form frequency index x taper index x channels/trials)
  14. if nargin < 4; error('Need all input arguments'); end;
  15. data=change_row_to_column(data);
  16. [NC,C]=size(data); % size of data
  17. [NK K]=size(tapers); % size of tapers
  18. if NK~=NC; error('length of tapers is incompatible with length of data'); end;
  19. tapers=tapers(:,:,ones(1,C)); % add channel indices to tapers
  20. data=data(:,:,ones(1,K)); % add taper indices to data
  21. data=permute(data,[1 3 2]); % reshape data to get dimensions to match those of tapers
  22. data_proj=data.*tapers; % product of data with tapers
  23. J=fft(data_proj,nfft)/Fs; % fft of projected data