I have followed the userguid to implement the filter.
GDFLIB_FilterIIR2Init_FLT
and
GDFLIB_FilterIIR2_FLT
I have implemented an IIR filter in my project, which needs to be called periodically. However, the filter only works if I initialize it before each call, which resets the filter. This periodic reset is not acceptable for my design. If I initialize the filter only once at the beginning, the GDFLIB_FilterIIR2_FLT returns NaN values, indicating that the filter is not functioning correctly. Could you please provide an example of how to use the IIR filter effectively for periodic data filtering?
for
GDFLIB_FilterIIR2Init_FLT
and
GDFLIB_FilterIIR2_FLT
Hi, could you please share your implementation?
Do you have consulted 3.14.3 Worst-Case Error Bounds section of S32K3XXMCFLTACC?
Hi again,
The GDFLIB_FilterIIR2_FLT function is designed for periodic use and the GDFLIB_FilterIIR2Init_FLT function only needs to be called once at the beginning.
Here is a simplified example of how to use this filter periodically:
//---------------------------------------------------------------------
float fltIn[10] = {0, 0.3211, 0.7427, 0.6645, 0.2892, 0.3374, 0.9086, 0.0323, 0.6964, 0.2088};
float fltOut;
flttrMyIIR2.trFiltCoeff.fltB0 = (float)(0.066122101544579);
flttrMyIIR2.trFiltCoeff.fltB1 = (float)(0.0);
flttrMyIIR2.trFiltCoeff.fltB2 = (float)(-0.066122101544579);
flttrMyIIR2.trFiltCoeff.fltA1 = (float)(-1.776189018043779);
flttrMyIIR2.trFiltCoeff.fltA2 = (float)(0.867755796910841);
GDFLIB_FilterIIR2Init_FLT(&flttrMyIIR2);
for (int i = 0; i < 10; i++){
fltOut = GDFLIB_FilterIIR2_FLT(fltIn[i], &flttrMyIIR2);
}
//---------------------------------------------------------------------
A NaN value may appear at the filter output for several reasons:
More details can be found in the document Accuracy of Floating-Point Functions (S32K3XXMCFLTACC).