[Eeglablist] causal bandpassfilter with very low cutoff
Guillaume Lio
guillaume.lio at isc.cnrs.fr
Fri Aug 10 04:00:31 PDT 2012
Personally, I prefer IIR filters for some specific usages, when the
length of the data is low.
(e.g. for post-epoching filtering, controling border/edge effects).
Indeed, IIR filters can reach some particular filter specifications
(with fdatool for example) with lower order filters than with FIR filters.
IIR are also usefull in near real-time applications, like Brain Computer
Interfaces.
For standard EEG preprocessing, FIR filters have a lot of advantages, as
presented by Clemens.
But, just for precision, if most FIR filters have linear phase, complex
FIR filters with non-linear phase response can be designed (e.g. cfirpm
matlab function).
Guillaume.
PS :
I am also very interested by a short MATLAB code example about the DC
offset problem introduced by Andreas.
Le 10/08/2012 10:29, Clemens Brunner a écrit :
> Personally, I prefer FIR filters over IIR filters for the following reasons:
> * FIR filters are inherently stable
> * FIR filters can have linear phase
> * Minimum-phase FIR filters can have group delays that are comparable or even lower than IIR filters
> * FIR filters are robust to quantization
> * Most specialized hardware supports only FIR
>
> Sophie had problems with stability because she was designing an IIR filter. Had she used an FIR filter instead, she could have obtained a filter meeting the same specifications, but with guaranteed stability. IIR filters are useful when the goal is to minimize implementation costs. Since we are working with MATLAB and not with hardware, I don't think that we benefit from this property.
>
> Anyway, I don't want to start a flame war here, but I think FIR should remain the default filter type for EEG processing because of its many advantages. For special cases, IIR filters do also make sense. In addition, when using non-causal
>
> Clemens
>
> PS: Regarding filtfilt in MATLAB: of course you can use filtfilt for both FIR and IIR filters. Only if you are using the new object-oriented filter interface (fdesign or dfilt objects), then filtfilt won't work. filtfilt accepts input parameters only in the following forms: filtfilt(b, a, x) or filtfilt(sos, g, x).
>
> Andreas, could you please elaborate more on the problems when applying forward and reverse filtering to signals with DC offsets? I'd appreciate a short MATLAB code example.
>
>
>
>
> On Aug 9, 2012, at 11:26 PM, Andreas Widmann <widmann at uni-leipzig.de>
> wrote:
>
>> Hi,
>>
>> I plan to implement minimum-phase FIR conversion in the firfilt plugin (actually it is already written but needs some testing still).
>>
>> However, this is for sake of completeness only as minimum-phase FIR causal filtering will in most cases be inferior to IIR causal filtering (in electrophysiology). Both will have non-linear phase, but IIR has usually the smaller filter delay.
>>
>> Making filters zero-phase with the MATLAB filtfilt function is problematic not only with IIR, as noted by Guillaume, but also with FIR filters when large DC offsets are observed (as e.g. in BioSemi DC-recorded data). Padding with DC-constant and left-shifting the signal (as implemented in firfilt) instead of filtering backward with filtfilt is more robust.
>>
>> Best,
>> Andreas
>>
>> Am 09.08.2012 um 20:50 schrieb Makoto Miyakoshi <mmiyakoshi at ucsd.edu>:
>>
>>> Dear Guillaume and Clemens,
>>>
>>>> If you want to do the same procedure with IIR filters, you have to use
>>>> the filtfiltHD function.
>>> Actually I tested it with Clemens Brunner (who suggested fir1 instead
>>> of firls, and now fir1 is the default). We confirmed two things.
>>>
>>> 1. EEGLAB's IIR filter plug-in uses filtfilt, so it is a zero-phase filter.
>>> 2. EEGLAB's filter option 'causal' does not use a minimum-phase
>>> filter; this option does not preserve the rise onset, which is
>>> discussed in Rousselet (2012) 'Does filtering preclude us from
>>> studying ERP time-courses?'
>>>
>>> I'm not a filter expert. Would you help me Clemens?
>>>
>>> Makoto
>>>
>>>
>>>
>>> 2012/8/9 Guillaume Lio <guillaume.lio at isc.cnrs.fr>:
>>>>
>>>>
>>>> Dear Davide,
>>>>>> I don't understand why to use a IIR filter. They always cause some (phase) distorsion.
>>>>> Is it true even with filtfilt?
>>>>>
>>>>> Makoto
>>>> Causal filters always cause phase distortions.
>>>> FIR filters cause linear phase distortions.
>>>> IIR filters cause non-linear phase distortions.
>>>>
>>>> The filtfilt procedure makes filters not causal to produce zero-phase
>>>> filters.
>>>> But, the matlab built-in filtfilt fonction works only with FIR filters.
>>>>
>>>> If you want to do the same procedure with IIR filters, you have to use
>>>> the filtfiltHD function.
>>>> filtfiltHD function can be found here :
>>>> http://www.mathworks.com/matlabcentral/fileexchange/17061-filtfilthd
>>>>
>>>> Hope this help.
>>>>
>>>> Guillaume Lio
>>>>
>>>>
>>>>
>>>>
>>>>> 2012/8/8 Davide Baldo <davidebaldo84 at gmail.com>:
>>>>>> Hi!
>>>>>>
>>>>>> I don't understand why to use a IIR filter. They always cause some (phase)
>>>>>> distorsion.
>>>>>> I suggest you to use a FIR filter. If you use Matlab, just type "fdatool"
>>>>>> (Filter design & analysis tool). Than select: High pass and FIR
>>>>>> (Equiripple). Set the Srate to 512 and the Fstop to 0.01. You did not
>>>>>> specfied which frequencies you do not want to distort. I guess you could set
>>>>>> Fpass to 0.5 Hz (all frequencies higher than 0.5 Hz won't be modified). Then
>>>>>> set Dstop to 0.0005 and Dpass to 0.01.
>>>>>> Now you can click on Design Filter. When done...click on File -> Export (It
>>>>>> export the filter on Matlab workspace). Set Numerator to "HP_Filter" (it s
>>>>>> just a name for the filter).
>>>>>>
>>>>>> Now you are ready to filter your data:
>>>>>>
>>>>>> HP_Delay = round( mean(grpdelay(HP_filter)) ); % a FIR filter introduces
>>>>>> a delay in the signal. you need to compensate it.
>>>>>>
>>>>>> HP_Data = filter( HP_filter, 1, your_data ) ; % Filter the data
>>>>>> HP_Data = circshift( HP_Data , [1 -HP_Delay] ); %compensate the delay
>>>>>> introduced by the HP filter
>>>>>>
>>>>>> I hope it helps you.
>>>>>>
>>>>>> Ciao!
>>>>>>
>>>>>> Davide.
>>>>>>
>>>>>> On Mon, Aug 6, 2012 at 6:38 PM, Andreas Widmann <widmann at uni-leipzig.de>
>>>>>> wrote:
>>>>>>> Hi Sophie,
>>>>>>>
>>>>>>> a 0.01 Hz highpass filter with 512 Hz sampling frequency is very extreme.
>>>>>>> My personal rule of thumb is that the srate / cutoff ratio for IIR highpass
>>>>>>> filtering should not be much higher than ~1000 (acknowledgement to BM). The
>>>>>>> problem is increased by the EEGLAB default estimation of required filter
>>>>>>> order by a very narrow transition band (defined as cutoff/3 in your case;
>>>>>>> the help text in pop_iirfilt is wrong!). The extreme filter cutoff with
>>>>>>> narrow transition band requires a high filter order (here 6), but the
>>>>>>> resulting 6th order filter is instable.
>>>>>>>
>>>>>>> I would suggest first downsampling the data to an as low as possible
>>>>>>> sampling frequency (after lowpass filtering the data to 1/4-1/5 of new
>>>>>>> sampling frequency!).
>>>>>>>
>>>>>>> Then, I would suggest filtering the data with a butterworth filter at 0.1
>>>>>>> Hz cutoff frequency. Roll-off is a function of filter order (approx. order
>>>>>>> times -6dB/octave).
>>>>>>> E.g.:
>>>>>>>>> [b, a] = butter(4, 0.1 / (srate / 2), 'high')
>>>>>>> for a forth order filter.
>>>>>>>
>>>>>>> Check frequency response with
>>>>>>>>> freqz(b, a, 2^14, srate)
>>>>>>> At 256 Hertz this gives a reasonable frequency response and very good DC
>>>>>>> attenuation. Downsampling your data to 128 Hz you can use the same filter
>>>>>>> for a 0.05 Hz highpass.
>>>>>>>
>>>>>>> Check filter stability with
>>>>>>>>> zplane(b, a)
>>>>>>> All poles should be inside the unit circle. If you test the 6th order
>>>>>>> butterworth filter you will see that also this filter is instable.
>>>>>>>
>>>>>>> Causal filtering can be done easily on the command line using the MATLAB
>>>>>>> built in filter function. Take care not to filter across boundaries/DC
>>>>>>> offsets! Filter each segment separately.
>>>>>>>
>>>>>>> Hope this helps, best,
>>>>>>> Andreas
>>>>>>>
>>>>>>> Am 06.08.2012 um 17:44 schrieb Sophie Herbst <ksherbst at googlemail.com>:
>>>>>>>
>>>>>>>> Hi EEGlablist,
>>>>>>>>
>>>>>>>> I am trying to apply a causal bandpass filter with a very low cutoff
>>>>>>>> (0.01Hz) to my EEG data (continuos data with ~2,700,000 points, srate =
>>>>>>>> 512Hz)
>>>>>>>> by using iirfilt.m:
>>>>>>>>
>>>>>>>> iirfilt(EEG.data, EEG.srate, 0.01, 40, 0, 0, 0, [], [], 'on')
>>>>>>>>
>>>>>>>> I seem to run into similar problems as described in EEGLAB Bug #1011:
>>>>>>>> the default values for transition bandwidth and passband/ stopband ripple do
>>>>>>>> not seem to work as
>>>>>>>> the filter runs but leaves a matrix of NaNs.
>>>>>>>>
>>>>>>>> I have been playing around with values for the transition bandwidth etc,
>>>>>>>> but I could not get a satisfying frequency response.
>>>>>>>> Any idea why this is and which filter would be better to use?
>>>>>>>>
>>>>>>>> Thanks a lot,
>>>>>>>> Sophie
>>>>>>> _______________________________________________
>>>>>>> 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
>>>>>>
>>>>>> _______________________________________________
>>>>>> 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
>>>>>
>>>> _______________________________________________
>>>> 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
>>>
>>>
>>> --
>>> Makoto Miyakoshi
>>> JSPS Postdoctral Fellow for Research Abroad
>>> Swartz Center for Computational Neuroscience
>>> Institute for Neural Computation, University of California San Diego
>>> _______________________________________________
>>> 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
>>>
>
> _______________________________________________
> 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