DSPRelated.com
Forums

Oversampling 8KHz to 44.1KHz

Started by ggabe October 29, 2004
There's a 8KHz audio sample rate I want to convert up to 44.1KHz
sample rate. What's the right approach to keep Mr. Nyquist happy?
On 2004-10-29 21:20:56 +0200, ggabe@mail.com (ggabe) said:

> There's a 8KHz audio sample rate I want to convert up to 44.1KHz > sample rate. What's the right approach to keep Mr. Nyquist happy?
Mr. Nyquist generally doesn't have a problem with that kind of conversion... Google for "Upsampling" and "Interpolation", I'm sure you'll come up with some good references. -- Stephan M. Bernsee http://www.dspdimension.com
ggabe wrote:
> > There's a 8KHz audio sample rate I want to convert up to 44.1KHz > sample rate. What's the right approach to keep Mr. Nyquist happy?
Mr Nyquist would probably be happy with this: http://www.mega-nerd.com/SRC/ Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid) +-----------------------------------------------------------+ "One World, one Web, one Browser." - Microsoft promotion "Ein Volk, ein Reich, ein Fuhrer." - Adolf Hitler
ggabe wrote:

> There's a 8KHz audio sample rate I want to convert up to 44.1KHz > sample rate. What's the right approach to keep Mr. Nyquist happy?
Mr. Nyquist's happyness is the least of your concerns in this case -- the continuous-time signal corresponding to a signal sampled at 8kHz is band-limited to 4kHz. That means that you should have no problem in representing it with 44.1kHz sampling rate. A simple approach would be to up-sample your signal 441 times (i.e., put a sample, then 440 samples with zero), and then low-pass filter that signal and take one every forty samples (obviously, you will use an FIR filter and you will not compute all of the output values -- you only compute one every forty, the ones that you want to keep). This is in general impractical for rates that are not simple multiples of each other, like this case. However, if you think about it carefully, there may be many optimizations that could reduce the number of calculations significantly -- the low-pass filter will have *a lot* of coefficients, but only a small fraction of the input samples are non-zero, so you could play with it and only do the amount of operations really required. (perhaps your biggest problem will be the design of the filter?) You can also up-sample and low-pass filter to a sufficiently high rate for the signal to be very smooth. Then, determine the values at t = n*Ts (with Ts = 1/44100 sec) using linear interpolation (or 2nd- or 3rd-order polynomial interpolation) HTH, Carlos --
ggabe,

Having an audio signal sampled at 8kHz, probably means, having a ugly
sounding sample.
So don't put all your energy into upsampling it the best way with the least
possible noise/quality loss. It is bad anyway. :-)

Just do some linear interpolation. Or even repeat every frigging sample
44100 / 8000 times.

Best regards,

Rob

"ggabe" <ggabe@mail.com> wrote in message
news:3236f206.0410291120.bff1bb7@posting.google.com...
> There's a 8KHz audio sample rate I want to convert up to 44.1KHz > sample rate. What's the right approach to keep Mr. Nyquist happy?
"Rob Vermeulen" <rpvermeulen@tiscali-antispam-.nl> wrote in message
news:4186a8f0$0$44111$5fc3050@dreader2.news.tiscali.nl...
> ggabe, > > Having an audio signal sampled at 8kHz, probably means, having a ugly > sounding sample.
Depends. Properly sampled speech can sound OK (telephone quality).
> So don't put all your energy into upsampling it the best way with the least > possible noise/quality loss. It is bad anyway. :-) > > Just do some linear interpolation. Or even repeat every frigging sample > 44100 / 8000 times.
I wouldn't recommend repeating samples personally. Sample duplication adds high frequency harmonics. Or more precisely, changing the sample rate allows the high frequency harmonics that were already there to become part of the pass band and sample repeating doesn't provide much attenuation of them. Linear interpolation is definitely better, but a higher order LP filter set to 4kHz is better still.
Rob Vermeulen wrote:
> > ggabe, > > Having an audio signal sampled at 8kHz, probably means, having a ugly > sounding sample. > So don't put all your energy into upsampling it the best way with the least > possible noise/quality loss. It is bad anyway. :-) > > Just do some linear interpolation. Or even repeat every frigging sample > 44100 / 8000 times.
Sorry, thats just plain bad advice. Linear interpolation can provide reasonable results if the highest frequency component is 1/4 of the sample frequency or less. However, for audio sampled at 8kHz this is unlikey to be the case. In fact it is likey to have a large amount of energy in the 2-4kHz band and its this band where linear interpolation performs worst. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid) +-----------------------------------------------------------+ "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -- Ernst Jan Plugge
On 2004-11-02 07:43:41 +0100, Erik de Castro Lopo <nospam@mega-nerd.com> said:

> Sorry, thats just plain bad advice. > > Linear interpolation can provide reasonable results if the > highest frequency component is 1/4 of the sample frequency > or less. However, for audio sampled at 8kHz this is unlikey > to be the case. In fact it is likey to have a large amount > of energy in the 2-4kHz band and its this band where linear > interpolation performs worst. > > Erik
I concur with Erik and Jon that the use of zero order hold interpolation and linear interpolation isn't a wise thing from the technical perspective. The best option would be a sinc interpolation or at least a reasonably long FIR approximation of it. However, in defense of what Rob said, I would agree with him that due to the artifacts introduced when improperly upsampling a signal from 8kHz to 44.1kHz it may be perceptually better to use linear interpolation in that specific case. Our perception usually prefers *any* kind of energy over zero energy at a certain band, most likely because zero energy at a certain frequency rarely happens in nature. When you are upsampling from 8kHz to 44.1kHz you get a very large area that contains (almost) no energy which tends to sound "unnatural" and "dead" to a listener when using hi-end reproduction. Linear interpolation will add some noise which might sound more natural, even though it isn't "politically correct" from the DSP viewpoint. -- Stephan M. Bernsee http://www.dspdimension.com
From a signal processing point of view, I would use the standard interpolation 
(with Low Pass filter) to get to  40 kHz, and then use linear interpolation.

As memory serves the Sinc Interpolation is not optimal in any sense, and except 
for Kaiser windows you don't really have any control over the dB ripple, 
attenaution or transition width. Atleast with the Parks McClellan algorithm you 
get some optimality.

By upsampling first, you leave the frequency content at the lower frequencies, 
and you put yourself in position to get the best out of the linear 
interpolation.

You can of course go to higher frequencies first, and then use the linear 
interpolation. This improves the Lin. Interp. part but at the cost of increased 
complexity in the regular dsp interpolation (pad and filter).

Cheers,
David
"Stephan M. Bernsee" <spam@dspdimension.com> wrote in message 
news:2uosmgF2cs5f1U2@uni-berlin.de...
> On 2004-11-02 07:43:41 +0100, Erik de Castro Lopo <nospam@mega-nerd.com> said: > >> Sorry, thats just plain bad advice. >> >> Linear interpolation can provide reasonable results if the >> highest frequency component is 1/4 of the sample frequency >> or less. However, for audio sampled at 8kHz this is unlikey >> to be the case. In fact it is likey to have a large amount >> of energy in the 2-4kHz band and its this band where linear >> interpolation performs worst. >> >> Erik > > I concur with Erik and Jon that the use of zero order hold interpolation and > linear interpolation isn't a wise thing from the technical perspective. The > best option would be a sinc interpolation or at least a reasonably long FIR > approximation of it. > > However, in defense of what Rob said, I would agree with him that due to the > artifacts introduced when improperly upsampling a signal from 8kHz to 44.1kHz > it may be perceptually better to use linear interpolation in that specific > case. > > Our perception usually prefers *any* kind of energy over zero energy at a > certain band, most likely because zero energy at a certain frequency rarely > happens in nature. When you are upsampling from 8kHz to 44.1kHz you get a very > large area that contains (almost) no energy which tends to sound "unnatural" > and "dead" to a listener when using hi-end reproduction. Linear interpolation > will add some noise which might sound more natural, even though it isn't > "politically correct" from the DSP viewpoint. > -- > Stephan M. Bernsee > http://www.dspdimension.com >
"Stephan M. Bernsee" <spam@dspdimension.com> wrote in message
news:2uosmgF2cs5f1U2@uni-berlin.de...
> On 2004-11-02 07:43:41 +0100, Erik de Castro Lopo <nospam@mega-nerd.com> said: > > Our perception usually prefers *any* kind of energy over zero energy at > a certain band, most likely because zero energy at a certain frequency > rarely happens in nature. When you are upsampling from 8kHz to 44.1kHz > you get a very large area that contains (almost) no energy which tends > to sound "unnatural" and "dead" to a listener when using hi-end > reproduction. Linear interpolation will add some noise which might > sound more natural, even though it isn't "politically correct" from the > DSP viewpoint.
That is an interesting perspective, Stephan. I hadn't thought of that myself. I'll have to listen both ways and see if it makes any difference. I suppose an alternative would be to use "good" interpolation, but then generate some artificial high frequency content by either adding band-limited noise or using some type of "harmonic exciter" algorithm. But maybe the linear interpolation method accomplishes a similar thing very cheaply?