DSPRelated.com
Forums

Started by Grant Jennings June 5, 2007
Hello,

I'm trying to implement a cascading iir and here's my code for the first
second order z transform. I'm I going about this correctly? My output is
good till a particular value and then it starts having problems. Any help
or links to a good example would be great!

Thanks,
Grant

float b[3] = {1,2,1};
float a[3] = {1,-1.9985996261556458,0.99952100328066507};
float y[151]={0};
int i=0;
char wait;

while(i<151)
{
x[i] *= 7.0818881108085789e-7;
if(i==0)
y[i] = x[i];
if(i==1)
y[i] = x[i] + b[1]*x[i-1] - a[1]*y[i-1];
if (i>1)
y[i] = x[i] + b[1]*x[i-1] + b[2]*x[i-2] - a[1]*y[i-1] -
a[2]*y[i-2];
cout<
i++;
}
x = x * 7.0818881108085789e-7;

y = b[0]*x + d[0];
d[0] = b[1]*x - a[1]*y + d[1];
d[1] = b[2]*x - a[2]*y + d[2];

cout< i+=.001;
same results

--- In c..., "Grant Jennings" wrote:
>
> Hello,
>
> I'm trying to implement a cascading iir and here's my code for the first
> second order z transform. I'm I going about this correctly? My
output is
> good till a particular value and then it starts having problems.
Any help
> or links to a good example would be great!
>
> Thanks,
> Grant
>
> float b[3] = {1,2,1};
> float a[3] = {1,-1.9985996261556458,0.99952100328066507};
> float y[151]={0};
> int i=0;
> char wait;
>
> while(i<151)
> {
> x[i] *= 7.0818881108085789e-7;
> if(i==0)
> y[i] = x[i];
> if(i==1)
> y[i] = x[i] + b[1]*x[i-1] - a[1]*y[i-1];
> if (i>1)
> y[i] = x[i] + b[1]*x[i-1] + b[2]*x[i-2] - a[1]*y[i-1] -
> a[2]*y[i-2];
> cout< >
> i++;
> }
>