2013-06-25 05:40 AM
Hi,
I try to implement a IIR filter with the ''arm_biquad_cascade_df2T_f32
'' function from the CMIS dsp libraries and I encountered a problem: my output datas and my pstate table are overflowed after few iterations. I generated my coefficients with fdatool from matlab. They are stored in the followed order:{b10, b11, b12, a11, a12, b20, b21, b22, a21, a22, ...}
float32_t iir_coeff[30] = {
1, -0.0249943904456238, 0.999999999999993, -1.77729633861929, 0.845140679514385,
1, -1.42288228590609, 0.999999999999998, -1.72245970919624, 0.896574493119215,
1, -1.99973299802181, 1, -1.91581723732986, 0.929183550605981,
1, -1.5986745646875, 1, -1.72677706239042, 0.969582040573283,
1, -1.99845599796938, 0.999999999999999, -1.97568100711438, 0.981035519941801,
1, -1.99766610993993, 1, -1.99201600960503, 0.995968747765197
};
I don't know how to incorporate the ''Scale factors''. I try to add it to my coeff table as follow but it dosn't work.
float32_t iir_coeff[35] = {
0.001843832549177, 0, 0, 0, 0,
1, -0.0249943904456238, 0.999999999999993, -1.77729633861929, 0.845140679514385,
1, -1.42288228590609, 0.999999999999998, -1.72245970919624, 0.896574493119215,
1, -1.99973299802181, 1, -1.91581723732986, 0.929183550605981,
1, -1.5986745646875, 1, -1.72677706239042, 0.969582040573283,
1, -1.99845599796938, 0.999999999999999, -1.97568100711438, 0.981035519941801,
1, -1.99766610993993, 1, -1.99201600960503, 0.995968747765197
};
Here a part of my code:
#define NUM_STAGE 7 // if I don't incorporate the ''Scale factors'' NUM_STAGE = 6
static
float32_t iirStateF32X[2*NUM_STAGE];
arm_biquad_cascade_df2T_instance_f32 SX;
int
main(
void
)
{
arm_biquad_cascade_df2T_init_f32(&SX, NUM_STAGE, (float32_t *)&iir_coeff[0], &iirStateF32X[0]);
...
// in the interruption:
float32_t *inputF32X, *outputF32X
inputF32X = &temp_buffer[0];
outputF32X = &AccBufferX_filter[0];
arm_biquad_cascade_df2T_f32(&SX, inputF32X, outputF32X, FILTER_BUFFER_SIZE);
This code works with the fir functions.
Does someone know where the problem is ?
Thanks.
2013-06-25 11:37 PM
I can't serve with detailed knowledge about IIR and FIR filter implementations, but how about debugging ?
Had your mathlab tool possibly creating code for double, and not float ?2013-06-26 02:41 AM
Hi,
I don't think that is a problem of precision. Actually the IIR ST function only accepts floats coefficients.2013-06-26 04:24 AM
Actually the IIR ST function only accepts floats coefficients.
Correct. The most you can get in this Cortex M world is a M4 with single-precicision FPU, so double would be a performance hog.I don't think that is a problem of precision.
There is certainly a difference in precicision for float and double. Look
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
, for instance. The generated code might work with double, but exhibit instabilities when clipped to float. I would check intermediary results with a debugger.2013-06-26 07:38 AM
To me it looks like you don't have enough coefficients in
iir_coeff.
Try to generate those 35 coeffs somehow.2013-06-26 08:50 AM
To me it looks like you don't have enough coefficients in
iir_coeff.
Try to generate those 35 coeffs somehow.
My bad, when I put the IIR coefficients without the ''scale fators'' the iir_coeff table size is 30 and NUM_STAGE is egal to 6.
2013-06-26 10:34 AM
I don't know, those bx1 and ax1 looks suspicious, mostly close to -2, I would rather expect something close to +-1 or fractional.
2013-06-27 12:50 PM
You can try to negate the axx coefficients, it may solve the problem.