DSPRelated.com
Forums

Resampling questions - from 44.1kHz to 48kHz

Started by Newbie January 28, 2004
> Thanks. Do you have any recommendations on software I can use to design
the
> filter - windowed sinc?
Matlab, but I presume you don't have that. You can actually just do it yourself with Excel or a C program from the basic equations for sin(x)/x and say a Hamming window. I'm not all that familiar with other filter packages out there but maybe someone else can help? Or Jim's recommendation on multiple stages is a good idea too.
"Jon Harris" <goldentully@hotmail.com> wrote in message
news:bv97om$pe1oi$1@ID-210375.news.uni-berlin.de...
> > Thanks. Do you have any recommendations on software I can use to design > the > > filter - windowed sinc? > > Matlab, but I presume you don't have that. You can actually just do it > yourself with Excel or a C program from the basic equations for sin(x)/x
and
> say a Hamming window. I'm not all that familiar with other filter
packages
> out there but maybe someone else can help?
Just found this link: http://www.dspguru.com/sw/tools/filtdsn.htm Or you could cough up the $100 for the full version of ScopeFIR and help our buddy Grant Griffin put food on his table! :-)
Hello Newbie,
Instead of directly doing a 147:160 conversion, just do a series of simpler
conversions. Since 147 factors into 3*7*7, I'd look at doing a cascade of 3
interpolator/decimator functions in series. Just write your code so it can
work recursively.

-- 
Clay S. Turner, V.P.
Wireless Systems Engineering, Inc.
Satellite Beach, Florida 32937
(321) 777-7889
www.wse.biz
csturner@wse.biz



"Newbie" <none@available.com> wrote in message
news:usTRb.11943$7s7.4291@newssvr23.news.prodigy.com...
> In article <llnsuxgv.fsf@ieee.org>, yates@ieee.org says... > > > >none@available.com (Newbie) writes: > > > >> I've had a look at dspguru.com and am trying to implement a program
that
> will > >> resample an audio signal from 44.1kHz to 48kHz. I'm running into some > problems > >> - namely too many zeros in my converted file. My algorithm is
basically:
> >> > >> > >> Take 44.1kHz signal and interpolate by padding the signal with L-1 =
159
> zeros > >> in order to oversample. > > > >OK, so you're upsampling by a factor of 160 to a sample rate of 160 *
44100 =
> 7.056 MHz. > > > >> Apply a low pass filter with a stop band freq. of 24kHz > > > >No. The typical upconverter consists of upsampling by a factor of N > >(inserting N-1 zeros) followed by a 1/N interpolating (lowpass) > >filter. The typical downconverter consists of a 1/M lowpass filter > >followed by a M:1 decimator (keeping 1 of M samples). > > > >You can combine the two filters (1/N and 1/M) by simply choosing the
lowest.
> >In this case N = 160 and M = 147, so 1/N is the lowest. Thus you want to > filter > >by 1/N (relative to a sample rate of 7.056 MHz), which corresponds to a > filter > >of bandwidth (7.056 MHz/2) / 160 = 22.05 kHz. > > > >> Downsample by keeping every 1 out of 147 samples > >> > >> Do I need to LPF again? > > > >Not if you did it right. > > > >> Another thing that I'm not sure about is if there is any requirement on
the
> >> number of filter taps. Obviously the more taps I have, the fewer > zero-valued > >> samples will be in my output file. > > > >Aha. Well, yes there is a requirement, but it's not black-and-white.
Let's
> >just take the upsampling stage for a moment and think about what's
happening
> >in the frequency domain. The original 44.1 kHz signal has a repetitive > spectrum > >out to infinity, repeating at multiples of 44.1 kHz. After you upsample
by
> 160 > >by inserting 159 zeros, the resulting spectrum hasn't changed. However,
since
> >your sample rate is now 7.056 MHz, the stuff between 22.05 kHz and
7.056/2
> MHz = 3.528 > >MHz has to be filtered out. If that filter isn't perfect, then, at the
7.056
> MHz > >rate, the stuff above 22.05 kHz that leaks through will sound like
garbage
> (if > >you could hear it). So the object is to have you're 1/160 lowpass filter
be
> >down as far as reasonable at 22.05 kHz. For high quality audio, it should > >probably be at least 90 dB or so down. Note that this means that you will > >necessarily have the cutoff frequency at something less than 22.05 kHz.
The
> >closer you get the cutoff frequency to 22.05 kHz, and the more you want
the
> >filter attenuation down at 22.05 kHz, the longer your filter will get. > > > >Another simple point: Obviously your filter was less than 161 taps long, > >hence you are getting the zeros you spoke of. That's a bad sign that > >you probably haven't chosen the passband/stopband characteristics
properly.
> >How did you design the filter? > > > > > Thanks for all of the feedback. I think that you are correct about my
filter
> not being designed correctly. > > I used ScopeFIR and chose Fs = 7056000, passband upper freq = 20kHz, > stopband lower freq. = 22.05kHz, 1 dB passband ripple, and 100 dB stopband > attenuation. I'm not sure what is going on here since the freq. response
plot
> shows the signal to be attenuated ~-75dB at 0 Hz. Also, I've got several
wide
> lobes above the cutoff freq. The lobes can be shorter if I increase the
number
> of filter taps, but then I also get more lobes. > > Please suggest a filter for me to use, including the number of taps. If
the
> number can be < 32 that would be good as my program doesn't support any > higher. > > Lastly, I don't want to use someone elses program as I'm doing this for my
own
> education. In separate projects, I've interpolated audio from 22.05kHz to > 44.1kHz and in another decimated from 48kHz down to 24kHz - these worked
fine.
> The 44.1kHz to 48kHz resampling project so far has proven to be a little
more
> difficult, namely, I believe because of the large interpolation and
decimation
> factors and long filters required. > > > Thx. > > > > > > > > >> Does anyone have any suggestions to implementing this SRC correctly? > > > >Erik has a good point - use his. Unless your goal is the learning > >experience. > >-- > >% Randy Yates % "Though you ride on the wheels of
tomorrow,
> >%% Fuquay-Varina, NC % you still wander the fields of your > >%%% 919-577-9882 % sorrow." > >%%%% <yates@ieee.org> % '21st Century Man', *Time*, ELO > >http://home.earthlink.net/~yatescr >

Newbie wrote:
> > > Thanks. Do you have any recommendations on software I can use to design the > filter - windowed sinc?
Would you please trim the inclusion of posts you respond to down what is necessasary to establish context for what you add to it. Thanks, Bob -- "Things should be described as simply as possible, but no simpler." A. Einstein
"Newbie" <none@available.com> wrote in message
news:OWURb.11694$2y5.9162@newssvr24.news.prodigy.com...
> In article <bv929v$phlpa$1@ID-210375.news.uni-berlin.de>, > goldentully@hotmail.com says... > >
> Thanks. Do you have any recommendations on software I can use to design
the
> filter - windowed sinc? >
Well, there's a couple of ways to look at this objective. One has to do with the overall filtering objective and the other has to do with the design approach for the filter. So, it's easy enough to window a sinc in a spreadsheet as was suggested. The other way is to recognize that it's just a lowpass filter anyway and use the Parks-McClellan program or filter design program of your choice. The zero-crossing spacing of the sinc is directly related to the bandwidth of the lowpass filter. So, you have both pieces of information anyway. Here's a way to look at it: A sinc is of infinite extent and has a perfect lowpass / brick wall frequency response. Not realizable. A windowed sinc is a sinc that's been truncated to a finite length. A rectangular window does the simplest truncation. As a result, the frequency response is no longer perfect and there are noticeable peaks in the stopband. Changing the shape of the window so that it's more tapered has an effect on the frequency response. The more gradual the window, the sharper the frequency response and the lower the stopband ripples - as a very general statement. Note that the zero crossings of the sinc in time don't change when you apply a window - unless the window has zeros itself so that those zeros are potentially adde - which is most unlikely or unusual at least. If you turn the process around and design a lowpass filter: The impulse response will resemble a windowed sinc and the "window" is generally unknown. The zero crossings in time need not remain the same as for a sinc. You can optimize the frequency response more directly this way. Fred
Fred Marshall wrote:

   ...

> A windowed sinc is a sinc that's been truncated to a finite length. > A rectangular window does the simplest truncation. > As a result, the frequency response is no longer perfect and there are > noticeable peaks in the stopband. > Changing the shape of the window so that it's more tapered has an effect on > the frequency response. > The more gradual the window, the sharper the frequency response and the > lower the stopband ripples - as a very general statement.
Sharper frequency response? I think you mean lower stopband ripple (smaller side lobes) and more gradual transition to cutoff. No? ... Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
In article <llnsuxgv.fsf@ieee.org>, Randy Yates  <yates@ieee.org> wrote:
>none@available.com (Newbie) writes: >No. The typical upconverter consists of upsampling by a factor of N >(inserting N-1 zeros) followed by a 1/N interpolating (lowpass) >filter. The typical downconverter consists of a 1/M lowpass filter >followed by a M:1 decimator (keeping 1 of M samples).
This upsample and downsample stuff sounds like a bunch of confusing extra work. How about just applying your lowpass FIR filter directly to the input data, calculating the correct phase taps for any fractional point between input samples, rational or irrational, and getting your output data in a single pass? Then it becomes a matter of approximating or interpolating your windowed sync, or other choosen filter function, instead of all this artificial upsample, downsample work. Does anyone really cares about the intermediate 7 MHz upsampled "signal" with all those stuffed zeros? If not, why bother generating it? So, does anyone have some good polynomial approximations for each lobe of a windowed sync? Or is phase table interpolation the only method worth looking at? IMHO. YMMV. -- Ron Nicholson rhn AT nicholson DOT com http://www.nicholson.com/rhn/ #include <canonical.disclaimer> // only my own opinions, etc.
"Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in message
news:aLydnYdO7ub10oXd4p2dnA@centurytel.net...
> > "Newbie" <none@available.com> wrote in message > news:OWURb.11694$2y5.9162@newssvr24.news.prodigy.com... > > In article <bv929v$phlpa$1@ID-210375.news.uni-berlin.de>, > > goldentully@hotmail.com says... > > > > > > Thanks. Do you have any recommendations on software I can use to design > the > > filter - windowed sinc? > > > > Well, there's a couple of ways to look at this objective. One has to do > with the overall filtering objective and the other has to do with the
design
> approach for the filter. > > So, it's easy enough to window a sinc in a spreadsheet as was suggested. > > The other way is to recognize that it's just a lowpass filter anyway and
use
> the Parks-McClellan program or filter design program of your choice. The > zero-crossing spacing of the sinc is directly related to the bandwidth of > the lowpass filter. So, you have both pieces of information anyway.
The OP said that his filter design program only supported filters up to 32 taps, hence the suggestion for using a spreadsheet. The simplest approach would be of course to get a better filter design program!

Jerry Avins wrote:
> > Fred Marshall wrote: > > > The more gradual the window, the sharper the frequency response and the > > lower the stopband ripples - as a very general statement. > > Sharper frequency response? I think you mean lower stopband ripple > (smaller side lobes) and more gradual transition to cutoff. No?
I just tried it going between a straight truncated and a Hahn window, the cutoff is _much_ sharper. The test was a 65536 point sinc with 100 samples between zero crossings. Bob -- "Things should be described as simply as possible, but no simpler." A. Einstein
"Jerry Avins" <jya@ieee.org> wrote in message
news:40185603$0$11471$61fed72c@news.rcn.com...
> Fred Marshall wrote: > > ... > > > A windowed sinc is a sinc that's been truncated to a finite length. > > A rectangular window does the simplest truncation. > > As a result, the frequency response is no longer perfect and there are > > noticeable peaks in the stopband. > > Changing the shape of the window so that it's more tapered has an effect
on
> > the frequency response. > > The more gradual the window, the sharper the frequency response and the > > lower the stopband ripples - as a very general statement. > > Sharper frequency response? I think you mean lower stopband ripple > (smaller side lobes) and more gradual transition to cutoff. No?
Jerry, Yes. As a general statement that's what I should have said. So now I'm curious about what Bob Cain did.... For general filter design there's a tradeoff between sidelobe level and transition width. The higher the sidelobes, the narrower the transition can be - largely because the definition of width in that case is dependent on the sidelob levels!! But, a given length filter should be limited to a minimum transition width as you say - as long as we don't get too picky about how to define the width to -80dB..... Fred