DSPRelated.com
Forums

A stupid question about FIR filter

Started by phuture_project July 22, 2004
Hi guys,

Excuse me for this stupid question but i want to understand.

I send a sine at 9 kHz in the ADC input. I sample it. Then i apply a
FIR filter which features are  a bandpass of 8000-10000 Hz with a
unity gain (and 401 coefficients). Logically, if i've understood well
(thing that i'm doubting now)  by recovering the y(n) of the FIR
output, i should recover the input sine, shouldn't I? That's what i
thought but with the results i get it doesn't corespond at all! Am i
so stupid?

Thanks.
phuture_project wrote:

> Hi guys, > > Excuse me for this stupid question but i want to understand. > > I send a sine at 9 kHz in the ADC input. I sample it. Then i apply a > FIR filter which features are a bandpass of 8000-10000 Hz with a > unity gain (and 401 coefficients). Logically, if i've understood well > (thing that i'm doubting now) by recovering the y(n) of the FIR > output, i should recover the input sine, shouldn't I? That's what i > thought but with the results i get it doesn't corespond at all! Am i > so stupid? > > Thanks.
If the filter is designed correctly y(n) should be a delayed version of the sine wave -- are you looking at y(n) over all n, or are you just looking every once in a while and catching the valleys? -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
phuture_project wrote:

> Hi guys, > > Excuse me for this stupid question but i want to understand. > > I send a sine at 9 kHz in the ADC input. I sample it. Then i apply a > FIR filter which features are a bandpass of 8000-10000 Hz with a > unity gain (and 401 coefficients). Logically, if i've understood well > (thing that i'm doubting now) by recovering the y(n) of the FIR > output, i should recover the input sine, shouldn't I? That's what i > thought but with the results i get it doesn't corespond at all! Am i > so stupid? > > Thanks.
The theory is right. It appears that your implementation falls short. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
"phuture_project" <phuture_project@yahoo.fr> wrote in message
news:25fe518f.0407220516.5c20f429@posting.google.com...
> Hi guys, > > Excuse me for this stupid question but i want to understand. > > I send a sine at 9 kHz in the ADC input. I sample it. Then i apply a > FIR filter which features are a bandpass of 8000-10000 Hz with a > unity gain (and 401 coefficients). Logically, if i've understood well > (thing that i'm doubting now) by recovering the y(n) of the FIR > output, i should recover the input sine, shouldn't I? That's what i > thought but with the results i get it doesn't corespond at all! Am i > so stupid? > > Thanks.
Other than your FIR implementation, it appears that your fs (sample frequency) might also play a part here. What sample frequency are you using? Also, you can check to see if your 9kHz sine can be seen in the raw data samples (before the FIR). Serves as a sanity check. Cheers Bhaskar
"Bhaskar Thiagarajan" <bhaskart@my-deja.com> wrote in message
news:2ma8eoFktmsmU1@uni-berlin.de...
> > Other than your FIR implementation, it appears that your fs (sample > frequency) might also play a part here. What sample frequency are you
using?
> Also, you can check to see if your 9kHz sine can be seen in the raw data > samples (before the FIR). Serves as a sanity check.
Bhaskar has given good advice here. Note that the sample rate of the ADC must be *greater than* something like 2x9kHz/0.8 = 22.5kHz. Is it? Also note that the sample rate of the FIR filter (as designed) must be the same as the ADC sample rate. This is the same as saying that the sample interval of the ADC is the same as the assumed time delays in the FIR filter. Is that how you designed the FIR filter? Or, if you like to normalize to the sample rate: If the sample rate is normalized to 1.0 then you need to know what fraction 9kHz is of that sample rate. It better be less than 0.4 or 80% of the theoretical "less than 0.5". If the sample rate is 27kHz, then 9kHz is 0.333fs (which meets this <0.4fs criterion) and the pass band would be from 0.296fs to 0.370fs. And, I note that 0.370 is less than 0.4 which is good. (You need some room for a transition band to get from the high end of the passband to the high end desired stopband value of zero). Fred
phuture_project@yahoo.fr (phuture_project) wrote in message news:<25fe518f.0407220516.5c20f429@posting.google.com>...
> Hi guys, > > Excuse me for this stupid question but i want to understand. > > I send a sine at 9 kHz in the ADC input. I sample it. Then i apply a > FIR filter which features are a bandpass of 8000-10000 Hz with a > unity gain (and 401 coefficients). Logically, if i've understood well > (thing that i'm doubting now) by recovering the y(n) of the FIR > output, i should recover the input sine, shouldn't I? That's what i > thought but with the results i get it doesn't corespond at all! Am i > so stupid?
There are the questions about sampling the signal correctly. With the specifigation of your signal and filter, you have to sample at at least 20 kHz, probably a bit more. There are also the questions about signal scaling when displaying your output data, and round-off errors if you use integer arithmetics in the DSP. Rune
Rune Allnor wrote:

> phuture_project@yahoo.fr (phuture_project) wrote in message news:<25fe518f.0407220516.5c20f429@posting.google.com>...
(snip)
>>I send a sine at 9 kHz in the ADC input. I sample it. Then i apply a >>FIR filter which features are a bandpass of 8000-10000 Hz with a >>unity gain (and 401 coefficients). Logically, if i've understood well >>(thing that i'm doubting now) by recovering the y(n) of the FIR >>output, i should recover the input sine, shouldn't I? That's what i >>thought but with the results i get it doesn't corespond at all! Am i >>so stupid?
> There are the questions about sampling the signal correctly. With the > specifigation of your signal and filter, you have to sample at at least > 20 kHz, probably a bit more. There are also the questions about signal > scaling when displaying your output data, and round-off errors if > you use integer arithmetics in the DSP.
The 9kHz sine seems to have a bandwidth near 0Hz, so it should be possible to recover the signal with almost any sampling rate. Designing an FIR filter for a system where the sampling band does not include DC is somewhat more complicated. If the system bandwidth is less than 2kHz it will be difficult to design a filter with 2kHz bandwidth. So, given the above it is probably reasonable that the system should be baseband sampled with a sample rate of 22kHz or so, but it isn't required. -- glen
Hi everyone,

First of all i want to thank you all. I do apreciate. And secondly i'm
happy not to be so stupid!

So I'm going to answer to all your questions.

>Tim:
>If the filter is designed correctly y(n) should be a delayed version
of
>the sine wave -- are you looking at y(n) over all n, or are you just >looking every once in a while and catching the valleys?
So i've understood well (is it a correct sentence to say "understand well" ? (i'm french)) what is fir filter and what i should expect as output signal. To answer to your question, i recover all the y(n) in a table and when the program ends, i look at these stored values. What does "catching the valleys" mean?
>Jerry:
>The theory is right. It appears that your implementation falls short.
I'm happy to know the theory is right! I'm sorry but what does "falls short" mean?
>Bhaskar:
>Other than your FIR implementation, it appears that your fs (sample >frequency) might also play a part here. What sample frequency are you
using?
>Also, you can check to see if your 9kHz sine can be seen in the raw
data
>samples (before the FIR). Serves as a sanity check.
My sample frequency is 100 kHz, so Shannon (or Nyquist?) criteria is respected. I checked the samples i get and i can tell you that everything is ok, before the fir filter.
>Fred:
>Bhaskar has given good advice here.
>Note that the sample rate of the ADC must be *greater than* something
like
>2x9kHz/0.8 = 22.5kHz. Is it?
>Also note that the sample rate of the FIR filter (as designed) must
be the
>same as the ADC sample rate. This is the same as saying that the
sample
>interval of the ADC is the same as the assumed time delays in the FIR >filter. Is that how you designed the FIR filter?
Yes, of course. I did that way.
>Or, if you like to normalize to the sample rate: >If the sample rate is normalized to 1.0 then you need to know what
fraction
>9kHz is of that sample rate. It better be less than 0.4 or 80% of
the
>theoretical "less than 0.5". >If the sample rate is 27kHz, then 9kHz is 0.333fs (which meets this
<0.4fs
>criterion) and the pass band would be from 0.296fs to 0.370fs. >And, I note that 0.370 is less than 0.4 which is good. >(You need some room for a transition band to get from the high end of
the
>passband to the high end desired stopband value of zero).
In fact i designed my fir filter with the Scilab software, using the wfir function for those who are familiar with it. So i designed it using normalized cut-off frequencies. Of course, before employing the coefficients and implementing the fir filter on my DSP, i checked that the frequency response was correct, regarding the bandpass and gain i wanted.
>Rune
>There are the questions about sampling the signal correctly. With the >specifigation of your signal and filter, you have to sample at at
least
>20 kHz, probably a bit more.
As i said it before, the sample frequency is 100 kHz. I respect Nyquist (or Shannon ?) criteria.
>There are also the questions about signal scaling when displaying
your output >data, and round-off errors if you use integer arithmetics in the DSP. Yes, i think you're right. In fact i think the issue comes from scaling. I'll try to be as clear as possible. First, it's good to know that the DSP i use is a fixed-point one. When i sample, the sample values i get are in "unsigned int" format. This is due to my serial port. It's not an issue i think, since the results correspond to the reality. The function i use to realize the fir filter is a function provided by TI in its "dsplib" directory. The trick is that the samples must be in the Q15 format. So before launching the fir filter, i need to convert my unsigned int samples into Q15 ones. And as i've not a function that directly changes unsigned int numbers into Q15 ones, i must change the unsigned int numbers into float ones and then use a dedicated function that allows to convert float numbers into Q15 ones. It's a little complicated i can confess! The coefficients must be in the Q15 format too. Once again i make a conversion since the coefficients i get from Scilab are float numbers. That's not an issue i think. The only thing is that i lose precision. As y(n) are in the Q15 format too, i make the conversions in the opposite order. Maybe all these conversions play a part in the false output i get. Nevertheless i checked that my unsigned int samples are well converted in float then in Q15. I didn't check for y(n), but there's no reason for it not to work. Maybe i must add that when i convert the unsigned int samples into float ones, in fact i make the following thing : s[n]=x[n]*2.5/2560 My ADC is an 8 bit ones and the analog input must be between 0 and 2.5V. So the sample value i get correspond in reality to a volatge of: sample*2.5/256. But if i only do that i'll have float numbers that can be >1. And as in Q15 format the greatest value i can use is 1, i thought it was a good idea to divide by 10. Maybe i'm totally wrong. What do you think about that? I think that's all i can tell. I hope that was clear enough. If you miss other infos please tell me. Thanks once again. Bye
Another question :

i guess that the number of samples to be recorded depends on how many
coefficients there are. what is the minimum number of samples to be
recorded regarding the number of coefficients? I'd say : minimum
number of samples = number of coefficients, but i'm not sure.

Thanks.

phuture_project wrote:
> > I'm happy to know the theory is right! I'm sorry but what does "falls > short" mean?
Find a body of water that is wider than you are capable of jumping. Attempt to jump across it. Repeat as often as need to fully understand the concept of "falling short". -jim -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =-----