Help - Search - Members - Calendar
Full Version: Resampling algorithms
Hydrogenaudio Forums > Hydrogenaudio Forum > Scientific Discussion
goodsound
I am interested in knowing more about how resampling is done - especially non-integer sample rate conversions like 44.1 -> 48Khz. What exactly is in the algorithm ?

Also asked another way - what makes a resampler different(better or worse) than the other ?
senab
I'd also be quite interested in this
HotshotGG
QUOTE
"This program converts sampling rate of PCM wav file. Also, this program has a function to apply dither to its output and extend perceived dynamic range. Sampling rates of 44.1kHz and 48kHz are populary used, but ratio of these two frequency is 147:160, and these are not small numbers. And thus, sampling rate conversion without degradation of sound quality requires filters with very large order, and it's difficult to achieve both quality and speed. This program achieved relatively fast and high quality conversion using two different kinds of filters combined in a smart way." -Shibatch.


This is a start. What sort of filters they are describing I guess you would have to look at the source code? Chebyshev maybe? noise shaping? sad.gif
Mike Giacomelli
QUOTE(goodsound @ Jun 2 2006, 12:40) *

I am interested in knowing more about how resampling is done - especially non-integer sample rate conversions like 44.1 -> 48Khz. What exactly is in the algorithm ?

Also asked another way - what makes a resampler different(better or worse) than the other ?


I have no idea how its done in practice, but the one the textbooks teach is to up sample to the least common multiple of the two sample rates, and then downsample by an integer amount to the second rate. This is done just by throwing out extra samples. Only problem is when you add samples, you'll introduce higher frequency noise which could cause aliasing when you downsample. So you need to add a lowpass filter in the middle to remove all the noise before you downsample.

http://www.dspguide.com/ch3/6.htm
jmartis
I think that the right word is interpolation. There are different kinds of interpolation (linear, cubic, whatever), and this is what defines the quality of the resampler. Basically the resampler "draws" lines between the samples (eg. straight lines in linear interpolation) and then uses it as a reference to the resampled signal. Of course I may be completely wrong.

J.M.
Hanky
JOS's Digital Audio Resampling Home Page could be a nice start. Please be aware that it contains some math.
gaekwad2
Or this (less math).

In short, a resampler interpolates by applying a lowpass filter.
goodsound
hanky & gaekwad, thanks for the links. I will check them out.

147:160 of interpolation:decimation would be a lot of processing! wonder if even the best resamplers really implement that (?)
SebastianG
QUOTE(goodsound @ Jun 3 2006, 19:03) *

hanky & gaekwad, thanks for the links. I will check them out.

147:160 of interpolation:decimation would be a lot of processing! wonder if even the best resamplers really implement that (?)


This is how it's usually done:
- zero stuffing to 147 times the rate (just insert 146 zeros after each sampe)
- apply a lowpass filter
- just keep one out of 160 samples
- compensate for the gain of 160/147

Since you throw 159 out of 160 samples away while downsampling you can save a lot of time by not computing those samples in the first place during the filtering step. Simply throwing away those samples can be done if the lowpass filter's cut-off frequency is set appropriately (to avoid aliasing). This would be the "text-book-approach"

Other methods exist like only zerostuffing to 4 times the rate, lowpassing via fast FFT convolution and cubic interpolation. (cubic interpolation doesn't introduce much aliasing when your signal only contains frequencies below nyquist/4)

Sebi
goodsound
QUOTE(SebastianG @ Jun 3 2006, 12:45) *

- apply a lowpass filter

sounds like this is the step where those "zero" samples are calculated. This could be the most important step and I believe it would by way of interpolation that the values of these additional samples are computed ? and the type of interpolation used(linear, cubic,etc..) would also have an effect on the final result ?
Although I cant seem to understand why exactly is it called a "lowpass filter" then ?
SebastianG
goodsound, just check the pages others have linked in this thread.

QUOTE(goodsound @ Jun 6 2006, 18:55) *

...and the type of interpolation used(linear, cubic,etc..) would also have an effect on the final result ?

There's no such thing in the above "text-book" approach.

QUOTE(goodsound @ Jun 6 2006, 18:55) *

Although I cant seem to understand why exactly is it called a "lowpass filter" then ?

Because it is a lowpass filter.

Things get clearer once you understand what happens to the spectrum when you do zero-stuffing.

Sebi
penvzila
Zero padding:

http://web.pdx.edu/~michc/zepad.pdf
SebastianG
QUOTE(penvzila @ Aug 16 2006, 01:09) *

This is something entirely different.


Suppose we have a simple time distrete signal containing a sinusoid with 0<=freq<=1:
x1[n] = cos(n*pi*freq) for n=0,1,2,....

When we do "zero-stuffing" we interleave this signal with zero samples so that
x2[n] = x1[n/2] = cos(n*pi*freq*1/2) for n being even
x2[n] = 0 for n being odd

Observe that
x2[n] = 1/2 * cos(n*pi*freq*1/2) + 1/2 * cos(n*pi*(1-freq*1/2))
(Proof is left to the reader as exercise)

What does this mean? We now have TWO sinusoids, one at freq*1/2 times the nyquist frequency and one at 1-freq*1/2 times the nyquist frequency (alias). In other words the spectrum is mirrored at the original nyquist frequency (alias).

(This actually extends to stuffing two or more zeros inbetween two samples instead of just one -- The original spectrum stays intact and above alias frequencies are created)

Now we just need to apply a lowpass filter to get rid of the alias frequencies.
We then have appropriately resampled the signal x1 to twice the sampling rate. smile.gif


Sebastian
cabbagerat
In addition to the approaches discussed here, there are some others that trade speed for quality. These are mostly used in very low powered systems where sound quality is not an important factor. I saw a radar system from the eighties that used linear interpolation and a 3 tap FIR filter to do SRC. Another approach taken in some systems is to use a DAC cascaded with an ADC - this obviously introduces noise and other problems but can save on system complexity and power.

There is a nice discussion of a couple of approaches to this problem in most DSP books. If you really want to get into the details and theory behind digital rate conversion then consider reading a book on the subject. 'Discrete-time signal processing' by Oppenheim and Schafer is a nice one, but you'll probably need at least one year of university calculus.
muaddib
Did anyone compare resampling using bandlimited interpolation and interpolate:decimate.
How do they compare when it comes to speed and how when it is about quality?
Woodinville
Proakis also does a very good job of explaining how to interpolate between filter taps to do any sort of variable-ratio resampling.

For the basics, Crochiere and Rabiner is hard to beat.
Mike Giacomelli
QUOTE(muaddib @ Sep 28 2006, 09:51) *

Did anyone compare resampling using bandlimited interpolation and interpolate:decimate.
How do they compare when it comes to speed and how when it is about quality?


I've never seen a comparison, but just looking at the two apporaches I can tell you that the second will provide better quality but be slower. In fact, if you don't mind spending infinately long computing a perfect lowpass and have enough precision such that no rounding errors occur, it can in theory be lossless wink.gif
Woodinville
QUOTE(Mike Giacomelli @ Sep 28 2006, 14:01) *

QUOTE(muaddib @ Sep 28 2006, 09:51) *

Did anyone compare resampling using bandlimited interpolation and interpolate:decimate.
How do they compare when it comes to speed and how when it is about quality?


I've never seen a comparison, but just looking at the two apporaches I can tell you that the second will provide better quality but be slower. In fact, if you don't mind spending infinately long computing a perfect lowpass and have enough precision such that no rounding errors occur, it can in theory be lossless wink.gif



Done right, they are exactly the same thing, guys.

"bandlimited interpolation" can, and at least sometimes has, been known to be a form of standard resampling wherein each input sample carries a time signature, and each output sample simply grabs the appropriate filter taps when needed.
MedO
Shouldn't sinc interpolation be "perfect" when upsampling as well?
Woodinville
QUOTE(MedO @ Sep 28 2006, 14:29) *

Shouldn't sinc interpolation be "perfect" when upsampling as well?



If you have "infinite" time. smile.gif
Mike Giacomelli
QUOTE(Woodinville @ Sep 28 2006, 14:19) *

QUOTE(Mike Giacomelli @ Sep 28 2006, 14:01) *

QUOTE(muaddib @ Sep 28 2006, 09:51) *

Did anyone compare resampling using bandlimited interpolation and interpolate:decimate.
How do they compare when it comes to speed and how when it is about quality?


I've never seen a comparison, but just looking at the two apporaches I can tell you that the second will provide better quality but be slower. In fact, if you don't mind spending infinately long computing a perfect lowpass and have enough precision such that no rounding errors occur, it can in theory be lossless wink.gif



Done right, they are exactly the same thing, guys.

"bandlimited interpolation" can, and at least sometimes has, been known to be a form of standard resampling wherein each input sample carries a time signature, and each output sample simply grabs the appropriate filter taps when needed.


I think from context he was refering to polynomial interpolation, or something like that, since otherwise, all methods are technically bandlimited and interpolation smile.gif
muaddib
Hmm, when I think more about it, it is just as Woodinville sais: if you have infinite precision and infinitly long filters then both are the same.
And it is probably very hard to do righteous comparison in real applications when we have that limitation of finite time and length.
Maybe we can do comaprison having two methods use the same ammount of memory?
SebastianG
BTW: I recently found this nice paper about image interpolation in the context of medical imaging -- where high accuracy is needed. Interesting side note: Cardinal B-Splines with increasing order converge to the sinc curve. (YAY!) Apparently cubic B-Splines are the way to go for proper image interpolation (really good quality/speed trade-off).

However, if you plan to use cubic B-Splines for audio you better work on a digital signal that has been oversampled a couple of times. The rejection of image frequencies due to B-Spline interpolation at a signal which is 10x oversampled will be at least 102 dB then.

edit: the img tags didn't seem to work. Here's the direct link to the frequency plot:
image

Cheers!
Woodinville
QUOTE(Mike Giacomelli @ Sep 28 2006, 18:32) *

QUOTE(Woodinville @ Sep 28 2006, 14:19) *

QUOTE(Mike Giacomelli @ Sep 28 2006, 14:01) *

QUOTE(muaddib @ Sep 28 2006, 09:51) *

Did anyone compare resampling using bandlimited interpolation and interpolate:decimate.
How do they compare when it comes to speed and how when it is about quality?


I've never seen a comparison, but just looking at the two apporaches I can tell you that the second will provide better quality but be slower. In fact, if you don't mind spending infinately long computing a perfect lowpass and have enough precision such that no rounding errors occur, it can in theory be lossless wink.gif



Done right, they are exactly the same thing, guys.

"bandlimited interpolation" can, and at least sometimes has, been known to be a form of standard resampling wherein each input sample carries a time signature, and each output sample simply grabs the appropriate filter taps when needed.


I think from context he was refering to polynomial interpolation, or something like that, since otherwise, all methods are technically bandlimited and interpolation smile.gif


Well, if you generate a filter at, say, a sampling rate of 1 megaHz, and then use some kind of 3 or 5 order interpolation to calculate the actual filter taps from that, you're doing both, and it works fine.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.