Hello Community,
I found the solution: __L_mult_ls_int can multiply 32bit x 16bit values. It generates a 48bit result which is shifted 16bits right a returns a 32bit value. Here is the c-code for the 2order IIR filter function.
#include "Cpu.h"
#include "Filter.h"
/* L_mult_int */
Int16 SecOrderFilter(Int16 *x, TFilter *filter, TCoeff *coeff)
{
register Int32 temp;
register Int16 gain2;
//L(z)=b0 + b1*z^-1 + b2*z^-2
// ------------------------ * gain
// 1 + a1*z^-1 + a2*z^-2
//y=b0*x+b1*x(-1)+b2*x(-2)
// -a1*y(-1)-a2*y(-2)
gain2=16-coeff->gain;
temp= __L_mult_int(coeff->B0 , *x);
temp= __L_mac_int(temp, coeff->B1 , filter->x_1);
temp= __L_mac_int(temp, coeff->B2 , filter->x_2);
temp=temp - __L_mult_ls_int(filter->y_1 << gain2, coeff->A1); // SHR(32Bit x 16Bit, 16)=32Bit
temp=temp - __L_mult_ls_int(filter->y_2 << gain2, coeff->A2); // SHR(32Bit x 16Bit, 16)=32Bit
//Werte schieben
filter->x_2=filter->x_1;
filter->x_1=*x;
filter->y_2=filter->y_1;
filter->y_1=temp;
return extract_l(temp >> coeff->gain);
}
Attached you can find a excel sheet to design the filter an simulate the filter response.
Cheers
Seb.