Hi, I have one question regarding implementation of IIR filter. I try to write C code of IIR filter for ARM microcontroler for real time signal processing. Filter should be lowpass and second order. I try to do this in interupt function. This should be part of the code . volatile int count, count_on; char On_ind; volatile float Sample[3],Filtered[3], Max, Min, Power_curent, Power_wanted, Scal, FB;;
/* Timer0 interupt funkcija*/ void tc0 (void) __irq { IODIR0 = 0x00000001;
Sample[2]=Sample[1]; Sample[1]=Sample[0]; Sample[0]=(float)ADC1_read();
Filtered[2]=Filtered[1]; Filtered[1]=Filtered[0];
Filtered[0]=0.0002478584065*Sample[0]+0.000495716813
*Sample[1]+0.0002478584065*Sample[2]+ 1.964326262*Filtered[1]-0.9654386044*Filtered[2]; // ffilteringBut there is a problem this code doesnt work. I try to implement IIR filter order 1
I replace
Filtered[0]=0.0002478584065*Sample[0]+0.000495716813
*Sample[1]+0.0002478584065*Sample[2]+ 1.964326262*Filtered[1]-0.9654386044*Filtered[2]; // ffilteringwith
Filtered[0]=
0.044263*Sample[0]+0.044263*Sample[1]+0.91147*Filtered[1];and this filter works fine. I am not shure but I don't know what is a problem when i am trying to implement second order IIR filter. Could anyone help me, please.
I designed this filters using Matlab "filters design and analys tool" (fdatool). I tested bouth filters in matlab and as test signal I used signal that is almost the same the one I am using with lpc2148. When I am testing filter order 1(with mc) the results is expected but when I use filter of second order I am getting wrong results (I am constantly getting '0').
I apreciated any kind of help.
Thanks Zoran