I currently feed a sampled audio input signal into a 511 tap highpass FIR filter, the output of which is then fed to another 511 tap lowpass FIR filter, resulting in a very narrow bandpass filter capable of filtering out an individual musical note.

I'd like to use a single filter with the same response and I've found a description on how to combine them here : https://www.dspguide.com/ch14/5.htm

But if I convolve a 511 tap filter with another one, surely I end up with a 1022 point filter so no gain in performance. Is this correct or am I missing something ?

  • 2
    $\begingroup$ Yes, that's it. Or you can design an alternative bandpass filter. And I'd like to know why you want to use a single filter, for computational complexity, code implementation, or something else? Does an IIR filter with much lower order meet your demand? $\endgroup$ – ZR Han Jun 3 at 1:31
  • $\begingroup$ Trying to reduce the computing load - there are 128 of these filters in parallel listening for the 128 notes in the MIDI standard. A 511 tap BP filter would half the calculations so I'll try an alternative design method. An IIR filter would have phase issues and some memory of previous inputs whereas an FIR only knows the latest 511 samples. $\endgroup$ – MikeDB Jun 3 at 1:54
  • $\begingroup$ A FIR filter would have group delay. There are also IIR bandpass filters that don't have any phase shift at the passed frequency, such as this. $\endgroup$ – fibonatic Jun 3 at 2:24
  • $\begingroup$ All 128 filters have 511 taps so have the same group delay. The IIR shown only has 0 phase shift at the exact centre frequency, not slightly to each side. $\endgroup$ – MikeDB Jun 3 at 2:37
  • $\begingroup$ It's 2×511-1=1021, but: What's the reason you're designing a narrowband filter like this, instead of the usual "design a low-pass and shift it" or remez-exchange? Could you maybe do with less taps if you used a different design method? Other than that: 128 filters of length 1021 are no big deal for a PC at audio rates (assuming this is sensibly implemented as fast convolution filtering), but will be too much for a typical microcontroller and expensive in terms of resources if actually implemented as parallel FIRs on an FPGA. $\endgroup$ – mmmm Jun 3 at 8:51

I think you are using the wrong tool for the job. Semitones are spaced logarithmically but FIR filters have linear frequency resolution. If you want to reliably distinguish between the low E and the low F on the bass guitar you need a frequency resolution of better than 2 Hz which requires 10s of thousands of taps (at 48 kHz sample rate).

That's why most audio processing is using IIR filters. There are various options to explore:

Standard IIR bandpass: Butterworth, etc. An interesting one to try out would be a Chebysheff Type 2 filter were you put the first zero of the stop band right on the neighboring semitone to notch it out.

Here is an example of a 5th order Cheby2 filter centered at 220 Hz (A3) with the first zeros in the neighboring semitones. Chebysheff Type 2 Semitone Bandpass

Once you have something you like you can use the same design parameters for any other tone frequency, the design just "warps" but maintains it's overall shape.

It will be MUCH cheaper to implement than an equivalent FIR filter and work even at very low frequency, although it will get fairly sluggish.

Standard Biquads. You could try a peaking filter with a very high Q at the center frequency plus two notches at the neighboring semitones. This may take a little tweaking to get it to look good.

Heterodyne. Multiply the input signal with cosine of the center frequency and then apply a low pass filter with the desired bandwidth. This will turn a bandpass problem into a similar lowpass problem. You still need to design a different lowpass for each note, but you can control the bandwidth directly.

As with all filter design problem it's extremely important to get the requirements right. Filter design requires a lot of trade off so the better you understand which properties are important to your application, the better the filter will be: Passband ripple, transition steepness, stopband attenuation, group delay, phase distortion, complexity, MIPS and memory, latency, numerical noise, etc.

Especially at low frequency you will have to trade off frequency resolution vs group delay (which will VERY high), latency and tracking speed.

  • $\begingroup$ "to distinguish between the low E and the low F on the bass guitar you need a frequency resolution of better than 2 Hz." - Indeed so, which is why I low pass filter and decimate each octave so that the frequencies of interest are always between fs/8 and fs/4. I did try with IIR and with synchronous filters but FIR filters gave me the best response when the input tone is bent or just off-tune. However your diagram has given me the idea of placing the first notch half way between the two semitones and the second notch on the adjoining semitone so I'll revisit an IIR solution. $\endgroup$ – MikeDB Jun 3 at 16:29

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.