# Why do I have to scale filter coefficients during bandlimited sample rate conversion?

I am writing an example for how to perform sample rate conversion using windowed sinc and polyphase filters.

Here is the C++ code as a github gist.

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.

• in the up-filter-down, sample rate conversion model, there is always a scale factor (a gain by upsampling factor) not only when there is more downsampling... please check your understanding of resampling and the code carefully... – Fat32 May 11 '19 at 21:12
• However, if I apply it like that, then the signal is erroneously amplified if I upsample the original signal, so clarify please. – dv_ May 11 '19 at 21:29
• then it's a C++ coding error... – Fat32 May 11 '19 at 21:53
• Good question. I am having an issue for that also. Perhaps I will perform a test-run at different sample rates and just multiply the filter output amplitude. so that all the different rates have the same amplitude. can't you divide the output by 2 if you divide the SR by 2? Why does it happen? – com.prehensible Oct 21 '19 at 9:31