[Eeglablist] Setting correct parameters for pop_eegfiltnew()

Cedric Cannard ccannard at protonmail.com
Mon Feb 27 13:50:54 PST 2023


Hi Alica,

Adding eeglablist again in case this is useful to someone else in the future.

> 1) For the 'hicutoff' and 'locutoff', do I use my cutoff frequencies (25 Hz and 1000 Hz), or do I use the passband edge frequencies (i.e., 25.5 Hz and 999.5 Hz)?

Try it and look at the outputs in the command window, it will tell you exactly what the cutoff is for what you selected.
Look also at the power spectra with:
figure; pop_spectopo(EEG, 1, [], 'EEG' , 'freqrange',[1 1100],'electrodes','off');

> 2) To create a notch filter instead of a bandpass filter, do I just need to set 'revfilt' as 1 (instead of the default 0)? I.e., for notch filtering out 57-63 Hz would the following syntax be correct?
> EEG = pop_eegfiltnew(EEG, 'locutoff', [], 'hicutoff', 57, 'filtorder', 16500, 'revfilt', 1)> EEG = pop_eegfiltnew(EEG, 'locutoff', 63, 'hicutoff', [], 'filtorder', 16500, 'revfilt', 1)

You can simply both filters like this:

- Bandpass (keep only this frequency band)
EEG = pop_eegfiltnew(EEG, 'locutoff',25,'hicutoff',1000,'filtorder',16500);

- Notch (remove only this frequency band and keep the rest)
EEG = pop_eegfiltnew(EEG, 'locutoff',57,'hicutoff',16500,'filtorder',16500,'revfilt',1,);

If this is for removing line noise, you can also use the cleanline or zapline plugins, they're probably better suited for this purpose.

Cedric

------- Original Message -------
On Monday, February 27th, 2023 at 12:04 PM, Alica Rogojin <arogojin at research.baycrest.org> wrote:

> Hi Cedric,
>
> Great, thank you for the resource! I've played around with the parameters, and confirmed that I need a filter older of 16,500 for my given sampling frequency and transition bandwidth. I had a couple of follow-up questions about the syntax for the pop_eegfiltnew function:
>
> 1) For the 'hicutoff' and 'locutoff', do I use my cutoff frequencies (25 Hz and 1000 Hz), or do I use the passband edge frequencies (i.e., 25.5 Hz and 999.5 Hz)?
>
> 2) To create a notch filter instead of a bandpass filter, do I just need to set 'revfilt' as 1 (instead of the default 0)? I.e., for notch filtering out 57-63 Hz would the following syntax be correct?
>>> EEG = pop_eegfiltnew(EEG, 'locutoff', [], 'hicutoff', 57, 'filtorder', 16500, 'revfilt', 1)
>>> EEG = pop_eegfiltnew(EEG, 'locutoff', 63, 'hicutoff', [], 'filtorder', 16500, 'revfilt', 1)
>
> Thanks again for your help,
> Alica
>
> On Fri, Feb 24, 2023 at 10:04 PM Cedric Cannard <ccannard at protonmail.com> wrote:
>
>> Hi Alica,
>>
>> You should find the information you need here: https://urldefense.com/v3/__https://eeglab.org/others/Firfilt_FAQ.html*q-what-are-passband-stopband-transition-bandwidth-cutoff-frequency-passband-rippleringing-and-stopband-rippleattenuation__;Iw!!Mih3wA!G94orONvmmE_oZWdYGFGQD-j7Z_njFY3KUqW9GNuw30VJ9wkORYzeJ1MsCVS_WV-k6DWTXn8haUgwhXx-qo6MyPjDQ$ 
>>
>> In brief, a notch filter is typically used to remove specific frequencies from a signal, while a bandpass filter is used to isolate a specific frequency range from a signal. But you can do both by applying a highpass and a lowpass filter one after the other, it's the same.
>>
>>> 3) Do I need to specify anything for usefft, plotfreqz, minphase, or
>> usefftfilt?
>> usefft would be if your filter order is very large and will save you significant computing time.
>> plotfreqz will show you what the filter is doing, you should give it a try and see the differences that your parameters have.
>> minphase if for causal filtering (crucial if you're looking at pre-stimulus activity for example; see link I sent there is abundant information from Andreas Widmann on all this).
>>
>> You can go to Tools > filter data > Windowed sync FIR filter and play with the parameters there (estimate order based on cutoff frequencies and transition bandwidths). However, you can just apply highpass 20 Hz and lowpass 1000 hz with the pop_eegfiltnew function (it will estimate the transition bandwidths and orders automatically). Then you can remove line noise with the cleanLine or zapline plugins.
>>
>> Whatever you do, plot the power spectra and compare before/after filtering to see what you are doing to the data.
>>
>> Cedric
>>
>> ------- Original Message -------
>> On Friday, February 24th, 2023 at 8:29 AM, Alica Rogojin <arogojin at research.baycrest.org> wrote:
>>
>>> Hi there,
>>>
>>> Apologies for the double email - I think I may have figured it out but was
>>> hoping to confirm that I did this correctly.
>>>
>>> fs = 5000; %5000 Hz sampling rate
>>> df = 1; %requested transition band width of 1Hz (I'm not sure if this is
>>> reasonable or if I should have a larger transition band)
>>> filter order = 3.3/(1/5000) = 16,500
>>>
>>> 1) Bandpass filter of 25 - 1000 Hz means lower passband edge = 25.5 Hz and
>>> upper passband edge = 999.5 Hz (based on transition band of 1Hz)
>>>
>>> > > EEG = pop_eegfiltnew(EEG, 'locutoff', [], 'hicutoff', 25.5, 'filtorder',
>>>
>>> 16500, 'revfilt', 0) --> will give a 25 Hz highpass with 25.5 Hz passband
>>>
>>> edge
>>>
>>> > > EEG = pop_eegfiltnew(EEG, 'locutoff', 999.5, 'hicutoff', [],
>>>
>>> 'filtorder', 16500, 'revfilt', 0) --> will give a 1000 Hz lowpass with
>>>
>>> 999.5 Hz passband edge
>>>
>>> 2) Then using same transition band for a notch filter, would I need to set
>>> 'revfilt' to 1?
>>> This is where things get a bit confusing but for a notch filter of of
>>> 57-63Hz, would I do the following:
>>>
>>> > > EEG = pop_eegfiltnew(EEG, 'locutoff', [], 'hicutoff', 57.5, 'filtorder',
>>>
>>> 16500, 'revfilt', 1)
>>>
>>> > > EEG = pop_eegfiltnew(EEG, 'locutoff', 62.5, 'hicutoff', [], 'filtorder',
>>>
>>> 16500, 'revfilt', 1)
>>>
>>> 3) Do I need to specify anything for usefft, plotfreqz, minphase, or
>>> usefftfilt?
>>>
>>> Thank you!
>>> Alica
>>>
>>> On Fri, Feb 24, 2023 at 10:25 AM Alica Rogojin <
>>> arogojin at research.baycrest.org> wrote:
>>>
>>> > Hi there,
>>> >
>>> > I'm trying to use pop_eegfiltnew to filter EMG data from a muscle in the
>>> > hand, sampling rate = 5000Hz. I'd like to apply a bandpass filter (low
>>> > cutoff = 25Hz, high cutoff = 1000Hz) and a notch filter (60Hz), and have
>>> > the following:
>>> >
>>> > Bandpass filter -
>>> >
>>> > > > EEG = pop_eegfiltnew(EEG, 'locutoff', 25, 'hicutoff', 1000);
>>> >
>>> > Notch filter (revfilt = 1 to change bandpass filter to be a notch filter)
>>> > -
>>> >
>>> > > > EEG = pop_eegfiltnew(EEG, 'locutoff', 57, 'hicutoff', 63, 'revfilt', 1);
>>> >
>>> > However, looking into more posts about pop_eegfiltnew I feel that I may
>>> > have oversimplified and there may be more to this. Did I do this correctly?
>>> >
>>> > According to https://sccn.ucsd.edu/pipermail/eeglablist/2017/012297.html,
>>> > the numbers I used above are not actually cutoff frequencies but are
>>> > passband edges. They also mention calculating transition band widths to
>>> > get the correct cutoff frequency to use in pop_eegfiltnew. I'm a bit
>>> > confused as to how to do this and would appreciate any pointers. Same for
>>> > the notch filter.
>>> >
>>> > I also saw posts mentioning that I should not be creating a bandpass
>>> > filter with high and low cutoffs in one - that I should be doing this in
>>> > separate lines. Is this true?
>>> >
>>> > I would appreciate any help! Thank you,
>>> > Alica
>>>
>>> _______________________________________________
>>> 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