I'm applying an ideal filter on the frequency domain. My code below:

subplot(321), plot(t,s)

subplot(322), plot(w,log(abs(S)))

H( w<=fc ) = 1;
H( w>=fs-fc ) = 1;
subplot(323), plot(w,abs(H))

subplot(324), plot(w,log(abs(SF))) 

ss = ifft(SF);
subplot(325), plot(t,ss); title('Filtered on freq domain')

subplot(326), plot(t,ss2(N:end)); title('Filtered on time domain')

The results are not the same.

And so my questions are:

  1. What am I doing wrong?

  2. Is it better to filter on frequency domain or time-domain or it's the same?

  3. Sometimes applying a filter on frequency domain results on a "strange" signal after IFFT. Why?

enter image description here

  • 3
    $\begingroup$ The problem lies in the fact that the fft of a rectangular signal is a sinc function (which is infinite). However, you are approximating it by a given length. There are different methods to improve this approach based on windowing, for e.g. you could read windowing, also see zeroing fft bins $\endgroup$ Apr 8, 2019 at 5:38
  • $\begingroup$ You are suggesting that I could apply a window to h (near the end of the code) ? I've tried and things don't get better. Why does the frequency domain approach works much better? $\endgroup$ Apr 9, 2019 at 1:48
  • $\begingroup$ Related - dsp.stackexchange.com/questions/52760. $\endgroup$
    – Royi
    May 26, 2021 at 5:21

1 Answer 1


Mathematically or information-wise, you're doing the same thing.

However, filtering in time domain means convolving the signal with a filter kernel, so the algorithmic complexity would be something like $O(n^2)$ in terms of float additions with $n$ the length of the signal.

In frequency domain, filtering is an element-wise multiplication which algorithmic complexity is at most $O(n)$. You also have to consider the complexity of switching between time-domain and frequency-domain, meaning using an FFT algorithm. The FFT complexity is most of the time $O(n\log(n))$.

So the overall complexity of frequency domain filtering would then be $O(n\log(n))$, which is way more efficient than $O(n^2)$.

Considering for example a 1024-long signal, time-domain filtering would need more than 1 millions operations, while frequency-domain filtering would need approximately 3000 !

  • 2
    $\begingroup$ However, if you want minimal latency, you need to do time-domain filtering. $\endgroup$
    – Ben
    May 6, 2019 at 17:11
  • 3
    $\begingroup$ not entirely, @Ben. you might wanna look up this paper from Bill Gardner. this paper went from presentation at an AES convention to publication in the Journal in the fastest time i have ever seen. $\endgroup$ May 7, 2019 at 2:16
  • 1
    $\begingroup$ If I’m interpreting it correctly, in order to get zero latency you still need to do time domain filtering, but that frequency domain filtering can be leveraged to improve efficiencies for longer impulse responses. So Ben is technically correct. A bit of nitpicking to supplement a paper that is remarkable in both readability and usefulness. $\endgroup$
    – Dan Szabo
    May 7, 2019 at 4:01
  • 1
    $\begingroup$ Have a look at dsp.stackexchange.com/questions/52760. $\endgroup$
    – Royi
    May 26, 2021 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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