DSPRelated.com
Forums

Odd symmetric FIR filter

Started by Umutesi Faith September 23, 2005
"Umutesi Faith" <ma_nz1@yahoo.com> wrote in message 
news:XJGdnSYHAtBNXaPeRVn-qA@giganews.com...
> > Well, this is the most common form of array initialization in C language. > This array has 8 elements running from s0 to s7! > My intention was just to make sure if i understood well "the pseudo code" > so that i can continue with fixed ideas in my studying about the FIR > filter implementation!
OK - I hope this helped then... Fred
I don't mean to be annoying , but here i am again with the same question!
/*Input samples*/
int Input[7] = {s0, s1, s2, s3, s4, s5, s6 ,s7};// array initialization in
C language
   
Input[0] = newestsample

Knowing that the newestsample is a certain variable which is assigned to
the Input[0] each time a next input sample is received,my concern is how 
then to assign these inputs samples to the variable newestsample each
time!!(example,the first round would take newestsample = s0!!, and the
next round after the shifting of s0 it would take s1 at Input[0] and so
on....)
thanks!

>"Umutesi Faith" <ma_nz1@yahoo.com> wrote in message >news:XJGdnSYHAtBNXaPeRVn-qA@giganews.com... >> >> Well, this is the most common form of array initialization in C
language.
>> This array has 8 elements running from s0 to s7! >> My intention was just to make sure if i understood well "the pseudo
code"
>> so that i can continue with fixed ideas in my studying about the FIR >> filter implementation! > >OK - I hope this helped then... > >Fred > > >
This message was sent using the Comp.DSP web interface on www.DSPRelated.com
Umutesi Faith wrote:
> I don't mean to be annoying , but here i am again with the same question! > /*Input samples*/ > int Input[7] = {s0, s1, s2, s3, s4, s5, s6 ,s7};// array initialization in > C language > > Input[0] = newestsample > > Knowing that the newestsample is a certain variable which is assigned to > the Input[0] each time a next input sample is received,my concern is how > then to assign these inputs samples to the variable newestsample each > time!!(example,the first round would take newestsample = s0!!, and the > next round after the shifting of s0 it would take s1 at Input[0] and so > on....) > thanks!
Once you understand the what you need to do, the code will seem simple. The naive approach shifts all the data in the buffer each time a new sample is inserted: s7=s6; s6=s5; s5=s4; s4=s3; s3=s2; s2=s1; s1=s0; s0=newsample Now, multiply each sn by the coefficient assigned to it and add the result to an initially zero accumulator. (This step is called a MAC; Multiply and ACcumulate. some processors support it as a single instruction.) The accumulator is the filter output when all the sn have been processed. Then do it again for the next output. One is tempted to code the buffer shift as a loop. Don't bother. Instead, get rid of the shift by using a circular buffer. (Q.V.) Some processors support circular buffering in hardware. circular buffers are not unique to DSP. That are also very useful, for example, for UART operation, especially when the UART service routine is interrupt driven. 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;
"Umutesi Faith" <ma_nz1@yahoo.com> wrote in message 
news:9aednWhxVvIrdKLeRVn-vw@giganews.com...
>I don't mean to be annoying , but here i am again with the same question! > /*Input samples*/ > int Input[7] = {s0, s1, s2, s3, s4, s5, s6 ,s7};// array initialization in > C language > > Input[0] = newestsample > > Knowing that the newestsample is a certain variable which is assigned to > the Input[0] each time a next input sample is received,my concern is how > then to assign these inputs samples to the variable newestsample each > time!!(example,the first round would take newestsample = s0!!, and the > next round after the shifting of s0 it would take s1 at Input[0] and so > on....) > thanks!
I'll give you the same answer that Jerry did but will try to stick to your notation. I am not the best programmer so the goodness of the code should be questioned: you said: /*Input samples*/
> int Input[7] = {s0, s1, s2, s3, s4, s5, s6 ,s7};// array initialization in > C language
I'm going to modify the variable name here for clarity: k=0 /*Buffer samples*/ int Buffer[8]=[s0,s1, s2, s3, s4, s5, s6 ,s7};// array initialization in
> C language
/*Define filter*/ int filter[8]=[f0, f1, f2, f3, f4, f5, f6, f7];// filter initialization /*compute filter output*/ y(k)=s0*f7 + s1*f6 + s2*f5 + s3*f4 + s4*f3 + s5*f2 + s6*f1 +s7*f0 k=k+1 "get newsample" ; however you do this.... s7=s6 s6=s5 s5=s4 s4=s3 s3=s2 s2=s1 s1=s0 s0=newsample; // note the order of replacement. the sample that was in s7 goes away. /*compute filter output*/ y(k)=s0*f7 + s1*f6 + s2*f5 + s3*f4 + s4*f3 + s5*f2 + s6*f1 +s7*f0 ...build this into a loop. But, this is a pretty brute force approach so instead of doing all those replacements, we'll not move the data but index the buffer circularly instead: k=0 /*Buffer samples*/ int Buffer[8]=[s0,s1, s2, s3, s4, s5, s6 ,s7};// array initialization in
> C language
/*Define filter*/ int filter[8]=[f0, f1, f2, f3, f4, f5, f6, f7];// filter initialization /*compute filter output*/ y(k)=s0*f(7) + s1*f(6) + s2*f(5) + s3*f(4) + s4*f(3) + s5*f(2) + s6*f(1) +s7*f(0) "get newsample" ; however you do this.... s(7+k)=newsample; //replaces the sample that will go away with the newest sample// k=k+1 /*compute filter output*/ y(k)=s(0+k)*f(7) + s(1+k)*f(6) + s(2+k)*f(5) + s(3+k)*f(4) + s(4+k)*f(3) + s(5+k)*f(2) + s(6+k)*f(1) +s(7+k)*f(0); // x+k has to be done modulo 8 and I've not shown that ... there are surely "good" programs on dspguru.com // //repeat// "get newsample" ; however you do this.... s(7+k)=newsample; //replaces the sample that will go away with the newest sample so now s(7) is the "zeroeth" sample, s(0) is the 1st sample, s(1) is the 2nd sample ... and s(6) is the 7th sample // k=k+1 /*compute filter output*/ y(k)=s(0+k)*f(7) + s(1+k)*f(6) + s(2+k)*f(5) + s(3+k)*f(4) + s(4+k)*f(3) + s(5+k)*f(2) + s(6+k)*f(1) +s(7+k)*f(0); //so the "beginning" of the data moves through the array as the oldest sample is replaced with the newest sample.// I hope this is clear enough now. Fred