cancel
Showing results for 
Search instead for 
Did you mean: 

Error with arm_fir_f32()

ASpie.11
Associate

Hi,

i'm using the arm_fir_f32() funktion to filter a real time input signal.

My problem is, that the funktion return '-nan' for each input.

#include "foc.h"

#include "tim.h"

#include "adc.h"

#include "debug.h"

#include "arm_math.h"

/* FIR-FILTER */

#define BLOCK_SIZE 8

#define NUM_TAPS 10

uint16_t blocksize = BLOCK_SIZE;

arm_fir_instance_f32 S;

static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS -1];

const float32_t firCoeffs32[NUM_TAPS] = {

 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f,

};

float32_t in[8]={0, 0, 0, 0, 0, 0, 0, 0};

float32_t out[8]={0, 0, 0, 0, 0, 0, 0, 0};

/* Init FIR-Filter */

arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blocksize);

/* This funktion is called after the adc-conversion is finished (20000Hz) */

void FOCLOOP(void)

{

   Get_Angle_rad(ADC_Value[3], &theta_rad_mech[0]);

   Convert_Angle_rad(&theta_rad_mech[0], &theta_rad_el[0], motor_1.PPZ);

   theta_grad_el = radtograd(theta_rad_el[0]);

   CalcOmega(&theta_rad_mech[0], &omega_el[0], freq);

   for(int i = BLOCK_SIZE; i>=1; i--) {

      in[i] = in[i-1];

   }

   in[0] = omega_el[0];

   arm_fir_f32(&S, &in[0], &out[0], blocksize);

}

3 REPLIES 3

Perhaps find and review others examples for usage?

STM32Cube_FW_F4_V1.21.0\Drivers\CMSIS\DSP_Lib\Examples\arm_signal_converge_example\ARM\arm_signal_converge_example_f32.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AvaTar
Lead

The float datatype has a limited precision of only 24 bytes, which makes "divisions by almost zero" much more probable.

I suggest to single-step through your code, and check where the problem occurs. You might be able to tweek filter coefficients and input data (angles ?) to avoid the problem.

To not confuse some newbies, I'll correct - in C language float datatype has a size of 32 bits, but precision of 24 bits (not bytes). :)