I am writing an example for how to perform sample rate conversion using windowed sinc and polyphase filters.
So far, this works, and I think I have understood it correctly.
But, at line 184, you can see something curious. If the downsampling factor is higher than the upsampling factor (that is, we are overall downsampling the input by a fractional factor), I have to scale the filter coefficients, otherwise the output is too loud (its amplitude is increased). And I do not know why exactly that is. My current suspicion is that is necessary in order to account for the energy in the parts of the spectrum that I cut off if I overall downsample the signal (for example, when converting 48 kHz -> 40 kHz, this would be the energy of the upper 8 kHz that I cut off).
If I apply this scaling, it works, except for when I use very small filters (5 coefficients or less). With such small filters, the output signal gets dampened. I am unsure if this hints at a deeper problem, or if this is just to be expected with such small filters due to numerical errors.
Can anybody help out?
Oh, and there is also something unclear at line 169 regarding the parameter for sinc.