Upsampling and "zero" padding - theory question

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Can someone explain why when upsampling we fill the new samples with "0s" rather than repeating the previous sample?

I am particularly interested in how this applies to sample rate conversion (i.e., upsample - FIR filter - downsample). It seems to me that repeating the previous sample would be a closer approximation for "in between" samples than zeros - thus demanding less from the filter stage.

But it is not normally done that way. The routines I have seen insert zeros. Why?

Post

Did you consider what it means in the frequency domain?

i.e. for sake of argument, if I have a sine wave sampled at 24 kHz I have one sample played out every 41.6 micro-seconds. Say I upsample it to 48 kHz, I would have have 1 sample played out every 20.8 micro-seconds. However, there is no relevant information in the original waveform above 24 kHz and so, ideally I would low pass filter my 48 kHz to cut-off everything above 24 kHz. This is equivalent to zeroing every other sample point in a 48 kHz representation of the sine wave. Which is equivalent to playing out at 48 kHz and zeroing every other sample which is equivalent to playing out at 24 kHz and zeroing no samples.

If you were to double up samples and clock out at 48 kHz, it would be equivalent to clocking out at 24 kHz with samples that are twice as long in time. This would introduce an undesirable roll-off of your signal amplitude depending on frequency.

Check this out http://research.opt.indiana.edu/Library ... /ch13.html
Image

Post

Short answer.. zero padding doesnt cause distortion, it just shifts the nyquist up to it's new place. Repeating the last sample is like using drop sample interpolation, and that will cause distortion and aliasing, and not just in the newly created region of the spectrum.


Another point worth mentioning is that by zero stuffing a lot of the sample points are now zeros, so you dont have to evaluate those taps. For example upsampling 2x means you only have to evaluate half the filter taps, those that line up with non zeros.

Post

Consider this example: when you copy samples instead of inserting zeros what you are basically doing is applying FIR filter with two taps both equal to 1, AND doing insertion of zero samples at the same time.

To say it differently, if you insert zeros in the first place, and then apply FIR filter with two taps equal to 1, to the result, you will get the same thing as if you were duplicating samples.

Obviously, such FIR filter will change overall response - but of course, it won't "distort" the signal - it will only change frequency/phase response.
Image

Post

Ooops, must engage brain before opening mouth.

;-0

Post

Thank you for all the replies. I need to study this some more for the light to come on. :roll:

My original question was from an example I saw of a conversion from 48KHz to 44.1KHz. Over 100 zeros were inserted after every original sample; the array LP filtered, then re-sampled at the new rate. It's almost like converting digital to analog (via the very high upsample rate and filter) then re-sampling. (I understand this is not an efficient approach, just presenting the concept).

It seems to me the purpose of the filter is to interpolate the new values between original sample points. What I still don't follow is why inserting numbers that are not related to the original signal (zeros) produces LESS distortion than repeating the actual data. Is it because zeros are "inert"?

Post

that's probably the easiest way of looking at it.

Something to note, is that inserting zeros keeps the spectrum constant, but decreases the amplitude... so the resulting signal will be half the 'volume' at the new sampling rate.

Easiest thing to do would be to write a little routine that takes a buffer, performs an fft, then draws the result as a graph (that's a good excercise anyway, if you've never done it, I have one knocked up for filter testing). Pass it a zero stuffed buffer, then a duplicate stuffed buffer and see the differences.. :)

DSP
Image

Post

Look at the insertion of zeros and the filtering as one entity. If your filter is ideal, then you are inserting the ideal value between samples. If you want to look at it like this, the upsampling simply creates the 'space' into which you insert the proper value.

As Aleksey said, you can view your sample repeat in exactly the same light: as a zero insertion followed by a filter that repeats the previous sample. In otherwords, repeating samples amounts to a zero insertion followed by a far-from-ideal 0th order interpolator. What you want is an ideal bandlimitted interpolator, i.e. an ideal lowpass filter. So taking them together, the upsampler and filter are inserting the 'ideal' samples.

To really understand what is going on, you need to understand what effects inserting zeros has on the spectrum. It simply contracts the frequency axis by your upsampling factor. Since spectra in the digital domain are 2pi periodic, between 0 and Nyquist you now have multiple (shrunk in frequency) copies of your orignal spectrum. The interpolation lowpass filter gets rid of those extra copies between 0 and 2pi.

Post

Another way to look at it: Don't think of your sampled data as 'blocks' with width, they are mathematically considered to be a series of thin points- look up delta function. Looking at it this way, when you zero-stuff, all you are doing is increasing the distance between the points or changing the (sample)rate.

Post Reply

Return to “DSP and Plugin Development”