filtfilt.m vs. filter for Butterworth bandpass filter

17 vues (au cours des 30 derniers jours)
olga
olga le 21 Juil 2011
Hi! I designed a Butterworth 8th order bandpass filter (1-50Hz passband)and tried implementing it using filter.m and filtfilt.m. Filter.m returned a signal that is clearly incorrect - looks like filter.m implementation does not work on this type of signal (EEG signal with high level of 60+ Hz noise). However, filtfilt.m worked very well. My understanding that filtfilt.m does two additional things compared to filter.m: 1)compensates for end point transients and 2)solve initial conditions problem and uses values of initial conditions when implementing a difference equation (or conv/deconv?) in filter.m. Could you please explain to me what the limitations of filter.m are and whether or not initial conditions issue is the root of the problem here. Also, I would really like to know how calculated initial conditions are used in filter.m function. I was able to open filtfilt.m but could not locate the appropriate filter.m function, which uses initial conditions. I found one that only uses (b,a,x). Thank you.
  1 commentaire
abdel monem shalabi
abdel monem shalabi le 8 Mai 2020
Hi
I have EEG signals sampled at 256 Hz. It is necessary to design filters in the range of 0.5-40Hz of these signals.please help me

Connectez-vous pour commenter.

Réponses (2)

Jan
Jan le 21 Juil 2011
Of course FILTER can work on all kind of signals.If FILTFILT works correctly for you, FILTER must also, because it performs the main part of FILTFILT. Why do you think, that the results are incorrect?
FILTFILT expands the original signal at the beginning and ending by "reflected values". These are 3*(filter order - 1) elements of the original signal in reverse order and shifted such that the transicients are smooth. It is a kind of extrapolating the signal to a certain time before the actual signal starts and after it end. Together with the initial conditions this reduces the edge effects.
After the expanded signal was filtered in forward and backward direction, the added parts are cut off again.
In this fast implementation of FILTFILT and FILTER in the FEX the leading and trailing parts are filtered separately to reduce the memory consumption and increase the speed. Perhaps this implementation is easier to understand.
In this thread I've posted a Matlab version of the built-in FILTER function. The "direct form II transposes structure" algorithm is explained in "doc filter" also.
  2 commentaires
olga
olga le 21 Juil 2011
The resulting signals are VERY different between filter and filtfilt. I tried simply filtering out 50 and up Hz, and filtfilt.m returns exactly what one would expect, whereas filter does not. I understand about mirror/extrapolation at end points. But there is more to filtfilt - and that is calculation of initial conditions, which (after commenting out that portion of the filtfilt code), seems to make all the difference.
Mahmoud Eladawi
Mahmoud Eladawi le 23 Oct 2018
this is because the fact that filter has a transient output (underdamped) while in filtfilt, MATLAB removes that by additions processing (i.e., reversal filter, ...)

Connectez-vous pour commenter.


olga
olga le 21 Juil 2011
Thank you very much! It is of great help. I realized after reading your response once again that my issue (or the difference I was seeing between filter.m and filtfilt.m results was mainly the forward directiohtn end point amplitude - with filter.m, it was several orders of magnitude higher than in filtfilt results. Once I dropped the points out, the results were similar but NOT identical (I suppose that is expected). One more question: could you please explain to me in simple terms how the calculated initial conditions are used in the filter.m function. In other words, how are they incorporated into the filtering operation?
  2 commentaires
Jan
Jan le 22 Juil 2011
Do you mean the Zi input for FILTER or the initial condition vector in FILTFILT?
The initial conditions for filter are the values of the Z-vector, which stores the current status. Try this:
x = rand(1, 100); [B, A] = butter(2, 0.5, 'low');
[y1,zf1]=filter(B, A, x(1:50));
[y2,zf2]=filter(B, A, x(51:100), zf1);
Now [y1,y2] is identical to filter(B, A, x), because the final conditions zf1 are used as initial conditions for the 2nd half.
The initial conditions in FILTFILT are an estimation of a "good" initial value of Z. For the RAND signal and the filter order 2, [0] would be a fair choise, and [1000] would be bad (try it and plot the filtered signal).
olga
olga le 22 Juil 2011
Thank you! I will try it today. But will likely get back to you with more questions :). I am determined to get it :):):).

Connectez-vous pour commenter.

Catégories

En savoir plus sur Single-Rate Filters dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by