filtfilt.m vs. filter for Butterworth bandpass filter
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
abdel monem shalabi
el 8 de Mayo de 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
Respuestas (2)
Jan
el 21 de Jul. de 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 comentarios
Mahmoud Eladawi
el 23 de Oct. de 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, ...)
olga
el 21 de Jul. de 2011
2 comentarios
Jan
el 22 de Jul. de 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).
Ver también
Categorías
Más información sobre Single-Rate Filters en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!