DSPRelated.com
Forums

FIR Filter Help

Started by Unknown February 13, 2005
>Design a single band-pass filter. Or rather, let a program design it
for you. lol, well said.
Jerry Avins wrote:
> > I like the Lyons book. You'll find it and others cited on > http://www.dspguru.com/.
THat site is chock-full-o good DSP stuff. In particular, it has a nice FAQ on FIRs, including working code. http://www.dspguru.com/info/faqs/firfaq.htm -- 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:
> Coefficients: > > a[0] = -0.047739632 > a[1] = -0.017229123 > a[2] = 1.0119492E-8 > a[3] = -0.064445764 > a[4] = -0.087204635 > a[5] = -0.011658093 > a[6] = -0.021648642 > a[7] = -0.15716003 > a[8] = -0.11321392 > a[9] = 0.221274 > a[10] = 0.43638006 > a[11] = 0.221274 > a[12] = -0.11321392 > a[13] = -0.15716003 > a[14] = -0.021648642 > a[15] = -0.011658093 > a[16] = -0.087204635 > a[17] = -0.064445764 > a[18] = 1.0119492E-8 > a[19] = -0.017229123 > a[20] = -0.047739632 > > > So, I have my time-domain samples patiently sitting in an array and I'm > currently fumbling with the proper formulas! :O >
You have 21 coefficients, but the code snippet you posted uses only three of them. You need to use them all. -- 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.
Is the following process correct?

//20 tap low-pass filter, Rectangular, coefficiants--->2000Hz, -10dB
double a0 =-0.028991204;
double a1 =0.008665845;
double a2 =0.033431053;
double a3 =-0.022146255;
double a4 =-0.037133045;
double a5 =0.043838896;
double a6 =0.039916355;
double a7 =-0.08839386;
double a8 =-0.041643664;
double a9 =0.28917018;
double a10 =0.50124127;
double a11 =0.28917018;
double a12 =-0.041643664;
double a13 =-0.08839386;
double a14 =0.039916355;
double a15 =0.043838896;
double a16 =-0.037133045;
double a17 =-0.022146255;
double a18 =0.033431053;
double a19 =0.008665845;
double a20 =-0.028991204;

for (int t=20; t < audioShortData.length; t++) {
audioShortData[t] = (short)((
a0*audioShortData[t]+
a1*audioShortData[t-1]+
a2*audioShortData[t-2]+
a3*audioShortData[t-3]+
a4*audioShortData[t-4]+
a5*audioShortData[t-5]+
a6*audioShortData[t-6]+
a7*audioShortData[t-7]+
a8*audioShortData[t-8]+
a9*audioShortData[t-9]+
a10*audioShortData[t-10]+
a11*audioShortData[t-11]+
a12*audioShortData[t-12]+
a13*audioShortData[t-13]+
a14*audioShortData[t-14]+
a15*audioShortData[t-15]+
a16*audioShortData[t-16]+
a17*audioShortData[t-17]+
a18*audioShortData[t-18]+
a19*audioShortData[t-19]+
a20*audioShortData[t-20]
}

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.
Based on your filter coefs and stated spec (2000Hz, -10dB), I'm guessing your
audio sample rate is something around 8kHz?

"samseed" <agent3492003@yahoo.com> wrote in message
news:1108564946.710984.197470@l41g2000cwc.googlegroups.com...
> Is the following process correct? > > //20 tap low-pass filter, Rectangular, coefficiants--->2000Hz, -10dB > double a0 =-0.028991204; > double a1 =0.008665845; > double a2 =0.033431053; > double a3 =-0.022146255; > double a4 =-0.037133045; > double a5 =0.043838896; > double a6 =0.039916355; > double a7 =-0.08839386; > double a8 =-0.041643664; > double a9 =0.28917018; > double a10 =0.50124127; > double a11 =0.28917018; > double a12 =-0.041643664; > double a13 =-0.08839386; > double a14 =0.039916355; > double a15 =0.043838896; > double a16 =-0.037133045; > double a17 =-0.022146255; > double a18 =0.033431053; > double a19 =0.008665845; > double a20 =-0.028991204; > > for (int t=20; t < audioShortData.length; t++) { > audioShortData[t] = (short)(( > a0*audioShortData[t]+ > a1*audioShortData[t-1]+ > a2*audioShortData[t-2]+ > a3*audioShortData[t-3]+ > a4*audioShortData[t-4]+ > a5*audioShortData[t-5]+ > a6*audioShortData[t-6]+ > a7*audioShortData[t-7]+ > a8*audioShortData[t-8]+ > a9*audioShortData[t-9]+ > a10*audioShortData[t-10]+ > a11*audioShortData[t-11]+ > a12*audioShortData[t-12]+ > a13*audioShortData[t-13]+ > a14*audioShortData[t-14]+ > a15*audioShortData[t-15]+ > a16*audioShortData[t-16]+ > a17*audioShortData[t-17]+ > a18*audioShortData[t-18]+ > a19*audioShortData[t-19]+ > a20*audioShortData[t-20] > } >
yes.

what is the correct formula for a high-pass?

"samseed" <agent3492003@yahoo.com> 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.
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:
> 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. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
"samseed" <agent3492003@yahoo.com> 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..