1
0

eeg_autocorr.m 554 B

123456789101112131415161718192021
  1. function resamp = eeg_autocorr(EEG, pct_data)
  2. if ~exist('pct_data', 'var') || isempty(pct_data)
  3. pct_data = 100;
  4. end
  5. % calc autocorrelation
  6. X = fft(EEG.icaact, 2^nextpow2(2*EEG.pnts-1), 2);
  7. c = ifft(mean(abs(X).^2, 3), [], 2);
  8. if EEG.pnts < EEG.srate
  9. ac = [c(:, 1:EEG.pnts, :) zeros(size(c, 1), EEG.srate - EEG.pnts + 1)];
  10. else
  11. ac = c(:, 1:EEG.srate + 1, :);
  12. end
  13. % normalize by 0-tap autocorrelation
  14. ac = bsxfun(@rdivide, ac, ac(:, 1));
  15. % resample to 1 second at 100 samples/sec
  16. resamp = resample(ac', 100, EEG.srate)';
  17. resamp(:, 1) = [];