# Resampling: how many samples to zero-stuff or down sample?

I am a little confused about how resampling works with one filter. I get why you choose the lower nyquist cutoff when you combine both interpolation and decimation for resampling by a rational fraction (you don't want to alias and you only get one shot to take care of it when you combine interpolation+decimation).

I will use a practical example: $44.1 \, \textrm{kHz}$ to $48\, \textrm{kHz}$.

$(44100 / 48000) = (441 / 480) = (147 / 160)$

Combining $147$ decimation factor by $160$ interpolation, you can use one anti-alias: at $44.1/2= 22050\,\textrm{Hz}$ cutoff for a lowpass FIR. However, you still need to zero stuff, right? But how much? 160 zeroes?

Going the other way around $48 \, \textrm{kHz}$ to $44.1\, \textrm{kHz}$, how many samples do you downsample? Certainly not 147 zeroes?

Is $160 - 147 = 13$ zeroes the answer?

In the multi-stage solution, here's how this would work (I think): Stuff $160$ zeroes, anti-alias lowpass at $24\, \textrm{kHz}$. Downsample the output by $147$, antialias lowpass at $22050 \, \textrm{Hz}$. But wait, you're not computing outputs for a lot of those zeroes, so why not just combine the two? Does this leave me with $13$ zeroes for resampling up and $13$ samples to skip over when resampling down before applying the lower of the two cutoffs?

Next thing to wrap my head around: polyphase filterbanks.

EDIT: source of confusion is in last comment to answer, interpolate is upsampling followed by anti-image filter while decimation is anti-alias followed by downsampling. cascading these two obviates the need for two separate filters. if this is the case then would this mean that resampling by a rational factor < 1 entails 2 filters always by the nature of the decimation/interpolation process, while a resample factor > 1 entails that 1 filter may be used instead?

DOUBLE EDIT: thinking about it, you can still use 1 filter, but you must interpolate first, then anti-alias, then decimate.

sorry (definitely not sorry) this is how my brain debugs its malformed thoughts on DSP (:

• The alternative to up/down sampling by two large factors is to interpolate the just the few samples you need at the destination sample rate, and no others. If you interpolate using a high-quality low-pass/anti-alias FIR filter kernel, there will be little qualitative difference. A polyphase table is a way to efficiently implement the FIR filter(s) needed. – hotpaw2 Nov 4 '15 at 5:52

When you up sample by 160, if you wanted to filter twice, you would actually be applying an "anti-image" filter. The next filter for decimation would be the "anti-alias" filter. But in you case, you could just use the anti alias filter once and accomplish the same. I think perhaps you need to consider what zero stuffing means, to put so many zeros between samples and decimate is to throw away so many samples inbetween.

Btw, you do compute samples for the zeros when you filter. If you want to understand better, try plotting the spectrum of each stage, and what would happen if only using the 13.

If I understand your question properly, you would effective just upsampling by 13, filter, then downsample. You'd be back where you started

• Ok, the answer is no. You will effectively just run samples through a filter. I stand by the suggestion to try plotting, matlab or python? – johnnymopo Nov 4 '15 at 0:54
• Edited, if you think I did not understand, please clarify how you would attempt to use 13 – johnnymopo Nov 4 '15 at 1:03
• Good for you. I assumed this example came from dspguru: dspguru.com/dsp/faqs/multirate/resampling and figured you understood that based on your question and that it was explained there – johnnymopo Nov 4 '15 at 1:59
• Well it does... "Likewise, since resampling includes decimation, you seemingly need a decimation filter. Or do you? Since the interpolation filter is in-line with the decimation filter, you could just combine the two filters by convolving their coefficients into a single filter to use for decimation. Better yet, since both are lowpass filters, just use whichever filter has the lowest cutoff frequency as the interpolation filter." But I personallydidn't really get it until I had to actually do it a few times myself. – johnnymopo Nov 4 '15 at 2:05