DSPRelated.com
Forums

downsampling + upsampling gain problems.

Started by guillem April 9, 2008
Hello all!

I have a 1000 Hz fs signal and to achieve a 2000 order 0.5 Hz lowpass fir
filtering I've filtered with a 150/500( = f_s(1/2)) lowpass filter and
downsampled 1/10. 

Then I've filtered the signal using a 200 order 0.5/50 lowpass filter and
later on, upsampled adding 9 zeros for each filtered data and filtered
using a 100 order 10/500 Hz lowpass filter. 

Since I think I've done all rightly, the output signal seems to have 1/10
magnitude compared with the same signal directly filtered with the 2000
order 0.5 Hz lowpass fir.

One thing is that I am working whith signed int 16 data, the filter
coeficients are exported to C using matlab fdatool.

I don't understand why I have this lower amplitude.


On Apr 9, 6:23 am, "guillem" <serra.guil...@gmail.com> wrote:
> Hello all! > > I have a 1000 Hz fs signal and to achieve a 2000 order 0.5 Hz lowpass fir > filtering I've filtered with a 150/500( = f_s(1/2)) lowpass filter and > downsampled 1/10. > > Then I've filtered the signal using a 200 order 0.5/50 lowpass filter and > later on, upsampled adding 9 zeros for each filtered data and filtered > using a 100 order 10/500 Hz lowpass filter. > > Since I think I've done all rightly, the output signal seems to have 1/10 > magnitude compared with the same signal directly filtered with the 2000 > order 0.5 Hz lowpass fir. > > One thing is that I am working whith signed int 16 data, the filter > coeficients are exported to C using matlab fdatool. > > I don't understand why I have this lower amplitude.
When interpolating as you've described, there typically is a gain of 1/10 because you effectively address the filter coefficients with a stride of 10. If all of the coefficients sum to one, then 1/10 of them probably sums to 1/10. This does not occur when you decimate, because you address the coefficients with a stride of 1. So my guess is the loss is occurring in your interpolation stage. John

guillem wrote:
> > Hello all! > > I have a 1000 Hz fs signal and to achieve a 2000 order 0.5 Hz lowpass fir > filtering I've filtered with a 150/500( = f_s(1/2)) lowpass filter and > downsampled 1/10. > > Then I've filtered the signal using a 200 order 0.5/50 lowpass filter and > later on,
This doesn't sound right. Are you saying that you did some of the low pass filtering *after* you arrived at the new sample rate?
> upsampled adding 9 zeros for each filtered data and filtered > using a 100 order 10/500 Hz lowpass filter. > > Since I think I've done all rightly, the output signal seems to have 1/10 > magnitude compared with the same signal directly filtered with the 2000 > order 0.5 Hz lowpass fir. > > One thing is that I am working whith signed int 16 data, the filter > coeficients are exported to C using matlab fdatool. > > I don't understand why I have this lower amplitude.
Are you saying that you reduced the sample rate by 10 and then as a check on your method you upsampled by 10? Either your test signal has most of its content above .5 Hz or the gain (scale) of your filters is not correct. -jim ----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= - Total Privacy via Encryption =---
Hi,

   Whenever you do zero insertion it leads to spectrum
   unrolling or traversing on unit circle one more time.

   For example if I take a sine wave of 1000 Hz, and
   Fs = 4000 Hz. and look at the FFT spectrum I will
   see 2 spikes. One at 1000 Hz and another one at
   4000-1000 == 3000 Hz (image component or negative
   frequency component). Both the spikes will have 
   amplitude = 0.5

   Now if I zero insert (1 zero in between) and perform
   FFT using 8000 hz as reference, I will see 4 spikes
   at 1000 hz, 3000 hz, 5000 hz and 7000 hz. This is 
   something like spectrum unrolling. the magnitudes of
   the 4 spikes will be 0.25 (as the power got redistributed)
   to 4 components, by means of zero insertion.

   This is example of upsampling by 2. I = 2. spectrum
   gets scaled down by 1/2 = 1/I

   when you insert 9 zeros, this is an example of performing
   interpolation by I = 10. Hence in this case the spectrum
   will get scaled down by 1/I == 1/10

   This can be solved 2 ways. Either scale up the input
   or scale up the coefficients. In fixed point implementations
   better approach is to scale up the coefficients.

Regards
Bharat Pathak

Arithos Designs
www.Arithos.com

DSP design consultancy and training company.
Thank you for your answers, They clarify me the problem (and the solution).
Jim, I want to answer your questions:

>> I have a 1000 Hz fs signal and to achieve a 2000 order 0.5 Hz lowpass
fir
>> filtering I've filtered with a 150/500( = f_s(1/2)) lowpass filter and >> downsampled 1/10. >> >> Then I've filtered the signal using a 200 order 0.5/50 lowpass filter
and
>> later on,
> This doesn't sound right. Are you saying that you did some of the low
pass
> filtering *after* you arrived at the new sample rate?
I choose each 1/10 data signal and then I make the convolution of the original signal and the filter. I don't make the convolution of each signal, to avoid operations because I will leave them.
>> upsampled adding 9 zeros for each filtered data and filtered >> using a 100 order 10/500 Hz lowpass filter. >> >> Since I think I've done all rightly, the output signal seems to have
1/10
>> magnitude compared with the same signal directly filtered with the
2000
>> order 0.5 Hz lowpass fir. >> >> One thing is that I am working whith signed int 16 data, the filter >> coeficients are exported to C using matlab fdatool. >> >> I don't understand why I have this lower amplitude.
> Are you saying that you reduced the sample rate by 10 and then as a
check
> on your method you upsampled by 10? Either your test signal has most of > its content above .5 Hz or the gain (scale) of your filters is not > correct.
The idea is to delete to the base drift line to its signal. So using a high pass 0.5 filter with a 1000 Hz signal I need too much order (2000 or more). So I've downsampled the signal, lowpass filter 0.5 (obtaining the base drift signal), rescale it to its original fs, and substract it from the original signal.
On Apr 9, 6:23&#4294967295;am, "guillem" <serra.guil...@gmail.com> wrote:
> Hello all! > > I have a 1000 Hz fs signal and to achieve a 2000 order 0.5 Hz lowpass fir > filtering I've filtered with a 150/500( = f_s(1/2)) lowpass filter and > downsampled 1/10. >
Other people have commented on other parts, so I am only commenting on this parrt. It sounds like you are bandlimiting to 150 Hz at fs=1000 Hz then down sampling. Is that correct? If so, then you have not sufficiently bandlimited your signal prior to down sampling to avoid aliasing. Also, if you are going to do this type of approach to get a highpass filter, look at implementing the lowpass filter with multirate methods for an extreme computational reduction. Dirk
guillem wrote:

> The idea is to delete to the base drift line to its signal. So using a > high pass 0.5 filter with a 1000 Hz signal I need too much order (2000 or > more). So I've downsampled the signal, lowpass filter 0.5 (obtaining the > base drift signal), &#4294967295;rescale it to its original fs, and substract it from > the original signal.
Rick has written a neat article on a highly efficient linear-phase DC (base drift) removal method here: http://www.dsprelated.com/showarticle/58.php It might be of interest to you. Regards, Andor
>On Apr 9, 6:23=A0am, "guillem" <serra.guil...@gmail.com> wrote: >> Hello all! >> >> I have a 1000 Hz fs signal and to achieve a 2000 order 0.5 Hz lowpass
fir
>> filtering I've filtered with a 150/500( =3D f_s(1/2)) lowpass filter
and
>> downsampled 1/10. >> > >Other people have commented on other parts, so I am only commenting on >this parrt. It sounds like you are bandlimiting to 150 Hz at fs=3D1000 >Hz then down sampling. Is that correct? If so, then you have not >sufficiently bandlimited your signal prior to down sampling to avoid >aliasing. > >Also, if you are going to do this type of approach to get a highpass >filter, look at implementing the lowpass filter with multirate methods >for an extreme computational reduction. > >Dirk >
I think I should use a 10~15 Hz lowpass filter because I'm only interested in 0~1 Hz signal (base line drifft). But on the other hand, which process can optimize using multirate methods? I do only the convolution of the 1/10 selected signals (I can't use FFT becaue it must be real time) and then in the interpolation, I avoid multiply by zero.
On Apr 9, 11:30&#4294967295;am, "guillem" <serra.guil...@gmail.com> wrote:
> >On Apr 9, 6:23=A0am, "guillem" <serra.guil...@gmail.com> wrote: > >> Hello all! > > >> I have a 1000 Hz fs signal and to achieve a 2000 order 0.5 Hz lowpass > fir > >> filtering I've filtered with a 150/500( =3D f_s(1/2)) lowpass filter > and > >> downsampled 1/10. > > >Other people have commented on other parts, so I am only commenting on > >this parrt. It sounds like you are bandlimiting to 150 Hz at fs=3D1000 > >Hz then down sampling. Is that correct? &#4294967295;If so, then you have not > >sufficiently bandlimited your signal prior to down sampling to avoid > >aliasing. > > >Also, if you are going to do this type of approach to get a highpass > >filter, look at implementing the lowpass filter with multirate methods > >for an extreme computational reduction. > > >Dirk > > I think I should use a 10~15 Hz lowpass filter because I'm only interested > in 0~1 Hz signal (base line drifft). But on the other hand, which process > can optimize using multirate methods? > > I do only the convolution of the 1/10 selected signals (I can't use FFT > becaue it must be real time) and then in the interpolation, I avoid > multiply by zero.- Hide quoted text - > > - Show quoted text -
I took 150/500 to mean a 150 Hz BW. The rate you mention is okay. You could do a series of lowpass filters that decimate by small amounts to get to a low rate, apply a linear phase FIR filter, and interpolate back to the original rate. You could probably start with a CIC filter (has been discussed in this forum at length), followed by a series of decimating half-band filters that have very few coefficients (discussed here also), final FIR at a very low rate, interpolate using a series of halfband filters, final interpolation with CIC filter. If you haven't done CIC filters, or don't want to bother, just use the half-band filters and the FIR filter. You will end up with very few multiplies and adds per input/output sample. Be aware that a filter with a very narrow bandwidth relative to the sample rate will have a long impulse response, so from the time the signal starts the filter will have to filter a number of samples equal to about half the length of the filter before it starts acting like the filter you want. Dirk
On Apr 9, 11:55&#4294967295;am, dbell <bellda2...@cox.net> wrote:
> On Apr 9, 11:30&#4294967295;am, "guillem" <serra.guil...@gmail.com> wrote: > > > > > > > >On Apr 9, 6:23=A0am, "guillem" <serra.guil...@gmail.com> wrote: > > >> Hello all! > > > >> I have a 1000 Hz fs signal and to achieve a 2000 order 0.5 Hz lowpass > > fir > > >> filtering I've filtered with a 150/500( =3D f_s(1/2)) lowpass filter > > and > > >> downsampled 1/10. > > > >Other people have commented on other parts, so I am only commenting on > > >this parrt. It sounds like you are bandlimiting to 150 Hz at fs=3D1000 > > >Hz then down sampling. Is that correct? &#4294967295;If so, then you have not > > >sufficiently bandlimited your signal prior to down sampling to avoid > > >aliasing. > > > >Also, if you are going to do this type of approach to get a highpass > > >filter, look at implementing the lowpass filter with multirate methods > > >for an extreme computational reduction. > > > >Dirk > > > I think I should use a 10~15 Hz lowpass filter because I'm only interested > > in 0~1 Hz signal (base line drifft). But on the other hand, which process > > can optimize using multirate methods? > > > I do only the convolution of the 1/10 selected signals (I can't use FFT > > becaue it must be real time) and then in the interpolation, I avoid > > multiply by zero.- Hide quoted text - > > > - Show quoted text - > > I took 150/500 to mean a 150 Hz BW. The rate you mention is okay. > > You could do a series of lowpass filters that decimate by small > amounts to get to a low rate, apply a linear phase FIR filter, and > interpolate back to the original rate. &#4294967295;You could probably start with > a CIC filter (has been discussed in this forum at length), followed by > a series of decimating half-band filters that have very few > coefficients (discussed here also), final FIR at a very low rate, > interpolate using a series of halfband filters, final interpolation > with CIC filter. If you haven't done CIC filters, or don't want to > bother, just use the half-band filters and the FIR filter. &#4294967295;You will > end up with very few multiplies and adds per input/output sample. > > Be aware that a filter with a very narrow bandwidth relative to the > sample rate will have a long impulse response, so from the time the > signal starts the filter will have to filter a number of samples equal > to about half the length of the filter before it starts acting like > the filter you want. > > Dirk- Hide quoted text - > > - Show quoted text -
Ooops. Change "The rate you mention is okay." to "The bandwidth you mention is okay." Dirk