DSPRelated.com
Forums

what makes a negative output result from a FIR bandpass filter?

Started by Simon May 26, 2006
I am try to implement a FIR bandpass filter in C2000 DSP.

I got the coefficients from FDATOOL
order=10;  % FIR filter order
fs:=500 HZ, % sampling frequency
fp1=60HZ,   %
fp2=100HZ, %

fstop1=20HZ,
fstop2=140HZ,
...
Then I   got the coefficients, And I muliply 32767 to make them Q15
format due to the need of
the FIR.asm provide by TI 24x filter library.

It's:
#define FIR_BPF10 {\
            644,-584,-2643,-2063,2001,4560,2001,-2063,-2643,-584,\
            644}


I use the frequency generator to generate the input sigal: sine wave
     freqency:    66HZ
     offset: 1000mVolt
     range:       almost in 1000V-3000mVolt
And my DSP AD sampling frequency is 500HZ
since the frequency is in the bandpass range [60, 100]HZ. The output
should be almost the same as input.

But I found actually, the output is very small. and even less then zero
after the FIR filter is stable .

Then I  load the data in the delay buffer from DSP.

dbuffer=[2358 2988 3087 2599 1801 1253 1271 1862 2647 3104]

I use the definition of FIR . y=... h(k)*x(n-k).

then I got the result is 386mv.

then I just confused, anyway, The FDATOOL must be right.

Then what's wrong with my implementation.

Thanks.




Refence: 24X filter library

Simon wrote:
> I am try to implement a FIR bandpass filter in C2000 DSP. > > I got the coefficients from FDATOOL
...
> then I just confused, anyway, The FDATOOL must be right. > > Then what's wrong with my implementation.
These are two questions. First, you need to understand how the filter works. You need to use a simulated signal (or some measurement you have stored) as a test to see how the filter you have designed actually works. You use matlab for this. Once you are confident the filter works as you want it to, you transfer it to the DSP, taking into account the various technical aspects concerning number formats etc. Again, use a test setup and see if the filter performs as expected. Use matlab to simulate the various steps (fixed-point arithmetics, offsets) if you do not quite understand what is going on. FDATOOL is only a tool. It does nothing by itself, it does what *you* tell it to do. If there are mistakes or errors, it is because *you* made them. If the filter works, it is because *you* desigend it to. Would you blame the hammer if you didn't manage to hit a nail straight? Rune
Rune Allnor wrote:

> Simon wrote: > >>I am try to implement a FIR bandpass filter in C2000 DSP. >> >>I got the coefficients from FDATOOL > > ... > >>then I just confused, anyway, The FDATOOL must be right. >> >>Then what's wrong with my implementation. > > > These are two questions. > > First, you need to understand how the filter works. You need to use > a simulated signal (or some measurement you have stored) as a test > to see how the filter you have designed actually works. You use > matlab for this. > > Once you are confident the filter works as you want it to, you > transfer it to the DSP, taking into account the various technical > aspects concerning number formats etc. Again, use a test setup > and see if the filter performs as expected. Use matlab to simulate > the various steps (fixed-point arithmetics, offsets) if you do not > quite understand what is going on. > > FDATOOL is only a tool. It does nothing by itself, it does what *you* > tell it to do. If there are mistakes or errors, it is because *you* > made > them. If the filter works, it is because *you* desigend it to. > > Would you blame the hammer if you didn't manage to hit a > nail straight?
There's no need to beat up on poor Simon. he writes "FDATOOL must be right" and asks what *he* is doing wrong. Matlab isn't the only way to design filters. Maybe we can help him troubleshoot his FIR. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Simon wrote:

> I am try to implement a FIR bandpass filter in C2000 DSP. > > I got the coefficients from FDATOOL > order=10; % FIR filter order > fs:=500 HZ, % sampling frequency > fp1=60HZ, % > fp2=100HZ, % > > fstop1=20HZ, > fstop2=140HZ, > ... > Then I got the coefficients, And I muliply 32767 to make them Q15 > format due to the need of > the FIR.asm provide by TI 24x filter library. > > It's: > #define FIR_BPF10 {\ > 644,-584,-2643,-2063,2001,4560,2001,-2063,-2643,-584,\ > 644} > > > I use the frequency generator to generate the input sigal: sine wave > freqency: 66HZ > offset: 1000mVolt > range: almost in 1000V-3000mVolt > And my DSP AD sampling frequency is 500HZ > since the frequency is in the bandpass range [60, 100]HZ. The output > should be almost the same as input. > > But I found actually, the output is very small. and even less then zero > after the FIR filter is stable . > > Then I load the data in the delay buffer from DSP. > > dbuffer=[2358 2988 3087 2599 1801 1253 1271 1862 2647 3104] > > I use the definition of FIR . y=... h(k)*x(n-k). > > then I got the result is 386mv. > > then I just confused, anyway, The FDATOOL must be right. > > Then what's wrong with my implementation. > > Thanks.
Simon, I don't know what's wrong with your implementation, but I know what I would do to find out. Make all but one of your filter coefficients zero. Make the exception unity. If the output isn't a delayed version of the input, and if the delay isn't established by the position of the unity coefficient, find out why and fix it. Once that works, restore the calculated coefficients and test again. I'm sure you can take it from there. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Thanks Rune and Jerry,
        I have found the problem with your advice. Actually, no fault
in FDATOOL and my implementation. But some basic misunderstanding and
foolish mistake. I am a newcomer to this field. Every step forward
costed me too much time, it's painful, but
 thanks, anyway, I knew more.

Simon wrote:
> Thanks Rune and Jerry, > I have found the problem with your advice. Actually, no fault > in FDATOOL and my implementation. But some basic misunderstanding and > foolish mistake. I am a newcomer to this field. Every step forward > costed me too much time, it's painful, but > thanks, anyway, I knew more.
Learning is often slower than we like. It takes about the same time no matter how much intelligence (above a certain minimum) you bring to it, so the smarter on is, the greater the discrepancy seems. I'm delighted to have been able to help a little; I'm sure Rune is too. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins wrote:
> Rune Allnor wrote: > > > Simon wrote: > > > >>I am try to implement a FIR bandpass filter in C2000 DSP. > >> > >>I got the coefficients from FDATOOL > > > > ... > > > >>then I just confused, anyway, The FDATOOL must be right. > >> > >>Then what's wrong with my implementation. > > > > > > These are two questions. > > > > First, you need to understand how the filter works. You need to use > > a simulated signal (or some measurement you have stored) as a test > > to see how the filter you have designed actually works. You use > > matlab for this. > > > > Once you are confident the filter works as you want it to, you > > transfer it to the DSP, taking into account the various technical > > aspects concerning number formats etc. Again, use a test setup > > and see if the filter performs as expected. Use matlab to simulate > > the various steps (fixed-point arithmetics, offsets) if you do not > > quite understand what is going on. > > > > FDATOOL is only a tool. It does nothing by itself, it does what *you* > > tell it to do. If there are mistakes or errors, it is because *you* > > made > > them. If the filter works, it is because *you* desigend it to. > > > > Would you blame the hammer if you didn't manage to hit a > > nail straight? > > There's no need to beat up on poor Simon. he writes "FDATOOL must be > right" and asks what *he* is doing wrong.
I apologize if I beat Simon up too badly. Still, knowing how the tools work -- and don't work -- is part of the game.
> Matlab isn't the only way to design filters. Maybe we can help him > troubleshoot his FIR.
I hope so. Rune
Hi Simon,

There is never any guarantee that any filter design tool (ie: FDATOOL)
will make a proper filter, and it's always necessary to test the filter
to ensure that it works properly (ie: according to your
specifications).

That said, if you are making a bandpass filter, it will naturally
reject DC.   Therefore a positve impulse at the input (all frequencies
present) will result in a set of spikes (reading out the coefficient
values).  If you provide an input signal which only contains frequency
components outside of the bandwidth of the filter (and the filter is
doing it's job), your results will tend to go towards zero.

If you like, there is a cool Quicktime animation which shows the
frequency and time responses of a FIR filter at
http://www.optunis.com/screenshots.html (scroll to the bottom where it
says FIR Coefficient Finder Demostration Movies and click the link)

(The animation shows a low pass filter (frequency and time response) at
first, but it is followed by a band pass filter (frequency and time
response) which shows that you may get negative values).

Tony



Rune Allnor wrote:
> Jerry Avins wrote: > > Rune Allnor wrote: > > > > > Simon wrote: > > > > > >>I am try to implement a FIR bandpass filter in C2000 DSP. > > >> > > >>I got the coefficients from FDATOOL > > > > > > ... > > > > > >>then I just confused, anyway, The FDATOOL must be right. > > >> > > >>Then what's wrong with my implementation. > > > > > > > > > These are two questions. > > > > > > First, you need to understand how the filter works. You need to use > > > a simulated signal (or some measurement you have stored) as a test > > > to see how the filter you have designed actually works. You use > > > matlab for this. > > > > > > Once you are confident the filter works as you want it to, you > > > transfer it to the DSP, taking into account the various technical > > > aspects concerning number formats etc. Again, use a test setup > > > and see if the filter performs as expected. Use matlab to simulate > > > the various steps (fixed-point arithmetics, offsets) if you do not > > > quite understand what is going on. > > > > > > FDATOOL is only a tool. It does nothing by itself, it does what *you* > > > tell it to do. If there are mistakes or errors, it is because *you* > > > made > > > them. If the filter works, it is because *you* desigend it to. > > > > > > Would you blame the hammer if you didn't manage to hit a > > > nail straight? > > > > There's no need to beat up on poor Simon. he writes "FDATOOL must be > > right" and asks what *he* is doing wrong. > > I apologize if I beat Simon up too badly. Still, knowing how the tools > work -- and don't work -- is part of the game. > > > Matlab isn't the only way to design filters. Maybe we can help him > > troubleshoot his FIR. > > I hope so. > > Rune
Thanks Tony and everybody,
     Tony got the point. Actually, everthing is right, including the
result. Since DC will tend to be zero espcially when the input
frequency is far away outside the pass band range . Anyway it is a
bandpass filter.

      These days, I can hardly get on google. It said even google will
quit from my country because of some sensitive political issues on our
country. I hope it was just a joke.
Without google, I just doubt where to go on with my everday life.

       Thanks , group, and you  all, kind guys!

Simon