# Upsampling PCM audio: from 6 kHz to 8kHz

What would a straight-forward way to convert an audio payload (PCM 16bit) from 6 kHz to 8kHz? I understand that this is an interpolation problem.

I fear that a linear interpolation would introduce too much noise. If so, what would be a better interpolation? I was looking at Lanczos resampling but I've seen it used in image scaling only and not sure it's worth it for audio.

I'm using Java. I've found the JSSRC library butI would have prefer something more lightweight. Beside, I'm not sure this is really necessary for low-frequency audio (which happens to be decoded from ADPCM).

BTW, I'm not interested in creating a WAV having a 6 kHz frequency header, I really want to resample.

• You can upsample it 4 times and downsample 3 times to achive 8 kHz, don't you?
– Serj
Jan 15, 2015 at 20:39

Using a windowed Sinc interpolation kernel is a very common way to do this kind of sample rate change. A polyphase table with precalculated coefficients allows this kind of rational interpolation to be done by a simple interleaved set of convolutions. You can vary the quality of the resampling by choice of the width and shape of the window on the Sinc function.

No need to upsample and downsample in two stages of operations.

• sorry if I'm wrong but, the sinc interpolation kernel is actually an ideal lowpass filter. And if you dont up/down sample how will you keep the number of samples correct? Polyphase decomposition is an efficient method of up/down rate conversion. These are all based on Discrete-Time Signal Processing, 2e, A.Oppenheim, Ch:4 Sampling of Continuous Time signals, sections: 4.6 and 4.7 Jan 16, 2015 at 21:25
• You get the correct number of samples by interpolating the correct number of points at the proper spacing and phase offset for each result sample point. Jan 16, 2015 at 23:26
• Indeed yes, I think I remembered that method of resampling a dt signal, from its reconstruction formula. Jan 16, 2015 at 23:41
• I'm currently reading ccrma.stanford.edu/~jos/resample/resample.pdf which explains in details how to get there. However, I'm not sure about the "polyphase table" you mentioned. Is it known by any other name? I do realize that coefficients do not need to be calculated every time since they get repeated periodically (scaling by a rational factor here), so they can be computed once and kept in a table. Is this what you meant by polyphase table?
– gawi
Jan 26, 2015 at 17:24
• Yes. A polyphase table is another name for a precalculated table for all the repeating fractional interpolation offsets (perhaps arranged for efficient access or indexing of the needed coefficients for each sample interpolation). Jan 26, 2015 at 18:05

If processing cost is not a problem, you may use the following algorithm for sample rate converting your data from 6 khz to 8 khz.

1- expand your signal x[n] by 8, producing xe[n] (insert 7 zeros after every sample of x[n])
2- design a low pass filter hlpf[n] with a gain of 8 and cutoff frequency pi/8
3- process the expanded signal with this lowpass filter = xef[n]
4- compress output of the filter by 6 via selecting every 6th sample: y[n]=xef[6n]
(NOTE: You can also do this with 4:3 upsample and down sample, with a new filter, which would require less processing cost)

Lowpass filter must be sharp enough to ensure proper anti-aliazing. If this is too much overburden for simple rate conversion then try high order polynomial resampling. That could also be costly however.

• One FIR filter with $\pi/4$ and out of band suppression of about 40...50 dB is the simplest decision here. Polynomial resempling is good enough for the cases of big least common multiple.
– Serj
Jan 15, 2015 at 21:01