Forums

IIR filter design

Started by March 14, 2004
Hi all !

Thank you for reading this post. I have a small problem. I would like to
design an IIR filter for a FPGA and simulate it with octave/matlab to see if
it works as it should. So I don't use the included 'filter' function, but I
designed it myself. As one can see it in the code provided here, the design
works for 2nd order filters, but not for orders 3 and more. Who could help
me ??

I would like to design a butterworth 4th order  bandpass filter whose corner
frequencies are 20 and 200 Hz. Sampling freq is 96 kHz.

Thanks a lot in advance !

Sam

Matlab/Octave code :

%----
function bp200

t=0:1/96000:10000/96000;
insig=sin(2*pi*100*t);

va(1:3)=0;

for i=1:length(insig)
%%% butter bp 2nd order (ok) :
%     va(i+2)=insig(i)+1.9941*va(i+1)-0.9941*va(i);
%     outsig(i)=va(i+2)*0.0029+va(i+1)*0-va(i)*0.0029;
%%% butter bp 4th order (not ok):
%
va(i+4)=insig(i)+3.9917*va(i+3)-5.9750*va(i+2)+3.9751*va(i+1)-0.9917*va(i);
%     outsig(i)=va(i+4)*0.0864e-4-va(i+2)*0.1728e-4+va(i)*0.0864e-4;
%%% butter lp 3rd order (not ok) :
    va(i+3)=insig(i)+2.9869*va(i+2)-2.9739*va(i+1)-0.9870*va(i);

outsig(i)=va(i+3)*(0.0348e-6)+va(i+2)*(0.1045e-6)+va(i+1)*(0.1045e-6)+va(i)*
(0.0348e-6);
end

plot(outsig);


Sam (r�p. sans -no-sp-am) wrote:

> Hi all ! > > Thank you for reading this post. I have a small problem. I would like to > design an IIR filter for a FPGA and simulate it with octave/matlab to see if > it works as it should. So I don't use the included 'filter' function, but I > designed it myself. As one can see it in the code provided here, the design > works for 2nd order filters, but not for orders 3 and more. Who could help > me ?? > > I would like to design a butterworth 4th order bandpass filter whose corner > frequencies are 20 and 200 Hz. Sampling freq is 96 kHz. > > Thanks a lot in advance ! > > Sam > > Matlab/Octave code [snipped]:
Numerical considerations dictate that practical filters be designed as cascades of second order. The order of the sections can have strong influence on the stability of the cascade. In general, proper distribution of poles and zeros will section gains from growing to high and keep enough significant bits in use for the output to be meaningful. Often, double precision is needed. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Sam (r�p. sans -no-sp-am) wrote:

 > Hi all !
 >
 > Thank you for reading this post. I have a small problem. I would like to
 > design an IIR filter for a FPGA and simulate it with octave/matlab to 
see if
 > it works as it should. So I don't use the included 'filter' function, 
but I
 > designed it myself. As one can see it in the code provided here, the 
design
 > works for 2nd order filters, but not for orders 3 and more. Who could 
help
 > me ??
 >
 > I would like to design a butterworth 4th order  bandpass filter whose 
corner
 > frequencies are 20 and 200 Hz. Sampling freq is 96 kHz.
 >
 > Thanks a lot in advance !
 >
 > Sam
 >
 > Matlab/Octave code [snipped]:


Numerical considerations dictate that practical filters be designed as
cascades of second order. The order of the sections can have strong
influence on the stability of the cascade. In general, proper
distribution of poles and zeros will prevent gains from growing to high
and keep enough significant bits in use for the output to be meaningful.
Often, double precision is needed.

Jerry
-- 
Engineering is the art of making what you want from things you can get.
�����������������������������������������������������������������������

Sam (r�p. sans -no-sp-am) wrote:

 > Hi all !
 >
 > Thank you for reading this post. I have a small problem. I would like to
 > design an IIR filter for a FPGA and simulate it with octave/matlab to 
see if
 > it works as it should. So I don't use the included 'filter' function, 
but I
 > designed it myself. As one can see it in the code provided here, the 
design
 > works for 2nd order filters, but not for orders 3 and more. Who could 
help
 > me ??
 >
 > I would like to design a butterworth 4th order  bandpass filter whose 
corner
 > frequencies are 20 and 200 Hz. Sampling freq is 96 kHz.
 >
 > Thanks a lot in advance !
 >
 > Sam
 >
 > Matlab/Octave code [snipped]:


Numerical considerations dictate that practical filters be designed as
cascades of second order. The order of the sections can have strong
influence on the stability of the cascade. In general, proper
distribution of poles and zeros will prevent gains from growing too high
and keep enough significant bits in use for the output to be meaningful.
Often, double precision is needed.

Jerry
-- 
Engineering is the art of making what you want from things you can get.
�����������������������������������������������������������������������

If you have the signal processing toolbox, do help on zp2sos.  That will
take any desired transfer function an spit out the coefs of cascaded 2nd
order sections

-Shawn


"Sam (r&#2013265929;p. sans -no-sp-am)" <totalsam-no-sp-am@hotmail.com> wrote in
message
news:405494f4$0$705$5402220f@news.sunrise.ch...
> Hi all ! > > Thank you for reading this post. I have a small problem. I would like to > design an IIR filter for a FPGA and simulate it with octave/matlab to see
if
> it works as it should. So I don't use the included 'filter' function, but
I
> designed it myself. As one can see it in the code provided here, the
design
> works for 2nd order filters, but not for orders 3 and more. Who could help > me ?? > > I would like to design a butterworth 4th order bandpass filter whose
corner
> frequencies are 20 and 200 Hz. Sampling freq is 96 kHz. > > Thanks a lot in advance ! > > Sam > > Matlab/Octave code : > > %---- > function bp200 > > t=0:1/96000:10000/96000; > insig=sin(2*pi*100*t); > > va(1:3)=0; > > for i=1:length(insig) > %%% butter bp 2nd order (ok) : > % va(i+2)=insig(i)+1.9941*va(i+1)-0.9941*va(i); > % outsig(i)=va(i+2)*0.0029+va(i+1)*0-va(i)*0.0029; > %%% butter bp 4th order (not ok): > % >
va(i+4)=insig(i)+3.9917*va(i+3)-5.9750*va(i+2)+3.9751*va(i+1)-0.9917*va(i);
> % outsig(i)=va(i+4)*0.0864e-4-va(i+2)*0.1728e-4+va(i)*0.0864e-4; > %%% butter lp 3rd order (not ok) : > va(i+3)=insig(i)+2.9869*va(i+2)-2.9739*va(i+1)-0.9870*va(i); > >
outsig(i)=va(i+3)*(0.0348e-6)+va(i+2)*(0.1045e-6)+va(i+1)*(0.1045e-6)+va(i)*
> (0.0348e-6); > end > > plot(outsig); > >