Forums

How to get rid of resampling artifacts ?

Started by John McDermick November 23, 2010
How do you get rid of resampling artifacts?

The P/Q fixed-point resampler algo I am working on takes as input a
signal which has been upsampled by P (zero insertion) and low-pass
filters the upsampled signal (fc = min[1/P,1/Q] ). In the final step
every Qth filter output sample is kept. The artifacts seems to get
worse when P/Q is much larger than 1...for example when P/Q = 6.
The low-pass filter is an 8th order IIR filter split into 4 second-
order sections.

I fed the resampler with an impulse sampled at 16000Hz and compared
the magnitude spectrum of the output with the magnitude spectrum of
the output from a floating point resampler. The impulse was upsampled
by 6. I see large deviations (spikes) at 7571Hz, 8487Hz and
12771Hz ....the deviation goes through the roof at 48000Hz.

LINK: http://img696.imageshack.us/img696/9840/fig1.png


I fed the resampler with a 440Hz sine sampled at 16000Hz and compared
the magnitude spectrum of the output with the magnitude spectrum of
the output from a floating point resampler. The sine was upsampled by
6. The deviation is more uniform (distance between -20dB to 20dB)
except in the frequency range from 0Hz to 10kHz where I (among others)
see spikes at 1320Hz, 2200Hz, 3080Hz and 3960Hz.

LINK: http://img140.imageshack.us/img140/4731/fig2.png


Please disregard the "noise floor" title in the images. The graphs
shows how many dB the output spectrum of my fixed-point resampler
deviates from the output spectrum of a floating point version of my
resampler.

The deviations can be minimized a LOT by increasing the resolution
(going from a 16bit resampler to a 32bit resampler). What I am
wondering about is if I can improve the resampler and still keep it as
a 16bit fixed-point resampler??

Thank you.


John McDermick wrote:

> How do you get rid of resampling artifacts?
Resampling artifacts are folded aliases and requantization effects. Set the cutoff frequency lower?
> The P/Q fixed-point resampler algo I am working on takes as input a > signal which has been upsampled by P (zero insertion) and low-pass > filters the upsampled signal (fc = min[1/P,1/Q] ). In the final step > every Qth filter output sample is kept. The artifacts seems to get > worse when P/Q is much larger than 1...for example when P/Q = 6. > The low-pass filter is an 8th order IIR filter split into 4 second- > order sections.
What is the rationale for this configuration? Why not a polyphase FIR ?
> The deviations can be minimized a LOT by increasing the resolution > (going from a 16bit resampler to a 32bit resampler).
There is inevitable loss of precision in IIRs. In your case, it probably looses 3-4 bits or so. Not much left from 16 bits.
> What I am > wondering about is if I can improve the resampler and still keep it as > a 16bit fixed-point resampler??
Describe the full picture. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
On Nov 23, 9:53&#2013266080;am, John McDermick <johnthedsp...@gmail.com> wrote:
> How do you get rid of resampling artifacts? > > The P/Q fixed-point resampler algo I am working on takes as input a > signal which has been upsampled by P (zero insertion) and low-pass > filters the upsampled signal (fc = min[1/P,1/Q] ). In the final step > every Qth filter output sample is kept. The artifacts seems to get > worse when P/Q is much larger than 1...for example when P/Q = 6. > The low-pass filter is an 8th order IIR filter split into 4 second- > order sections. > > I fed the resampler with an impulse sampled at 16000Hz and compared > the magnitude spectrum of the output with the magnitude spectrum of > the output from a floating point resampler. The impulse was upsampled > by 6. I see large deviations (spikes) at 7571Hz, 8487Hz and > 12771Hz ....the deviation goes through the roof at 48000Hz. > > LINK:http://img696.imageshack.us/img696/9840/fig1.png
Isn't 48 kHz = Fs/2 of the output? I would expect the filter to be attenuating near these frequencies. In fact, isn't the filter supposed to be attenuating above 8 kHz. I don't understand where you say you put the corner frequency of the filter. 1/P and 1/Q are not frequencies... but maybe I don't understand your notation.
> I fed the resampler with a 440Hz sine sampled at 16000Hz and compared > the magnitude spectrum of the output with the magnitude spectrum of > the output from a floating point resampler. The sine was upsampled by > 6. The deviation is more uniform (distance between -20dB to 20dB) > except in the frequency range from 0Hz to 10kHz where I (among others) > see spikes at 1320Hz, 2200Hz, 3080Hz and 3960Hz. > > LINK:http://img140.imageshack.us/img140/4731/fig2.png > > Please disregard the "noise floor" title in the images. The graphs > shows how many dB the output spectrum of my fixed-point resampler > deviates from the output spectrum of a floating point version of my > resampler. > > The deviations can be minimized a LOT by increasing the resolution > (going from a 16bit resampler to a 32bit resampler). What I am > wondering about is if I can improve the resampler and still keep it as > a 16bit fixed-point resampler??
How do you know these graphs show a problem? Rather than showing how "bad" the fixed point resampler is, maybe you are showing how "good" the floating point resampler is. Why not just plot amplitude relative to a fixed reference? I have seem spectral data that seemed to show the result was horrible, but it was just showing a huge variation, but still good. That may be what you are seeing. Try plotting the fixed point output of the impulse input vs. the average of the fixed point output. That will show the noise floor in a relative way, but still not in an absolute way. A plot with the tone should give you a good absolute reference. I don't even see the 440 Hz tone in your data. So clearly using the floating point design as a reference doesn't give you any sense of absolute noise levels... which is what you really care about, right? Rick
> Resampling artifacts are folded aliases and requantization effects. > Set the cutoff frequency lower?
I've tried, but it doesn't seem to help much.
> What is the rationale for this configuration? > Why not a polyphase FIR ?
I have considered a polyphase, but this implementation is more efficient in terms of memory and cycle consumption. Or maybe I am just overlooking something? Also, I am working with some "tight" filter requirements.
> Describe the full picture.
Ok. The filter coefficients look like this: Numerator Coefficients Section 1 0.0284 -0.0381 0.0284 Section 2 0.4836 -0.8218 0.4836 Section 3 0.7560 -1.3301 0.7560 Section 4 0.2201 0.2201 0 Denominator Coefficients Section 1 1.0000 -1.7690 0.8374 Section 2 1.0000 -1.7850 0.9305 Section 3 1.0000 -1.8010 0.9828 Section 4 1.0000 -0.8796 0 Coeff for the first section would look like this Coeff = [0.0284 -0.0381 0.0284 1.0000 -1.7690 0.8374] Input x is in Q1.15 format Coeff is in Q2.14 format Output y is in Q1.15 format 2nd order IIR filter pseudo code: c1=coeff(1)*x(m) c3=c1+z(1) c4=bitshift(c3,-14) y(m)=c4 c5=coeff(2)*x(m) c7=c5+z(2) c9=coeff(5)*y(m) z(1)=c7-c9 c12=coeff(3)*x(m) c14=coeff(6)*y(m) z(2)=c12-c14 Output spectrum looks like this LINK: http://img101.imageshack.us/img101/6171/fig3.png for a 440Hz sine sampled at 16000Hz which is resampled to 96000Hz.
> How do you know these graphs show a problem? &#2013266080;Rather than showing how > "bad" the fixed point resampler is, maybe you are showing how "good" > the floating point resampler is. &#2013266080;
I would just like to see how far away I am from an "ideal" solution (something that is as close as possible to a floating point solution).... right???
> I don't even see the 440 Hz tone in your data. > So clearly using the floating point design as a reference doesn't give > you any sense of absolute noise levels... which is what you really > care about, right?
The 440 Hz sine is "notched" out when you subtract the output spectrums from each other...You can see the two spectra here: http://img101.imageshack.us/img101/6171/fig3.png
On Nov 23, 1:01&#2013266080;pm, John McDermick <johnthedsp...@gmail.com> wrote:
> > How do you know these graphs show a problem? &#2013266080;Rather than showing how > > "bad" the fixed point resampler is, maybe you are showing how "good" > > the floating point resampler is. &#2013266080; > > I would just like to see how far away I am from an "ideal" solution > (something > that is as close as possible to a floating point solution).... > right??? > > > I don't even see the 440 Hz tone in your data. > > So clearly using the floating point design as a reference doesn't give > > you any sense of absolute noise levels... which is what you really > > care about, right? > > The 440 Hz sine is "notched" out when you subtract the output > spectrums > from each other...You can see the two spectra here: > > http://img101.imageshack.us/img101/6171/fig3.png
Yes, I understand. That is my point. The two approaches match well in some areas an not others... so? Where you see 100 dB peaks, you can't say if they are peaks in the fixed point design or nulls in the floating point design. Right? Do you care if your fixed point approach is 100 dB worse than the floating point approach if the floating point has 500 dB of head room? Until you show me the response relative the carrier or full scale or something else that is actually relevant, I am not convinced you have a problem. Rick
>Try plotting the fixed >point output of the impulse input vs. the average of the fixed point >output. That will show the noise floor in a relative way, but still >not in an absolute way.
Do you mean plotting X - mean(X) ??? ...where X contains the magnitudes expressed in dB If so, here is the plot: http://img593.imageshack.us/img593/6756/fig4.png The plot shows the magnitude spectrum of the resampler output (in dB) - the mean of that spectrum.
John McDermick <johnthedspguy@gmail.com> writes:

>> Resampling artifacts are folded aliases and requantization effects. >> Set the cutoff frequency lower? > > I've tried, but it doesn't seem to help much. > > >> What is the rationale for this configuration? >> Why not a polyphase FIR ? > > I have considered a polyphase, but this implementation is more > efficient in terms of memory and cycle consumption. Or maybe > I am just overlooking something? Also, I am working with some > "tight" filter requirements. > > >> Describe the full picture. > > Ok. The filter coefficients look like this: > > Numerator Coefficients > > Section 1 0.0284 -0.0381 0.0284 > Section 2 0.4836 -0.8218 0.4836 > Section 3 0.7560 -1.3301 0.7560 > Section 4 0.2201 0.2201 0 > > Denominator Coefficients > > Section 1 1.0000 -1.7690 0.8374 > Section 2 1.0000 -1.7850 0.9305 > Section 3 1.0000 -1.8010 0.9828 > Section 4 1.0000 -0.8796 0
John, this filter doesn't look all that great: http://galois.digitalsignallabs.com/filter.png I'm not sure if there are any numerical precision issues here, but judging from the relatively mild stopband of -70 dB or so, I would think not. This is in Octave's double-precision floating point. --Randy
> > Coeff for the first section would look like this > > Coeff = [0.0284 -0.0381 0.0284 1.0000 -1.7690 0.8374] > > Input x is in Q1.15 format > > Coeff is in Q2.14 format > > Output y is in Q1.15 format > > 2nd order IIR filter pseudo code: > > c1=coeff(1)*x(m) > c3=c1+z(1) > c4=bitshift(c3,-14) > y(m)=c4 > > c5=coeff(2)*x(m) > c7=c5+z(2) > c9=coeff(5)*y(m) > z(1)=c7-c9 > > c12=coeff(3)*x(m) > c14=coeff(6)*y(m) > z(2)=c12-c14 > > > > Output spectrum looks like this > > LINK: http://img101.imageshack.us/img101/6171/fig3.png > > for a 440Hz sine sampled at 16000Hz which is resampled to 96000Hz.
-- Randy Yates % "She's sweet on Wagner-I think she'd die for Beethoven. Digital Signal Labs % She love the way Puccini lays down a tune, and mailto://yates@ieee.org % Verdi's always creepin' from her room." http://www.digitalsignallabs.com % "Rockaria", *A New World Record*, ELO
> John, this filter doesn't look all that great: >
Why does the filter look bad? What is it exactly that you are looking at that makes you say that the filter looks bad?
On Nov 23, 3:53&#2013266080;pm, John McDermick <johnthedsp...@gmail.com> wrote:
> How do you get rid of resampling artifacts? > > The P/Q fixed-point resampler algo I am working on takes as input a > signal which has been upsampled by P (zero insertion) and low-pass > filters the upsampled signal (fc = min[1/P,1/Q] ). In the final step > every Qth filter output sample is kept. The artifacts seems to get > worse when P/Q is much larger than 1...for example when P/Q = 6. > The low-pass filter is an 8th order IIR filter split into 4 second- > order sections. > > I fed the resampler with an impulse sampled at 16000Hz and compared > the magnitude spectrum of the output with the magnitude spectrum of > the output from a floating point resampler.
Don't do that. Compare apples with apples and oranges with oranges. First represent thet input signal as a sequence of floating-point numbers, and use the floating-point resampler on this sequence. Compare spectra of these input and output signals. Then resample the input signal to whatever fixed-pt precision you use, and run it through the fixed-pt resampler. Note that in this version the filter coefficients of your FIR also have to be represented as fixed-pt numbers. Now compare these input and output spectra. Once you are done with this, compare the spectra of the floating pt and fixed pt input signals. The difference is due to quantization noise. There is nothing you can do about it, except understand why it's there and what causes it. Rune