I got a signal and I would like to remove a specific frequency range.

I am a frequency noob, so I will explain it by images: I have a frequency filter (butter bandpass): butter bandpass

I have a signal and it's filtered signal: signal and filtered signal

The frequency spectrum of the signal looks something like this: frequency - signal

And the extracted frequencies like this: extracted frequencies

So far everything is fine. But if I try to subtract the extracted signal from the original signal in time domain, then I get this frequency spectrum: not removed frequencies Instead, I would like to get the red marked spectrum.

What do I need to calculate in order to remove the specified frequencies from a signal?

I got the code from here and added FFT computations.

Kind regards, Thomy800

  • $\begingroup$ Your question is really unclear. Could you add a link to the signal and specify what you need? Do you want assistance with Filter Design? $\endgroup$
    – Royi
    Jun 6, 2018 at 10:50
  • $\begingroup$ The signal is already linked above. It is random noise and as you can see a sinus at 312, 600 and 2000 Hz. I want to dispose the frequencies from 500Hz up to 1250Hz. I want to keep 0 to 500 and 1250 to inf, i.e. the spike at 312Hz should not show up. If that's the trick I need help with filter design. Otherwise just mathematical assistance how to subtract an extracted signal from the original. $\endgroup$
    – Thomy800
    Jun 6, 2018 at 11:20
  • $\begingroup$ btw, it's a dummy signal. $\endgroup$
    – Thomy800
    Jun 6, 2018 at 11:27
  • $\begingroup$ What's the sampling Frequency? $\endgroup$
    – Royi
    Jun 6, 2018 at 13:05

1 Answer 1


The problem is most likely that you aren't accounting for the group delay of the filter. As an LTI system, your bandpass filter does two things to each frequency component present in its input signal:

  1. It multiplies the frequency component's magnitude by some value $A(\omega)$.
  2. It shifts the frequency component's phase by some phase angle $\theta(\omega)$.

Together, these two components make up the filter's frequency response. The second of these two effects is what yields the filter's group delay. That is, it takes some time for each component of the input signal to propagate through the filter. If you are looking to do some operation on the filter input and output that relies upon them being time-aligned, you have to account for this effect first.

With that said, doing such a thing with an IIR filter such as yours can be tricky. In general, IIR filters do not have linear phase. This means that your filter will delay some frequency components more than others. Again, if you're relying on time alignment of the filter input and output to do some operation, then this is going to work against you.

An alternative would be to use a symmetric FIR filter. These filters do have linear phase, so it will delay all frequency components by an equal number of samples (the delay $D$ is equal to half of the filter order, so if you have $N$ total coefficients, the delay is $\frac{N-1}{2}$ samples). If you did this, then you could accomplish what you want by doing the following:

  1. Pass your input signal $x[n]$ through the filter to get an output $y[n]$.
  2. Calculate the difference signal that you're looking for by adjusting your indexing according to the filter's group delay:

$$d[n] = x[n] - y\left[n + \frac{N-1}{2}\right]$$

Addendum: All of this begs the question of precisely what it is you're trying to do anyway. It seems like maybe you're trying to implement a bandstop filter by using a bandpass filter to isolate one frequency band and then subtract it from the original. It might make more sense to use a bandstop filter directly. For example, techniques exist to take a lowpass prototype filter and transform it to other types, like highpass, bandpass, or bandstop. This process might have been used to design your original bandpass filter anyway.

  • $\begingroup$ Thanks a lot. That really helped! Btw, I figured out how to make my example above get to work: just use filtfilt for computing y. That also considers the phase of the filter and somehow reconstructs it. $\endgroup$
    – Thomy800
    Jun 6, 2018 at 13:27
  • 1
    $\begingroup$ filtfilt() runs your signal through the filter twice: once in the forward direction and once in the reverse direction. By doing so, the group delays of each run of the filter cancel each other out, and the result has zero phase delay. This does accomplish what you want, but it isn't feasible for real-time applications if you ever need to do that. $\endgroup$
    – Jason R
    Jun 6, 2018 at 13:30
  • $\begingroup$ @JasonR: Your anwser was so educational, I would like to upvote it multiple times, if I could. $\endgroup$
    – typetetris
    Oct 8, 2021 at 6:31

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.