Tuesday 24 November 2015

filters - What is the advantage of MATLAB's filtfilt


MATLAB's filtfilt does a forward-backward filtering, i.e., filter, reverse the signal, filter again and then reverse again. Apparently this done to reduce phase lags? What are the advantages/disadvantages of using such a filtering (I guess it would result in an effective increase in filter order).


Would it be preferable to use filtfilt always instead of filter (i.e., only forward filtering)? Are there any applications where it is necessary to use this and where it shouldn't be used?




Answer



You can best look at it in the frequency domain. If $x[n]$ is the input sequence and $h[n]$ is the filter's impulse response, then the result of the first filter pass is


$$X(e^{j\omega})H(e^{j\omega})$$


with $X(e^{j\omega})$ and $H(e^{j\omega})$ the Fourier transforms of $x[n]$ and $h[n]$, respectively. Time reversal corresponds to replacing $\omega$ by $-\omega$ in the frequency domain, so after time-reversal we get


$$X(e^{-j\omega})H(e^{-j\omega})$$


The second filter pass corresponds to another multiplication with $H(e^{j\omega})$:


$$X(e^{-j\omega})H(e^{j\omega})H(e^{-j\omega})$$


which after time-reversal finally gives for the spectrum of the output signal


$$Y(e^{j\omega})=X(e^{j\omega})H(e^{j\omega})H(e^{-j\omega})= X(e^{j\omega})|H(e^{j\omega})|^2\tag{1}$$


because for real-valued filter coefficients we have $H(e^{-j\omega})=H^{*}(e^{j\omega})$. Equation (1) shows that the output spectrum is obtained by filtering with a filter with frequency response $|H(e^{j\omega})|^2$, which is purely real-valued, i.e. its phase is zero and consequently there are no phase distortions.



This is the theory. In real-time processing there is of course quite a large delay because time-reversal only works if you allow a latency corresponding to the length of the input block. But this does not change the fact that there are no phase distortions, it's just an additional delay of the output data. For FIR filtering, this approach is not especially useful because you might as well define a new filter $\hat{h}[n]=h[n]*h[-n]$ and get the same result with ordinary filtering. It is more interesting to use this method with IIR filters, because they cannot have zero-phase (or linear phase, i.e. a pure delay).


In sum:




  • if you have or need an IIR filter and you want zero phase distortion, AND processing delay is no problem then this method is useful




  • if processing delay is an issue you shouldn't use it





  • if you have an FIR filter, you can easily compute a new FIR filter response which is equivalent to using this method. Note that with FIR filters an exactly linear phase can always be realized.




No comments:

Post a Comment

readings - Appending 内 to a company name is read ない or うち?

For example, if I say マイクロソフト内のパートナーシップは強いです, is the 内 here read as うち or ない? Answer 「内」 in the form: 「Proper Noun + 内」 is always read 「ない...