Hi,
I have a few questions about certain processing techniques used to increase frequency resolution and maximum frequency band with small epochs. These are admittedly two separate topics so I apologize for putting them in one post, but I do think both topics are worth considering for how to manage power spectra with small epochs.
Zero Padding:
1. Given that zero padding will create big jumps in the EEG signal prior to the first sample of the data and at the last sample of the data, why not pad pre-epoch at the amplitude of the first sample and post-epoch at the amplitude of the last sample? So for instance, if the first sample in an epoch has an amplitude of 30 and the last sample 20, why not pad pre-epoch with 30's and post-epoch with 20's?
2. In the below code*, N is the number of samples per epoch prior to zero-padding, so the actual range of frequencies doesn't change. I think this is correct, but do I still divide fft(data) by N on line 56, or should that be size(data,2), or in other words the length after zero-padding?
3. Likewise, what would be the appropriate way to scale the frequency band with the power spectrum? For instance, on line 65 I do the following:
fft_subset = abs(fft_data(:,1:size(fft_data,2)/2+1,:)).^2;
Where, had I not zero-padded, I would have done the following:
fft_subset = abs(fft_data(:,1:N/2+1,:)).^2;
My thought process is that the range of the power spectrum which corresponds to the frequency band should still be the length of the zero-padded fft_data/2+1. However, I'm not sure if my math is quite right, and maybe it's a bit more complicated than that...
Epoch-reflection
In this paper (
http://www.sciencedirect.com/science/article/pii/S096098221501235X?via%3Dihub), in which you are cited and acknowledged, the authors reflect their epochs, essentially doubling the length of an epoch and making it symmetrical. However, I was under the impression that this sort of epoch concatenation could be problematic for producing a good power spectrum. Is there something that makes this method acceptable, as opposed to just concatenating multiple unrelated trials? Are there any particular considerations that should be taken with this method?
Thanks,
Max
*
data = EEG.data(ROI,:,:); % data across all trials continuously
srate = EEG.srate; % sampling rate in Hz
nyquist = srate/2; % Nyquist frequency -- the highest frequency you can measure in the data
N = size(data,2); % length of sequence (prior to zero-padding)
% Still using N prior to zero-padding because zero-padding should only
% increase frequency resolution, not frequency range
%% Zero-pad to get resolution of freqres
freqres = 0.25;
% The number of samples per epoch necessary, given the sampling rate, to get the frequency resolution freqres
nFFT = ceil(srate/freqres);
pad_idx = (nFFT-N)/2;
% Pads each trial to enough samples to gain the frequency resolution of freqres, half at the front and half at the end
data = padarray(data, [0 pad_idx 0], 0, 'both');
% The number of unique frequencies we can measure is
% exactly 1/2 of the number of data points in the time series (plus DC).
frequencies = linspace(0,nyquist,(N/2)+1);
%% FFT
fft_data = fft(data,[],3)/N; % Fast fouriet transform
if avg == 1
fft_data = mean(fft_data,1);
end
freqband = frequencies(frequencies >= freqrange(1) & frequencies <= freqrange(2)); % Subset frequencies to inputted range
freqband_start = find(frequencies >= freqrange(1),1);
freqband_end = find(frequencies <= freqrange(2),1, 'last');
fft_subset = abs(fft_data(:,1:size(fft_data,2)/2+1,:)).^2;
% Using size(fft_data,2) rather than N because the pwspctrm length is
% a reflection of increased resolution rather than frequency range, so
% subsetting up to size(fft_data,2)/2+1 has the equivalent effect as
% subsetting up to N/2+1 with non-zero-padded fft_data
% zero-padding may not work and b) that what I'm doing above may not be
% correct
fft_subset = fft_subset(:,pad_idx+freqband_start:pad_idx+freqband_end,:); % Subsets to the inputted frequency range
% Accounts for zero-padding by adding the padding index (1/2 the total
% padding since it's pre and post) to the start and end frequencies
fft_subset = mean(fft_subset,3); % Average across all trials