FIR Filter Help

Started by February 13, 2005
Hi, I would like to apply a FIR filter to my frequency sample array.
Specifically, I want to use a band-pass filter against my data, but I'm
pretty new to DSP and I'm not sure exactly how to integrate this.

First, I have a complex array of frequency data (real, imaginary).

Second, I've used a FIR design program to come up with the following
information:

-Rectangular window FIR filter
-Filter type: BP
-Passband: 300 - 3000 Hz
-Order: 20
-Transition band: 368 Hz
-Stopband attenuation: 21 dB

-Coefficients:
a[0] =	-0.026050229
a[1] =	-0.038693827
a[2] =	0.008864745
a[3] =	-0.06381684
a[4] =	0.006034263
a[5] =	-0.028610367
a[6] =	-0.06422336
a[7] =	0.06343614
a[8] =	-0.16215464
a[9] =	0.14424528
a[10] =	0.68565154
a[11] =	0.14424528
a[12] =	-0.16215464
a[13] =	0.06343614
a[14] =	-0.06422336
a[15] =	-0.028610367
a[16] =	0.006034263
a[17] =	-0.06381684
a[18] =	0.008864745
a[19] =	-0.038693827
a[20] =	-0.026050229

Now, could someone please describe to me how I can use the above info.
and apply it to my freq. data? Thank you!

Hi, I'm, assuming you know how to do a convolution - if not then you'll 
have to look it up.

Now to filter your complex series you really do the same thing, except 
that the multiplies and adds are now complex - you can think of you 
filter as having a complex componentm but it is just set to zero.

Since you filter has just a real component, it gets even easier. In this 
case you take the real part of the input data and apply your filter and 
it becomes the real part of your output data. You take the imaginary 
part of your input and apply the filter again (as if it were the real 
part - drop the i notation) and you end up with the imaginary part of 
your output. So you can just apply your filter twice to the real and 
imaginary parts of the input data to produce the corresponding part of 
your output data.

Note: This is only possible because your filter has just a real 
component. If it had a complex component you'd have to do the full 
complex adds and multiplies.

Hope that helps.

Cheers,
David

yeti349@yahoo.com wrote:
> Hi, I would like to apply a FIR filter to my frequency sample array. > Specifically, I want to use a band-pass filter against my data, but I'm > pretty new to DSP and I'm not sure exactly how to integrate this. > > First, I have a complex array of frequency data (real, imaginary). > > Second, I've used a FIR design program to come up with the following > information: > > -Rectangular window FIR filter > -Filter type: BP > -Passband: 300 - 3000 Hz > -Order: 20 > -Transition band: 368 Hz > -Stopband attenuation: 21 dB > > -Coefficients: > a[0] = -0.026050229 > a[1] = -0.038693827 > a[2] = 0.008864745 > a[3] = -0.06381684 > a[4] = 0.006034263 > a[5] = -0.028610367 > a[6] = -0.06422336 > a[7] = 0.06343614 > a[8] = -0.16215464 > a[9] = 0.14424528 > a[10] = 0.68565154 > a[11] = 0.14424528 > a[12] = -0.16215464 > a[13] = 0.06343614 > a[14] = -0.06422336 > a[15] = -0.028610367 > a[16] = 0.006034263 > a[17] = -0.06381684 > a[18] = 0.008864745 > a[19] = -0.038693827 > a[20] = -0.026050229 > > Now, could someone please describe to me how I can use the above info. > and apply it to my freq. data? Thank you! >
If you have frequency domain samples, you don't need the coefficients
of the FIR. You have specified:

"
-Rectangular window FIR filter
-Filter type: BP
-Passband: 300 - 3000 Hz
-Order: 20
-Transition band: 368 Hz
-Stopband attenuation: 21 dB
"

So all you do is attenuate the frequency samples that lie between 300
and 3000 Hz by 21 dB, et voila! Perhaps you might want to convert back
your frequency data into time domain data. I don't know.

The coefficients from the filter design program are only needed if you
want a time domain implementation of the FIR (that is, if your samples
are in time domain - but they are not, as you describe in your post).

Regards,
Andor

> If you have frequency domain samples, you don't need the coefficients > of the FIR. You have specified:
Yes, I can get all my time-domain samples to frequency samples using my FFT.
> So all you do is attenuate the frequency samples that lie between 300 > and 3000 Hz by 21 dB, et voila! Perhaps you might want to convert
back
> your frequency data into time domain data. I don't know.
This is the essence of my question. I'm not exactly sure how to attenuate... And yes I will be converting back to time-domain with my inverse FFT.
> The coefficients from the filter design program are only needed if
you
> want a time domain implementation of the FIR (that is, if your
samples
> are in time domain - but they are not, as you describe in your post).
This is correct, thank you.
Can I just apply a FIR filter in the time domain without even doing a
FFT? Is it faster in the time domain?

yeti349@yahoo.com wrote:

> Can I just apply a FIR filter in the time domain without even doing a > FFT?
Yes < Is it faster in the time domain? Sometimes. It's certainly simpler. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
> Sometimes. It's certainly simpler.
Hmm, too bad I had to get my FFT and iFFT working before I realized that. :)
is there a formula for filtering white noise from a time-domain signal?

yeti349@yahoo.com wrote:

> is there a formula for filtering white noise from a time-domain signal?
White noise has a flat spectrum which is to sat, the noise power is uniform across the passband. If the signal is concentrated in one or more parts of the band, allowing only those parts to pass improves the signal-to-noise ratio. When signal and noise occupy the same spectrum, there's little to be done. Consider a soprano's aria a signal, and a mewling child, noise. Imagine trying to suppress one of the voices on a recording. Only the script writers on CSI know how. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
> Only the script writers on CSI know how.
haha! yes I agree...good show though. Jerry, you seem to be a very helpful person in this forum. Could you please explain to me (like you are describing something to a retarded child) the simplest way I can apply a low-pass FIR in the time-domain? I have read and read, but this seemingly simple task is eluding me. If I understand correctly, I can apply a 3 tap filter on my samples like so: output[t]=a0*input[t+1]+a1*input[t]+a2*input[t-1]; Are a0-a2 the coefficiants that represent the frequencies I want to filter? When I apply this formula to my audio, the ouput has a lot of static and is amplified. There doesn't seem to be any filtering however. Are there other components, like dB or Gain that need to be applied to this formula, or is that just for FFT filters? It's very important to me that I can filter (low-pass/high-pass) in the time-domain, but like I've said, I haven't made much progress with good results. Thanks again!
ok good, so it's just a logic bug with my loop. Thanks Jim.

Jon Harris wrote:
> Looks good to me! I still would use a loop for the convolution step so it is > easier to change number of taps, but that's just a programming preference.
It's more than just a preference, it's good practice. But I think I see a problem with your implementation.
>>for (int t=20; t < audioShortData.length; t++) { >>audioShortData[t] = (short)(( >>a0*audioShortData[t]+ >>a1*audioShortData[t-1]+
...
>>a20*audioShortData[t-20]
You are overwriting your input data with your filter result. That means that the each pass through the filter loop gets a different set of data, and that is incorrect. You need to store your results somewhere else. Do have a look at the FIR code on dspguru. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536 Quidquid latine dictum sit, altum sonatur. Whatever is said in Latin sounds profound.
samseed wrote:

   ...

> Jon and Jerry, thanks again for sharing your vast knowledge of DSP with > me and all the other newbies.
My pleasure! Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
"samseed"  wrote in message
news:1108601220.386364.169590@c13g2000cwb.googlegroups.com...
> > OK, I understand you. The convolution formula is always the same > regardless of > > what filter type you are using--low-pass, high-pass, band-pass, > something > > totally arbitrary, etc.. So your filtering function can always be > the same, but > > depending on what filter coefficients you use, it may create a LP, > HP, etc.. > > excellent, that really clears up a lot of uncertainties for me. Of all > the documentation I've read nobody's just come out and said that.
That's because it's so obvious for those of us who have been doing DSP for years! :-)
> Jon and Jerry, thanks again for sharing your vast knowledge of DSP with > me and all the other newbies.
You're welcome.
> OK, I understand you. The convolution formula is always the same
regardless of
> what filter type you are using--low-pass, high-pass, band-pass,
something
> totally arbitrary, etc.. So your filtering function can always be
the same, but
> depending on what filter coefficients you use, it may create a LP,
HP, etc.. excellent, that really clears up a lot of uncertainties for me. Of all the documentation I've read nobody's just come out and said that. Jon and Jerry, thanks again for sharing your vast knowledge of DSP with me and all the other newbies.
"samseed"  wrote in message
news:1108595391.559407.170670@z14g2000cwz.googlegroups.com...
> my bad. > > >I'm guessing your audio sample rate is something around 8kHz > > correct. However, 44kHz is the only rate that has valid filter output, > but that may just be a bug in my app.
Probably.
> >Again, use your filter design program---there is no easy formula! I > think there > are some ways to transform a LP into a HP, but I would still use the > program. > > yes, I'm using the design program. What I meant to ask was, is the > high-pass a multiply/add like a low-pass, or do you multiply/ subtract > like so: > > audioShortData[t] = (short)(( a0*audioShortData[t] - > a1*audioShortData[t-1] - a2*audioShortData[t-2] - ...)
OK, I understand you. The convolution formula is always the same regardless of what filter type you are using--low-pass, high-pass, band-pass, something totally arbitrary, etc.. So your filtering function can always be the same, but depending on what filter coefficients you use, it may create a LP, HP, etc..
samseed wrote:
> my bad. > > >>I'm guessing your audio sample rate is something around 8kHz > > > correct. However, 44kHz is the only rate that has valid filter output, > but that may just be a bug in my app. > > >>Again, use your filter design program---there is no easy formula! I > > think there > are some ways to transform a LP into a HP, but I would still use the > program. > > yes, I'm using the design program. What I meant to ask was, is the > high-pass a multiply/add like a low-pass, or do you multiply/ subtract > like so: > > audioShortData[t] = (short)(( a0*audioShortData[t] - > a1*audioShortData[t-1] - a2*audioShortData[t-2] - ...)
Multiply and add is the usual. but id you always subtract, that just inverts the output signal. The operation is called MAC, for "Multiply And Accumulate". Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
my bad.

>I'm guessing your audio sample rate is something around 8kHz
correct. However, 44kHz is the only rate that has valid filter output, but that may just be a bug in my app.
>Again, use your filter design program---there is no easy formula! I
think there are some ways to transform a LP into a HP, but I would still use the program. yes, I'm using the design program. What I meant to ask was, is the high-pass a multiply/add like a low-pass, or do you multiply/ subtract like so: audioShortData[t] = (short)(( a0*audioShortData[t] - a1*audioShortData[t-1] - a2*audioShortData[t-2] - ...)
"samseed"  wrote in message
news:1108581210.574553.72530@z14g2000cwz.googlegroups.com...
> yes.
Just a tip, include some of the message you are replying too so we can see the context--what are you saying "yes" to?
> what is the correct formula for a high-pass?
Again, use your filter design program---there is no easy formula! I think there are some ways to transform a LP into a HP, but I would still use the program.
yes.

what is the correct formula for a high-pass?