DSPRelated.com
Forums

Beginning Interpolation

Started by Stacy May 10, 2007
Given: x(n) which is a sequence sampled at Fs1 = 8000 samples/sec.
Find: Interpolate x(n) up to Fs2 = 48k samples/sec. L = 6.       

Solution?
1) zero pack x(n) by placing L-1 = 5 zeros after every sample.

2) design anti-imaging filter.

   Using Matlabs fir1,
   
   b = fir1(N, Fs)

3) Run an FIR filter on x(n*L) using b.

Question: Based on fir1(N, Fs),
   i)  what is the recommended way to determine N?
       Or to re-phrase, what are the recommended passband, stopband, and
       deltas which determine N when used in fir1 for an FIR
Interpolation
       filter?
   ii) what value should Fs be? I would imagine it should be a little
less
       than Fs1/2? If so how much less and why?

Note: I'm aware of Matlabs upfirdn. However, I wish to do the actual 
      filtering using the coefficients returned by fir1 in a C# coded 
      program.
      
      I also have been to the dspgru's resampling site.





_____________________________________
Do you know a company who employs DSP engineers?  
Is it already listed at http://dsprelated.com/employers.php ?
On 10 May, 20:42, "Stacy" <stacy2003_yo...@yahoo.com> wrote:
> Given: x(n) which is a sequence sampled at Fs1 = 8000 samples/sec. > Find: Interpolate x(n) up to Fs2 = 48k samples/sec. L = 6. > > Solution? > 1) zero pack x(n) by placing L-1 = 5 zeros after every sample. > > 2) design anti-imaging filter. > > Using Matlabs fir1, > > b = fir1(N, Fs) > > 3) Run an FIR filter on x(n*L) using b. > > Question: Based on fir1(N, Fs), > i) what is the recommended way to determine N? > Or to re-phrase, what are the recommended passband, stopband, and > deltas which determine N when used in fir1 for an FIR > Interpolation > filter?
That's up to you to decide. Clearly, the passband edge should be somewhere in the area around Fs1/2, but you would have to decide on a transition bandwidth. The transition band should be selected such that all the baseband signal is let throug, and the mirror around Fs1 is rejected. Getting that right depends on the nature of the baseband signal, and how much oversampling was used in the original system.
> ii) what value should Fs be? I would imagine it should be a little > less > than Fs1/2? If so how much less and why?
What do you mean? The original sampling frequency Fs1 is given, and so is the resulting sampling frequency Fs2. Rune
Stacy wrote:
> Given: x(n) which is a sequence sampled at Fs1 = 8000 samples/sec. > Find: Interpolate x(n) up to Fs2 = 48k samples/sec. L = 6. > > Solution? > 1) zero pack x(n) by placing L-1 = 5 zeros after every sample. > > 2) design anti-imaging filter. > > Using Matlabs fir1, > > b = fir1(N, Fs) > > 3) Run an FIR filter on x(n*L) using b. > > Question: Based on fir1(N, Fs), > i) what is the recommended way to determine N?
There are various estimation formulas, to be checked by testing to see if the resulting filter is over- or under designed. Doesn't Matlab have one?
> Or to re-phrase, what are the recommended passband, stopband, and > deltas which determine N when used in fir1 for an FIR > Interpolation > filter?
The stopband must begin at Fs1/2 or lower. The passband as much below that as a practical filter can achieve. What is practical depends ...
> ii) what value should Fs be? I would imagine it should be a little > less > than Fs1/2? If so how much less and why?
You just upsampled (i.e. interpolated) to Fs = 48 KHz. What else could the sample rate be? ... Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
Stacy wrote:
> Given: x(n) which is a sequence sampled at Fs1 = 8000 samples/sec. > Find: Interpolate x(n) up to Fs2 = 48k samples/sec. L = 6. > > Solution? > 1) zero pack x(n) by placing L-1 = 5 zeros after every sample. > > 2) design anti-imaging filter. > > Using Matlabs fir1, > > b = fir1(N, Fs) > > 3) Run an FIR filter on x(n*L) using b. > > Question: Based on fir1(N, Fs), > i) what is the recommended way to determine N? > Or to re-phrase, what are the recommended passband, stopband, and > deltas which determine N when used in fir1 for an FIR > Interpolation filter?
I would juggle my desire for high speed on a cheap processor (low N) with good signal fidelity (high N).
> ii) what value should Fs be? I would imagine it should be a little > less than Fs1/2? If so how much less and why?
As much less as you need to get the quality you want. Yes, this is vague, but (a) you have to meet _your_ requirements with (b) _your_ signal (which I know nothing about), and (c) I'm not terribly familiar with MatLab!
> > Note: I'm aware of Matlabs upfirdn. However, I wish to do the actual > filtering using the coefficients returned by fir1 in a C# coded > program. > > I also have been to the dspgru's resampling site.
You may find it helpful to read my paper on sampling: http://www.wescottdesign.com/articles/Sampling/sampling.html. It's about sampling from the continuous rather than decimation, but many of the same issues apply. The really real bottom line here is that you can't do a perfect job, so there's no one good answer. The best you can do is a graceful compromise, and for that you need to understand your requirements and state them in a way that makes sense to your problem at hand. Once you do that, then your filter design exercise will be relatively easy. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" gives you just what it says. See details at http://www.wescottdesign.com/actfes/actfes.html
Tim Wescott wrote:
> Stacy wrote:
...
>> ii) what value should Fs be? I would imagine it should be a little >> less than Fs1/2? If so how much less and why? > > As much less as you need to get the quality you want. ...
Reconsider, Tim. Fs is what it is: 48 KHz by design. Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
>Tim Wescott wrote: >> Stacy wrote: > > ... > >>> ii) what value should Fs be? I would imagine it should be a little >>> less than Fs1/2? If so how much less and why? >> >> As much less as you need to get the quality you want. ... > >Reconsider, Tim. Fs is what it is: 48 KHz by design. > >Jerry >-- >Engineering is the art of making what you want from things you can get. >&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr; >
I'll do the following: 1) Zero pack x(n) by adding 5 zeros after every sample. (L = 6) 2) Get the coefficients for an anti-imaging filter with matlab's b = fir1(N, Wn), where N is the filter size, b are the coefficients. The cut-off frequency Wn must be between 0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. Therefore I'll use: b = fir1(N, .8) (N is tbd for now) 3) Use an FIR Filter with b coefficients on x(n*L). Due note: this is a first attempt on my part of interpolation. What say you? _____________________________________ Do you know a company who employs DSP engineers? Is it already listed at http://dsprelated.com/employers.php ?
Stacy wrote:
...

> I'll do the following: > > 1) Zero pack x(n) by adding 5 zeros after every sample. (L = 6)
Good.
> 2) Get the coefficients for an anti-imaging filter with matlab's > b = fir1(N, Wn), where N is the filter size, b are the coefficients. > The cut-off frequency Wn must be between 0 < Wn < 1.0, with 1.0 > corresponding to half the sample rate.
Premature. Decide on the characteristics that the filter needs to have: + Stopband attenuation -- 40 dB? + Passband ripple 2 dB? less if you don't need to squeeze too hard + Stopband lower frequency -- at or slightly below 4 KHz. + Passband upper frequency -- As high as you have patience and resources to achieve.
> Therefore I'll use: b = fir1(N, .8) > (N is tbd for now)
Once you know what you need, use it.
> 3) Use an FIR Filter with b coefficients on x(n*L).
IOW, filter the signal. Jerry Engineering is the art of making what you want from things you can get.
Jerry wrote:
>Premature. Decide on the characteristics that the filter needs to >have: >+ Stopband attenuation -- 40 dB? >+ Passband ripple 2 dB? less if you don't need to squeeze too hard >+ Stopband lower frequency -- at or slightly below 4 KHz. >+ Passband upper frequency -- As high as you have patience and >resources to achieve.
b = fir1(N, .8) N, the filter length is determined based on the parameters you mentioned above.
>IOW, filter the signal.
I am not familiar with the term IOW. Thanks Jerry. _____________________________________ Do you know a company who employs DSP engineers? Is it already listed at http://dsprelated.com/employers.php ?
Stacy wrote:
> I am not familiar with the term IOW.
IOW = In Other Words. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536 The real fun of living wisely is that you get to be smug about it. - Hobbes
Stacy wrote:

>> IOW, filter the signal. > > I am not familiar with the term IOW.
Sorry. "In Other Words." http://users.erols.com/jyavins/acronyms.html might interest you, Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;