[Eeglablist] anti-aliasing with downsampling?
Andreas Widmann
widmann at uni-leipzig.de
Fri Nov 6 02:07:51 PST 2015
Dear Lucia,
> - By "introduce many/extra frequencies", I mean e.g. between 30-40Hz, there are several peaks in the final plot (after downsampling), which aren't evident in either of the first two plots.
Ok, these additional peaks just „disappear“ due to the extremely low spectral resolution of pop_spectopo with high sampling rates due inappropriate defaults in the underlying spectopo function (imho). With 5kHz sampling rate and default options you get frequency sampling points (in the ~30-40 Hz you are looking at) at 29.3, 34.2 and 39.1 Hz and a straight line between these points. Thus, peaks cannot be visible.
You can adjust the relevant parameters 'winsize', 'nfft' (or 'freqfac') on the command line in pop_spectopo (forwarded to spectopo). I would suggest to start with 10000 for both winsize and nfft giving you a spectral resolution of 0.5 Hz. If this is too slow you could also try 8192 or 16384 (again for both).
pop_spectopo(EEG, 1, [], 'EEG', 'winsize', 10000, 'nfft', 10000, 'freqrange', [0 100]);
Now you should see the peaks in the 30-40 Hz range. You could then compare this to the output of
pop_spectopo(EEG, 1, [], 'EEG', 'winsize', 500, 'nfft', 500, 'freqrange', [0 100]);
for the 250 Hz downsampled data.
> Images are found: http://postimg.org/image/97w6davr1/
>
> 1st one is high pass filtered (still sampled at 5000Hz) at 0.5Hz.
> 2nd is low pass filtered (on top of the high pass filtering) at 70Hz.
> 3rd one is after downsampling to 250Hz
The plots look ok. No problems with filtering or downsampling. Good!
> There is a little residual signal >70Hz after filtering - does that imply that the filtering hasn't completely worked?
No, this is ok. The default transition width in pop_eegfiltnew is 25% of 70 Hz. In pop_eegfiltnew you specify passband edges (rather than cutoff frequency) so the stopband starts at 87.5 Hz. That you still see a noise floor above 87.5 Hz is due to the default hamming window in pwelch allowing a small amount of spectral leakage. To evaluate the effects of filtering you might either more aggressively highpass filter the data (not recommended) or use a window type avoiding spectral leakage (e.g. hanning or blackmanharris). pop_spectopo/spectopo does not allow to adjust the window type so you have to use pwelch:
pwelch(EEG.data', hanning(winsize), 0, nfft, EEG.srate)
or
pwelch(EEG.data', blackmanharris(winsize), 0, nfft, EEG.srate)
with the winsize and nfft values from above. Now you should see full attenuation (>= -53 dB relative to unfiltered) in the stopband.
> I note that there do not seem to be in extra frequencies in the plots after downsampling - does that mean the pop_spectopo function plots applies a different function than pwelch?
No, pop_spectopo uses pwelch if Signal processing toolbox is present. But by default it uses fixed winsize of 512 and nfft of 1024 independent of sampling rate resulting in very poor spectral resolution for higher sampling rates. I would consider this as a bug (and you might consider submitting a bug report to the EEGLAB bugtracker). However, maybe I do not see some implications/restrictions and other opinions are welcome. Actually, I also would recommend using overlap larger than default 0 (e.g. 50 % of winsize).
Hope this helps,
Andreas
> Many thanks again for your advice.
>
> Kind regards,
> Lucia
>
>
> ________________________________________
> From: Andreas Widmann [widmann at uni-leipzig.de]
> Sent: Monday, November 02, 2015 11:02 AM
> To: Li, Lucia M
> Cc: eeglablist at sccn.ucsd.edu
> Subject: Re: [Eeglablist] anti-aliasing with downsampling?
>
> Hi Lucia,
>
> the effects of 40Hz lowpass filtering do not look right/as expected, so I would like to have a look into the issue. Several questions have to be addressed first.
>
> * Please (always) state EEGLAB version. There have been substantial changes in the resampling function recently and it might be relevant whether you use the old or the new code.
> * Please all all spectopo options you used to make the plot (optimally command line version from eegh).
> * Please explain what you mean by „introduce many frequencies“/„extra frequencies“.
>
> Preliminary comments:
> (a) spectopo unfortunately uses a fixed length fft (1024). Thus, frequency axis sampling depends on sampling rate. With 5000 Hz you get a frequency sampling point every 4.9 Hz (5000/1024); with 250 Hz you get a frequency sampling point every 0.24 Hz. So, in your Figure 6 the frequency axis is sampled 20 times higher. I case you mean with „extra frequencies“ that you see more details, this is most likely due to the higher frequency axis sampling. (I will try to have a look into the spectopo code in the next weeks to see how difficult it would be to introduce a fft length option).
> (b) The (MATLAB implementation of the) pwelch method used in spectopo is susceptible to frequency noise/rounding errors introduced by DC offsets. You might want to try to apply a highpass filter before frequency analysis.
> (c) The 40 lowpass filter appears to have no/little effect. I would like to sort out (a) and (b) before looking into this.
>
> Please highpass filter you raw dataset (e.g. 0.1 Hz) and upload the following plots:
> figure, pwelch(EEG.data', [], [], 10240, 5000); xlim([0 0.07]) % or xlim([0 70]) in case the frequency axis is automatically scaled to Hz instead of kHz
> and the same figure after lowpass filtering and
> figure, pwelch(EEG.data', [], [], 512, 250); xlim([0 70])
> after downsampling to 250 Hz.
>
> Best,
> Andreas
>
>> Am 30.10.2015 um 12:05 schrieb Li, Lucia M <lucia.li at imperial.ac.uk>:
>>
>> Dear EEGlab users & experts,
>>
>> I was hoping someone might be able to shed some light how why downsampling my data appears to introduce many frequencies into it.
>>
>> http://s8.postimg.org/ah6vqvaut/Screen_Shot_2015_10_30_at_10_59_35.png
>>
>> I have acquired some EEG data at 5000Hz (figure 2). I acquired this with Brain Products and exported the data without doing anything to it, to use in eeglab.
>> I then lowpass filtered it at 40Hz in eeglab (using the Tools --> filter data --> basic FIR filter (new, default)) (figure 5).
>> I then downsampled it to 250Hz (Tools --> change sampling rate) and get the resultant spectral plot (figure 6).
>>
>> I was wondering:
>> a) are these extra frequencies indicative of anti-aliasing? If not, what might they indicate?
>> b) why am I still getting anti-aliasing effects if I downsampled after a low pass filter?
>>
>> Many thanks in advance for your help!
>> Kind regards,
>> Lucia
>>
>>
>> _______________________________________________
>> Eeglablist page: http://sccn.ucsd.edu/eeglab/eeglabmail.html
>> To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu
>> For digest mode, send an email with the subject "set digest mime" to eeglablist-request at sccn.ucsd.edu
>
>
More information about the eeglablist
mailing list