# Frequency Domain Filtering

Can you create a zero phase IIR filter by transforming its impulse response into frequency domain and only taking the magnitude of that frequency repsone?

I have seen this in an open source project in the following steps:

1. get filter response
2. transform it into frequency domain
3. take the magnitude of the frequency data (-> phase response becomes 0)
4. multiply with frequency data of a (to be filtered) signal

Does this make any sense? Is this method applicable? I have never seen this described in any literature.

This sort of filtering is done all the time, but it doesn't have the effect you think it should.

Suppose you have an IIR filter with an impulse response of $h[n]$ which is represented in the $z$ domain as: $$H\left(z^{-1}\right) = \frac{h_n\left(z^{-1}\right)}{h_d\left(z^{-1}\right)}$$ where $h_n$ is the numerator polynomial in $z^{-1}$ of order $N$ and $h_d$ is the denominator polynomial in $z^{-1}$ of order $D$. That's step 1 (getting the filter response).

Now let's do step 2: $$\hat{H}\left(e^{-\jmath 2\pi m /M}\right) = \frac{h_n\left(e^{-\jmath 2\pi m /M}\right)}{h_d\left(e^{-\jmath 2\pi m /M}\right)}$$ where $m = 0,1,\ldots,M-1$.

And now step 3: $$A\left(e^{-\jmath 2\pi m /M}\right) = \left | \hat{H}\left(e^{-\jmath 2\pi m /M}\right) \right|$$

Now the problem comes: $\hat{H}$ and therefore $A$ is just a sampling of $H$. The problem with that is that now $\hat{H}$ can be perfectly represented by an $M$-coefficient FIR filter.

The bottom line is: doing what you suggest has no benefit over using an FIR filter of length $M$. If anything, the resulting filter response $A$ will not represent the original filter $H$ and so you are probably better off designing an FIR filter to meet your needs.

• thank you for the answer. Thats what i suspected. I just thought there might be something I'm overlooking. Oct 17, 2016 at 13:20
• So, how is that your conclusion? Of course you only get an FIR approximation of the filter this way. But it can still be a good approximation, and it does have zero phase, or has it not? Oct 17, 2016 at 13:26
• @leftaroundabout The issue is it may not be a good approximation. Doing it this way just ensures the same gain as the original filter at the sampled frequencies. It makes no guarantees about how $A$ behaves in between the sampled frequencies. It will have zero phase, but I was providing a reason why this might not be the best approach.
– Peter K.
Oct 17, 2016 at 13:30
• Well, you can once sample the original filter with a very long window to make sure you've captured all details, then downsample just as much as possible without losing too much accuracy. Essentially what you're doing is, you're designing an FIR filter to meet your needs. Oct 17, 2016 at 13:38
• Also, I think it doesn't so much ensure the same gain at the sampled frequencies, but the same gain integrated over one window lobe. I.e. if $A$ has a sharp resonance right between two sampled frequency, the FIR approximation will still reflect that, though indeed not exactly. Oct 17, 2016 at 13:39

This is just "faking" the magnitude response of an IIR filter. The output's magnitude spectrum looks just like it has been filtered by the IIR filter with the given frequency response. Although it may somehow work, there are some limitations:

• Frequency-domain filtering is usually much more computationally demanding.
• It is not for real-time.

The problem with IIR filters is that they don't have linear phase and cause phase distortion. However, when the filtering is not in real-time (such as when dealing with a stored signal on a computer) there are some alternative non-causal approaches to make the IIR filter zero-phase. The most notable is forward-backward filtering which Matlab's filtfilt also uses. It actually is simple: to make the phase impact symmetric, pass the signal twice from the IIR filter, in opposite directions. After the signal passed the filter (the forward pass), time reverse it and then pass the result again through the filter. So the second (backward) pass cancels the phase impact of the forward pass. However, the magnitude response of the overall filer is the square of the frequency response of the IIR filter.

• Good idea pointing out filtfilt! :-)
– Peter K.
Oct 17, 2016 at 12:24
• Another limitation is that if you filter in the frequency domain, you always need data of the same length as the filter (so you might as well design a FIR filter of that length). Oct 17, 2016 at 12:28
• @msm: thank you for the answer. I'm aware of filtfilt() and the forward-backward filtering. I have just been confused by this type of zero phase filtering since you could just use an FIR filter Oct 17, 2016 at 13:18
• A short FIR is still perfectly suitable for soft-realtime applications; only when you need very low latency do you need an IIR. Whereas forward-backward filtering is completely impossible unless you have the entire signal in stored form. Oct 17, 2016 at 13:29