Help - Search - Members - Calendar
Full Version: Upsampling the Audio data by a factor of 2
Hydrogenaudio Forums > Hydrogenaudio Forum > General Audio
audio_geek
Hi,
I need to upsample the audio data @ 24KHz to 48KHz.
One simple method I know is to do "zero stuffing" between the two samples and then Low Pass Filter it with cut-off of the filter at pie/2.

This method on implementation(in C and then to put it on a DSP) gives a large complexity.
Can you suggest me some method with the least complexity.
Is there a single filter(FIR or else) design to do both above mentioned tasks??
Or, if you could tell me how is upsampling(like one I need to do) is implemented in professional audio codecs.

Please reply it ASAP.

Thanks

Regards,
Devilal
SebastianG
If the usage of libraries (like libResample or others) is out of option, then yes you should do zerostuffing+lowpass filtering or anything equivalent. FIR filters are generally preferable for resampling (over IIR) since you can exploit the fact that every second sample is zero (in this case). You can also save some computation time (twice as fast) by using a "half-band" filter (since half of the samples of a halfband filter's impulse response are ZERO)

To speed up things with a "long" filter (long impulse response) you can perform the convolution via FFT/iFFT. In this case you may directly FFT blocks of the 24 kHz signal and do the "zero stuffing" in the frequency domain (mirroring the spectral components) multiply with the Fourier transform of the filter's impulse response (taken at 48 kHz) and inverse transform the data. The usual rules apply (ie avoid the effect of circular convolution via zerostuffing blocks and overlap/add).

If you'll search hard enough you'll find at least one discussion thread (here on HA.org) that describes how "FFT convolution" is done properly (ie without applying "windows"!!)

The half-band filter approach (done in the time domain) boils down to interpolating the samples in-between already known samples (which remain the same) via a simple weithed sum of surrouding samples:
CODE

.... x[1] x[2] x[3] x[4] x[5] x[6] x[7] x[8]
x with odd indices = already known
x with even indices = to be computed/interpolated

interpolate at index 'pos' (even) by
x[pos]  = a*(x[pos-1]+x[pos+1])
        + b*(x[pos-3]+x[pos+3])
        + c*(x[pos-5]+x[pos+5])
        + d*(x[pos-7]+x[pos+7])
        + e*(x[pos-9]+x[pos+9])
        + ...

Simple example (possibly too short for your purpose) for such an "interpolating filter":
a = 150/256
b = -25/256
c = 3/256
(corresponds to the shortest half-band lowpass filter with six zeros at -1)


have fun,
Sebastian
audio_geek
QUOTE(SebastianG @ Jul 3 2006, 18:21) *

If the usage of libraries (like libResample or others) is out of option, then yes you should do zerostuffing+lowpass filtering or anything equivalent. FIR filters are generally preferable for resampling (over IIR) since you can exploit the fact that every second sample is zero (in this case). You can also save some computation time (twice as fast) by using a "half-band" filter (since half of the samples of a halfband filter's impulse response are ZERO)

To speed up things with a "long" filter (long impulse response) you can perform the convolution via FFT/iFFT. In this case you may directly FFT blocks of the 24 kHz signal and do the "zero stuffing" in the frequency domain (mirroring the spectral components) multiply with the Fourier transform of the filter's impulse response (taken at 48 kHz) and inverse transform the data. The usual rules apply (ie avoid the effect of circular convolution via zerostuffing blocks and overlap/add).

If you'll search hard enough you'll find at least one discussion thread (here on HA.org) that describes how "FFT convolution" is done properly (ie without applying "windows"!!)

The half-band filter approach (done in the time domain) boils down to interpolating the samples in-between already known samples (which remain the same) via a simple weithed sum of surrouding samples:
CODE

.... x[1] x[2] x[3] x[4] x[5] x[6] x[7] x[8]
x with odd indices = already known
x with even indices = to be computed/interpolated

interpolate at index 'pos' (even) by
x[pos]  = a*(x[pos-1]+x[pos+1])
        + b*(x[pos-3]+x[pos+3])
        + c*(x[pos-5]+x[pos+5])
        + d*(x[pos-7]+x[pos+7])
        + e*(x[pos-9]+x[pos+9])
        + ...

Simple example (may be too short for your purposes) for such an "interpolating filter":
a = 150/256
b = -25/256
c = 3/256
(corresponds to the shortest half-band lowpass filter with six zeros at -1)

have fun,
Sebastian



Thanks for this information but doing FFT and zero-stuffing and all will again be comlex.
Is there a single filter(IIR may be) exists which gives you the final output ?
It exists in the case of downsampling. A signle tap IIR filter does downsampling.

Dev
audio_geek
QUOTE
If the usage of libraries (like libResample or others) is out of option, then yes you should do zerostuffing+lowpass filtering or anything equivalent


What methods do these libraries use ??
Do they have a simpler algorithm ?? Or they use similar complex algorithms but provide a function which we can use ??

SebastianG
QUOTE(audio_geek @ Jul 3 2006, 15:18) *

What methods do these libraries use ??
Do they have a simpler algorithm ?? Or they use similar complex algorithms but provide a function which we can use ??

I dunno. It's on you now, buddy.
I've already spent enough time on compiling the above posting.
audio_geek
Hi,
Can someone please tell me how the IIR filters are used in Upsampling ??
Do they serve the same purpose as that of the FIR ??
I mean, the "zero-stuffing" and then IIR LP Filter or in a different manner ?

SebastianG
QUOTE(audio_geek @ Jul 3 2006, 15:48) *

Can someone please tell me how the IIR filters are used in Upsampling ??
Do they serve the same purpose as that of the FIR ??
I mean, the "zero-stuffing" and then IIR LP Filter or in a different manner ?

Yes, you could do that. But -- as already noted -- FIR filters are generally preferred (more efficient for arbritary rate conversions -- for the 1:2 upsampling case complexity is likely to be similar comparing FIR vs IIR)

Please educate yourself by reading this and the following 3 parts.

My suggestion would be to go with the half-band lowpass filter -- ie interpolating every "in-between" sample the way I described above. I admit: Designing those kinds of filters is easier when you have a tool like Matlab around. So, in case you havn't here's another more suitable example for your needs:
CODE

a=    6.322491778081092e-001
b=   -1.993932354571318e-001
c=    1.069223646747353e-001
d=   -6.426531911718342e-002
e=    3.939721362836458e-002
f=   -2.355802564878609e-002
g=    1.337160738580192e-002
h=   -6.850211104547673e-003
i=    3.117944982753459e-003
j=   -9.915172614528636e-004

This'll result in a rate of 10 additions and 5 multiplications per output-sample at average. Now, isn't this fun? wink.gif

(edit: replaced previous coeffs with improved ones)

Sebastian
SebastianG
QUOTE(audio_geek @ Jul 3 2006, 15:07) *

Is there a single filter(IIR may be) exists which gives you the final output ?
It exists in the case of downsampling. A signle tap IIR filter does downsampling.

Filters don't increase or decrease the amount of samples (sampling rate)
Consider this: Since the IIR filter's formula is recursive you need to calculate all the filtered samples -- even if you throw 50% away afterwards (downsampling). With FIR filters you don't have to do that. Samples can be calculated independently.

BTW: A "single tap IIR" filter makes a quite poor lowpass filter (very large transition)
benski
QUOTE(audio_geek @ Jul 3 2006, 08:21) *

Hi,
I need to upsample the audio data @ 24KHz to 48KHz.
One simple method I know is to do "zero stuffing" between the two samples and then Low Pass Filter it with cut-off of the filter at pie/2.

This method on implementation(in C and then to put it on a DSP) gives a large complexity.
Can you suggest me some method with the least complexity.
Is there a single filter(FIR or else) design to do both above mentioned tasks??
Or, if you could tell me how is upsampling(like one I need to do) is implemented in professional audio codecs.

Please reply it ASAP.

Thanks

Regards,
Devilal


Source code here - http://ldesoras.free.fr/prod.html#src_hiir (make sure to check the license)
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.