0
votes

Trying to undertsand how MATLAB does resampling, looking at toolbox/signal/resample.m.

This is the part where low-pass FIR filter coefficients are calculated:

  fc = 1/2/pqmax;
  L = 2*N*pqmax + 1;
  h = firls( L-1, [0 2*fc 2*fc 1], [1 1 0 0]).*kaiser(L,bta)' ;
  h = p*h/sum(h);

(In this case pqmax and p both represent downsampling ratio.)

Not sure what is the purpose of last line where all filter coefficients are scaled by downsampling ratio over coeffs sum, p/sum(h)? Does anyone know the theory behind?

MATLAB firls
MATLAB kaiser
firls theory: Least Squared Error Design of FIR Filters

1
Ander Biguri answered your question already. I only want to add some remarks regarding your terminology. The coefficients are not "downsampling filter coefficients", they are the "low pass filter coefficients" (or anti aliasing filter). Downsampling happens after filtering. - Irreducible
Thanks @Irreducible, fixed it. - Danijel
@AnderBiguri: That's a pretty complete answer, why not type it in the answer box? - Cris Luengo

1 Answers

1
votes

In most filters, you want the output magnitude to remain equal after filtering, not scaled up or down.

Mathematically this is generally properly done in the filter equation, but in discrete numbers this doesnt generally doesn't apply.

If you divide the filer by its sum, you make sure that for any input data p, the filter will always have a general scale factor of 1, as its normalized. For a p=ones(1:1000,1), if sum(h) is not 1, the result after filtering will be scaled, i.e. the values of p_filtered will not be 1.