2
votes

I'm new in DSP and I have a question in filtering a signal. As I have seen on the internet, IIR and FIR filters are commonly used for filtering a signal. In addition I have also seen another way to filter the signal namely: frequency domain filter (as in Aquilca C++) which apply a rectangular or brickwall window and perform a multiplication to the signal.

I know that we can perfrom the filtering on either time domain (using convolution) or frequency domain (using multiplication), however my question is:

Why can't we just simply use the frequency domain filter method instead of IIR or FIR ? because I think generate a window function is much simpler than generate an IIR filter.

Thanks

3

3 Answers

4
votes

Applying a window by multiplication in the frequency domain results in circular convolution, which will contaminate the result. (e.g. the end of the convolution will wrap around to the beginning of your filtered result.)

But you can zero pad your signal by the length of the filter's impulse response, and use a longer FFT to get a linear filter convolution. But a rectangular brick wall has a very long (theoretically infinite) impulse response, so the amount of zero-padding required approaches infinite.

A brick wall filter also has a nasty frequency response (huge ripples) between FFT bins or frequency sample points. Not something to do if you want a near flat frequency response filter.

Developing a window with a flat enough frequency response (between bins or frequency points), and also a short enough impulse response is non trivial.

An IIR filter most often requires far less computation than a frequency domain filter. But overlap add or overlap save FFT fast convolution can be faster than a long FIR filter convolution.

But first, you need to generate a frequency domain filter that does not have an impulse response that is way too long for your FFT size (causing circular convolution wrap-around issues).

3
votes

The afford of the implementation and runtime overhead of FIR and IIR filter are minimal. It can be done in C in less than 20 lines.

If you want to do the same in the frequency domain, you can design the filter as you want. But you have to

  1. Convert the signal into the frequency domain
  2. Apply the filter
  3. Convert it back into the time domain

Also, there are multiple design choices:

  • Which window size to use for conversion? (512, 1024,...)
  • FFT or one of the four DCTs?
  • windowing function to use?
  • ...

I haven't implemented such a filter (yet). Maybe you will hit more problems on the way.

Baseline: filtering in the frequency domain is much more complicated but it still have its uses

3
votes

You can't really do filtering of real time signals in the frequency domain. (OK, that's not entirely correct, but it's correct enough -- see note!) What you can do is use the overlap-add method to implement a filter with the FFT.

See: https://en.wikipedia.org/wiki/Overlap%E2%80%93add_method

Make no mistake, though -- when you do this, you are implementing a FIR filter. The FFT is used to accelerate convolution of the signal with the filter impulse response, but it is still a convolution.

There are a two big reasons why this isn't done all the time:

  1. It only provides significant performance advantages for very long impulse responses. For most FIR filters used in practice, the normal method is fine; also

  2. FFT filtering introduces a significant delay, since you have to collect a whole block of samples (which has to be as long as the impulse response), and THEN do FFT convolution, before you can produce your first output. Since FFT convolution is only useful for long impulse responses, blocks are always big, so the delays are always significant.

It can also be tricky to implement.

There are some super-clever algorithms that can do FFT convolution without introducing delays. They use a normal FIR for the initial portion of the impulse response, and then increasing length FFT convolutions for the remainder of the impulse response. These are quite tricky to implement and I seem to recall that the technique is patented.

NOTES:

  • The reason why overlap-add convolution is not "filtering in the frequency domain", is because you still design the filter as a time-domain impulse response.

  • You can actually "filter in the frequency domain" using better (non-rectangular) overlapping windows, but then your filter isn't LTI, and it doesn't really provide any advantages over the overlap-add method.