1
$\begingroup$

It is well known that it is a good idea to apply windowing to a signal, before obtaining its DFT and viewing its frequency response.

  • But is it a good idea to apply windowing to the impulse response of a filter, before viewing its frequency response?
  • Does the answer to this question depend on whether the filter is FIR or IIR?

I could perhaps see why windowing could be better than just truncating an IIR filter. But I can't decide whether the same applies to an FIR filter.

However, even in the case of an IIR filter, we usually don't do this. Instead we usually just plot the response as a function of the IIR filter's transfer function numerator & denominator coefficients (e.g. using freqz in Python or Matlab).

So is it ever a good idea to window the impulse response of a filter?

$\endgroup$
  • $\begingroup$ i don't think it's a good idea to apply a window to an impulse response as long as you've captured the entire impulse response (or if it's IIR, captured the entire impulse response to the point that it's indistinguishable from zero). might be a good idea to zero-pad the impulse response to twice the length and further to the next power of two (although there are plenty of DFT/FFT algs that don't need a power of two length). $\endgroup$ – robert bristow-johnson Aug 16 '16 at 17:23
  • $\begingroup$ I can see why that would be the case if the impulse response is symmetric/antisymmetric (as is the case for linear-phase FIR filters), and gradually increases from zero & decreases to zero. However, if it isn't then there may be a discontinuity between the beginning-end of the impulse response that could lead to spectral leakage when the DFT is evaluated. Doesn't this need to be addressed? Zero padding won't help with this. $\endgroup$ – user17230 Aug 16 '16 at 17:47
  • $\begingroup$ a causal filter's impulse response is always asymmetric (which is not the same as "antisymmetric" - maybe need to check your nomenclature). my suggestion is to take the impulse response (if IIR, to the length that the "tail" is so close to zero that it's indistinguishable from zero), pad it to the power of two just larger, and place that in the first half of the FFT buffer and zeroing the second half. the second half actually corresponds to the "negative" times of the impulse response (which is why MATLAB has fftshift()). so then your impulse response will appear causal. $\endgroup$ – robert bristow-johnson Aug 16 '16 at 18:33
  • $\begingroup$ It is not a good idea to window before an FFT, unless you want to decrease interference and sidelobes. In the case of looking at a frequency response, you want to see the sidelobes (they are part of the frequency response) and there are no interfering signals. $\endgroup$ – hotpaw2 Aug 16 '16 at 21:04
2
$\begingroup$

It is not a good idea to window before an FFT, unless you want to decrease interference, rectangular window artifacts, and/or sidelobes. In the case of looking at the frequency response of an impulse response, you want to see the sidelobes (they are part of the frequency response) and there are no interfering signals.

There might be rectangular window artifacts if your window is too short and truncates the response while it is still above the noise floor, but the solution to that is to use a longer FFT, not to use a different window.

$\endgroup$
  • $\begingroup$ Regarding the case of an IIR filter without knowing the coefficients, it is possible that we only have a truncated impulse response that isn't as long as we would like it to be. In this case there would be side-lobes in its frequency response. But why would we want to see the sidelobes? They aren't part of the actual IIR filter. Probably if we want to see the frequency response of the truncated IIR (this effectively answers my original question, so I'm choosing this answer as correct). But if we want the response of the non-truncated IIR, we better suppress the sidelobes, right? $\endgroup$ – user17230 Aug 18 '16 at 13:32
  • $\begingroup$ A non-rectangular window suppresses sidelobes by distorting the shape of the spectrum (it fattens up the main spectral lobes by convolution with a smearing function). $\endgroup$ – hotpaw2 Aug 18 '16 at 17:06
3
$\begingroup$

No, if you know the filter coefficients it's never a good idea to use a window. Why should it be? Instead of plotting the actual frequency response of the filter, you would plot the convolution of the filter's frequency response with the frequency response of the window, which would result in a "smeared out" frequency response. Especially for sharp frequency-selective filters the result would be misleading.

Note that the frequency response of an IIR filter is not computed by applying an FFT to its truncated impulse response (because that would be windowing with a rectangular window), but by computing the ratio of the FFTs of the numerator and the denominator. That's what Matlab's freqz does.

However, if you don't have the filter coefficients of an IIR filter, but just its impulse response, then you don't have much choice, and you have to use the impulse response. You must include as many terms as can be distinguished from noise and use an FFT. This corresponds to windowing with a (very long) rectangular window. I don't see much advantage of using any other window because you have to include practically all terms you can distinguish from noise in order to keep the truncation error small. See also the discussion in the comments below.

$\endgroup$
  • $\begingroup$ Matt, certainly if one goes out far enough, so that the tail of the IIR is so close to zero that truncating it is negligible, then with a little bit of zero-padding (like the 2nd half of the FFT input) will yield a virtually perfect frequency response. i s'pose one can also FFT the vector of numerator coefficients, FFT the vector of the denominator coefficients, and divide the result of the former by the result of the latter (using complex division). that should be "perfect" without any truncation. $\endgroup$ – robert bristow-johnson Aug 16 '16 at 18:38
  • $\begingroup$ @robertbristow-johnson: The latter is indeed what freqz does. The first option is of course theoretically possible but especially for narrow band filters, you'll need very large FFT sizes to achieve a good approximation. In any case, freqz is more accurate and more efficient, so why bother with the FFT of the truncated impulse response (if we know the filter coefficients). $\endgroup$ – Matt L. Aug 16 '16 at 18:47
  • $\begingroup$ you might not know the coefs. just a black box. of course, the narrower the bandwidth, the higher the Q. and the higher Q means the longer the impulse response. but it isn't very long. at AES i am chairing a workshop entitled "Q vs. Q" and one of the points that i will put out, for a resonant 2nd-order filter, for every integer value of Q, the impulse response rings for 2.2 cycles until it dies down to -60 dB (like "RT60"). so for a Q=10, it rings for 22 cycles. how many samples is that gonna be? there is nothing practically wrong with letting the IIR or FIR "ring out" and FFTing that. $\endgroup$ – robert bristow-johnson Aug 16 '16 at 18:54
  • $\begingroup$ @robertbristow-johnson: If we don't know the coefficients of an IIR filter there's indeed not much we can do other than what you suggest. In any case, for FIR filters I wouldn't know why we would ever want to truncate / window the impulse response for computing the frequency response. $\endgroup$ – Matt L. Aug 16 '16 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.