[Eeglablist] causal bandpassfilter with very low cutoff

Davide Baldo davidebaldo84 at gmail.com
Fri Aug 10 02:55:50 PDT 2012


You are right..thanks for the note
Il giorno 10/ago/2012 11:41, "Clemens Brunner" <clemens.brunner at tugraz.at>
ha scritto:

> Just a small note: the phase response of a FIR filter is _not_ always
> linear, but it _can_ be linear. Minimum-phase FIR filters do not have
> linear phase. On the other hand, the phase response of an IIR filter can
> _never_ be linear.
>
> I'm also interested in Andreas's response.
>
> Clemens
>
>
>
> On Aug 10, 2012, at 10:13 AM, Davide Baldo <davidebaldo84 at gmail.com>
> wrote:
>
> > I would like to ask you, which are the parameters you take under
> consideration to decide whether filter your data with a IIR or FIR filter.
> >
> > summarizing the information regarding these filters:
> >
> > IIR filter: The phase response of a IIR filter is not linear. This would
> always distorts the signal, unless the data are filtered back and forward
> via filtfilt Matlab function (this is of course possible only via off-line
> processing)
> >
> > FIR filter: The phase response of a FIR filter is always linear, thus
> the group delay of a FIR filter is constant number. That means that all the
> frequencies of the filtered data have been delayed by the same amount of
> time (might be several seconds). Since the delayed introduced by the FIR
> filter is exactly half of its length, it can be exactly compensated without
> the need of use filtfilt (again this is possible on via off-line processing)
> >
> > From my point of view both these solutions work (I mean it s possible to
> get to the same output both via a IIR filter using filtfilt and via a FIR
> filter using filter and compensating the delay introduced by the filter).
> >
> > I would like to know if and why do you prefer one of these two types of
> filters.
> >
> > Thanks a lot!
> >
> > Davide.
> >
> > On Fri, Aug 10, 2012 at 8:26 AM, Arnaud Delorme <arno at ucsd.edu> wrote:
> > Hi Sophie and David,
> >
> > Butterworth is available in EEGLAB from the command line (eegfiltsig
> function) and from the ERPLAB plugin of EEGLAB (which does not require
> ERPLAB itself and is installed by default when you download EEGLAB).
> >
> > In the most recent version of EEGLAB (to be released this month), we
> have replaced the default FIR filter by Andreas Widmann optimized filter
> functions (in the firfilt plugin). This fixes several minor issues such as
> sometimes non-optimal widths for the transition bandwidth. It is also more
> flexible and has many more options for plotting the filter properties. Note
> that all scripts will remain backward compatible.
> > Thanks,
> >
> > Arno
> >
> > On Aug 9, 2012, at 2:20 PM, David Acunzo wrote:
> >
> >> Hi Sophie,
> >>
> >> To design your IIR filter, you can use the buttord function (or
> ellipord, etc. for filters that are not Butterworth).
> >> To avoid roundoff errors and therefore instability or NaNs, you may
> want to use the zero-pole-gain filter design (see the examples in
> http://www.mathworks.co.uk/help/toolbox/signal/ref/butter.html for
> Butterworth filters), which is, I think, not used in the IIR filters
> available in EEGlab.
> >>
> >> Hope that helps.
> >>
> >> Best,
> >> David
> >>
> >>
> >> On 8 Aug 2012, at 14:58, Sophie Herbst wrote:
> >>
> >>> Hi again,
> >>> thank you for your very helpful comments. Andreas, I was trying to
> implement your suggestion but can't quite get it to work.
> >>> After low-pass filtering (30Hz), downsampling (128Hz), the butterworth
> filter you suggested transforms large parts of the data into NaNs.
> >>> I think it might already go wrong with the low-pass filter. Do you
> have a suggestion what to use here? It should also be causal, so I tried
> both iirfilt and butter but apparently I was not able to put together the
> right combination of parameters.
> >>>
> >>> Sorry for being so ignorant but my understanding of filtering is at a
> very early stage.
> >>> Sophie
> >>>
> >>>
> >>>
> >>>
> >>> On Wed, Aug 8, 2012 at 12:13 PM, Andreas Widmann <
> widmann at uni-leipzig.de> wrote:
> >>> Hi,
> >>>
> >>> Sophie asked for a *causal* filter. IIR is an appropriate filter type
> for this purpose. Using a linear phase FIR filter, as suggested, one will
> introduce a long filter delay. Using a minimum-phase FIR filter one will
> loose linear phase anyway. Thus, it is reasonable to use IIR as the filter
> delay is usually considerably smaller than for minimum-phase FIR in this
> type of application. (I have a slight preference for Butterworth due to its
> good (flat) frequency response in the passband.)
> >>>
> >>> See also recent contribution on causal filtering by Rousselet:
> >>>
> http://www.frontiersin.org/Perception_Science/10.3389/fpsyg.2012.00131/full
> >>> and my short comment (mainly focused on why one should not use the
> EEGLAB Basic FIR filter)
> >>>
> http://www.frontiersin.org/Perception_Science/10.3389/fpsyg.2012.00233/full
> >>>
> >>> Best,
> >>> Andreas
> >>>
> >>> Am 08.08.2012 um 10:17 schrieb 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
> >>
> >> The University of Edinburgh is a charitable body, registered in
> >> Scotland, with registration number SC005336.
> >>
> >> _______________________________________________
> >> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sccn.ucsd.edu/pipermail/eeglablist/attachments/20120810/e6451037/attachment.html>


More information about the eeglablist mailing list