If you know about transform theory and complex analysis the
H(z)=(a0+a1*z^-1+a2*z^-2)/(1+b1*z^-1+b2*z^-2) will make sense for you, but if the Z-transform (
http://en.wikipedia.org/wiki/Z-transform) is like magic, you might look at the equation in the time domain instead.
My Bint and Aint above is the a0, a1, a2 , b0, b1, b2 in the transfer function.
Try to write this with the mac function (x[0] is the in-signal y[0] is the out-signal )
Code: Select all
acc = b0 * x[0] + b1 * x[1] + b2 * x[2] - a1*y[1] - a2*y[2];
y = acc>>30;
Code: Select all
// l is unsigned int , everything else is int
// put input in x[0]
h=0;l=0;
{h , l } = macs(b0, x[0] ,h , l);
{h , l } = macs(b1, x[1] ,h , l);
{h , l } = macs(b2, x[2] ,h , l);
{h , l } = macs(-a1, y[1] ,h , l);
{h , l } = macs(-a2, y[2] ,h , l);
y[2]=y[1];
y[1]=h<<2;
x[2]=x[1];
x[1]=x[0];
//output in h<<2 or y[1]
edit: Changed the code
Above is far from optimal, but a good start to improve further later.
Use my coefs above. They should work with
y[1]= h<<2; in the example code
int b0=21564350;
int b1=43128699;
int b2=21564350;
int a1= -1676130396;
int a2= 688645970;