# Remove a frequency and all its multiple (harmonics)

In a soundfile, I'd like to remove a frequency and all its harmonics. What is the best solution in your opinion ?

1. Do a loop with 20 notch filters, one after another.

// f is the fundamental frequency
for (i=0; i++; i<21)
{
file.notchfilter(f*i);
}

Question : does each notch filter create some unwanted side-effects, and the fact that we use 20 filters one after another will create very high unwanted artefacts?

2. Is it possible to design a filter that will remove 20 frequencies in ONE STEP ? Then we wouldn't need to do a loop, just one pass wil be okay? Is it called a Comb filter ?

3. Other method ?

• If you know the frequency accurately and have some control over your signal's sample rate, then a comb filter like the one you linked could indeed be a good choice. They are very easy to implement, but the level of control that you have over the comb spacing is pretty coarse. Oct 12, 2013 at 18:28
• @JasonR : great! Would you have an example of C++ implementation of a comb filter that would remove for example frequency 440Hz and all the multiples (880, 1320, etc.) on a 16bit 44.1khz stereo WAV file ? Thanks in advance! (C++ implementation is exactly the thing that is really difficult for me here!)
– Basj
Oct 12, 2013 at 18:39
• If you need help with coding a C++ implementation, I recommend that you plan out what you want your program to do (inputs, outputs, specs.) and then get started with everything you do know how to do. If along the way you have questions that are specific to C++, take them to Stack Overflow. If you have questions specific to filter implementation come back here and we would be happy to help! Unfortunately it is not very likely that anyone will have ready-to-use C++ code that they can share. Oct 13, 2013 at 0:14

The choice of algorithm depends on your application scenario - i.e. there is no best solution per se. If your focus is on minimum computational requirements, a comb filter will probably be optimum. If you want optimum sound quality, a notch filter based approach could be a better choice.

To gain an overview about advantages and disadvantages of the different methods, maybe our article is of interest. We compared

• comb filters
• subband comb filters (only processing the lowpass frequencies) and
• notch filters

in terms of disturbance reduction capabilities and degradation of the desired signal.