I'm trying to improve my understanding of FIR filters. As an experiment, I've manually created an FIR filter, whose coefficients follow exactly one period of a sine wave. I'm wondering what is the peak gain frequency of such a filter.
For example, I'm filtering a 44.1 kHz audio signal with filter coefficients corresponding to a 440 Hz sine wave1. Intuitively I would expect that the convolution reinforces this frequency. However, I noticed that the frequencies of slightly lower frequencies (roughly a few semitones, ~365 Hz) actually have a stronger gain. This is also confirmed by running the filter coefficients through scipy.signal.freqz
(the red line corresponds to 440 Hz, the gray lines indicate frequencies of neighboring semitones):
Most likely I've encountered a basic rule of digital filter design that I'm not aware of. I'm wondering:
- Why is the peak shifted w.r.t. the frequency that is used in the convolution?
- Is there a formula that describes the relationship between the two, i.e., is it possible to compute the frequency that the sine convolution should have so that the frequency response peaks at 440 Hz?
1 With a sampling frequency of 44.1 kHz, the period of a 440 Hz sine has a fractional length 100.23 samples, which I'm rounding down to 100 filter coefficients. Could this imperfection play a role in the effect I'm seeing?
freqz
to a multiple of the filter length? $\endgroup$