Help with Comb Filter theory

Calling all DSP experts :slight_smile: I’m trying to code a very simple comb filter using a Teensy board and the Audio Shield. I’m trying to copy something like the Resonator in Ableton. I’m having problems achieving the sort of sound I was expecting. I’m using the delay object included in the audio library, but setting the delay time so that it is tuned to resonate at a certain pitch, using this simple calculation.

float calculate_delay_time_ms( float resonant_frequency )
{
  return 1000.0f / resonant_frequency;
}

The code is setup to have both a feed forward, and a feed back comb filter. Only the feed forward one is currently enabled. I’m not sure whether Ableton’s Resonator is feedback or feed forward, or a hybrid of the two (it also has many stages that can be individually tuned rather than one)? In testing with my guitar, I found the effect often resonated a semi-tone or even a tone above where I had intentionally tuned it, depending on where I had tuned it.

I thought this might be due to my guitar intonation, so I added some simple test tone code. What I would expect to see, is that when the test tone matches the frequency that the comb filter is tuned to, the amplitude would essentially double. But, testing on my (toy) oscilloscope, depending on what note it’s tuned to, the highest amplitude is indeed, often seen one tone up? I am seeing some amplitude increase at the expected frequency, but not as much as at 1 tone up. I suspect this is down to some error in my understanding of comb filters, but if someone more knowledgeable could point it out I’d be very appreciative!

Full code is here for reference…

I looked at their delay code and it seems that despite accepting a floating point argument they are storing the delay time in samples as an integer, so there’s going to be some error there, but that should only throw the frequency off by a few Hz not whole tones or semitones.

2 Likes

Thanks for investigating @kisielk. If I understand correctly, you’re pointing out that the audio library doesn’t deal with sub-sample accuracy? In which case, I agree that this probably isn’t the root of the problem. If A4 is 440Hz, and the sample rate is 44KHz, then the wavelength of A4 will be represented in 100 samples. So sub-sample accuracy in this case, would cause it to be, at worst, 1% out (4.4Hz), whereas the jump to the next semi-tone is 26Hz.

My understanding was that a simple comb filter is just a delay line which either feeds forwards or backwards, and mixes with the original signal. The delay time is set such that, to filter out a frequency, you would set the delay line to half the wavelength of the frequency you want to filter. So the delay is 180 degrees out of phase with the original signal, and the desired frequency is cancelled out. If you want to resonate, you set the delay time to the wavelength of the frequency you want to resonate at, so the waves are in phase, thus doubling the amplitude. Something is definitely wrong with my understanding though, as it doesn’t appear to work like that.

1 Like