I am faced with the following code snippet to get an understanding of a F0 estimation algorithm (DIO). Have a quick look below:
static void DesignLowCutFilter(int N, int fft_size, double *low_cut_filter) {
for (int i = 1; i <= N; ++i)
low_cut_filter[i - 1] = 0.5 - 0.5 * cos(i * 2.0 * world::kPi / (N + 1));
for (int i = N; i < fft_size; ++i)
low_cut_filter[i] = 0.0;
double sum_of_amplitude = 0.0;
for (int i = 0; i < N; ++i)
sum_of_amplitude += low_cut_filter[i];
for (int i = 0; i < N; ++i)
low_cut_filter[i] = -low_cut_filter[i] / sum_of_amplitude;
for (int i = 0; i < (N - 1) / 2; ++i)
low_cut_filter[fft_size - (N - 1) / 2 + i] = low_cut_filter[i];
for (int i = 0; i < N; ++i)
low_cut_filter[i] = low_cut_filter[i + (N - 1) / 2];
low_cut_filter[0] += 1.0;
}
I struggle to understand how this realises a low-pass filter.
- The arguments: N seems to be the cut-off frequency in samples, fft_size is the number of bins in our FFT, and low cut filter seems to be a pointer to an array that we should populate with our low-pass filter coefficients
- The first line seems to be a Hann function with a window length of N.
- Then a cumulative amplitude is calculated to negate and normalise the filter. I guess this is to ensure all numbers below are below -1.
- Then we seem to do something which looks like copying the signal to the other end of the spectrum.
- Then there is another copying part, which I don't get.
- Then we add one to the first bin.
I realise the main confusion for me is that I would start making a low pass filter in a completely different way and I don't see the connections with the above algorithm.
For an n-th order Butterworth low pass filter, I would make a transfer function:
$$ G^{2}(\omega) = \frac{G_0^2}{1 + (\frac{j \omega}{j \omega_c})^{2n}} $$ I would then multiply this transfer function together with the FFT of my signal, that would be the easiest. I can see that this is not a Butterworth filter, but I don't know what kind of filter the above is.
Could you help me in providing some pointers to find the missing concepts in my understanding?