Skip to main content
Senior III
September 9, 2026
Question

CMSIS DSP - arm_rfft_fast_f32 giving odd results

  • September 9, 2026
  • 0 replies
  • 7 views

Nucleowb55 - USB dongle

I am reading form 2 temp sensors (ADT7410) & 2 tri-axial accelerometers (ADXL345) & then sending the temp data, mean accelerometer & FFTs values along each axis.

 

For the accelerometers I read 2000 samples, take the mean & calculate FFT with arm_rfft_fast_f32()  and take the magnitudes using arm_cmplx_mag_f32(). I then pack the temp, acceleration means & top three FFT magnitudes for each axis for transmission over BLE. See code listing.

 

I have no sensors connected and every value I read from the transmitted BLE is 0 (which I expect) except for accelerometer 1’s 3rd peak FFT value for the x-axis which always read as -150669558266527122758482001920.00.

This is a sanity check really as I cant find a problem with me senor update function but was wondering if someone can spot something obvious I’ve been missing. (yes I know it might be the BLE client that is messing up but one step at a time)

 

/*
FFT & sensor data are held in the following type of union

union sensor_val
{
float sensor_float;
uint8_t sensor_bytes[4];
};
*/


void sensor_update(void)
{
/* FFT */
arm_rfft_fast_init_f32(&fft_instance, NUM_SAMP);

float32_t x_0_input[NUM_SAMP];
float32_t x_1_input[NUM_SAMP];

float32_t y_0_input[NUM_SAMP];
float32_t y_1_input[NUM_SAMP];

float32_t z_0_input[NUM_SAMP];
float32_t z_1_input[NUM_SAMP];


/* Temperature sensors */
ADT7410_ReadTemp(&temp_0);
temp_val_0.sensor_float = temp_0.deg_data;

ADT7410_ReadTemp(&temp_1);
temp_val_1.sensor_float = temp_1.deg_data;

/* Accelerometers */
acceleration_t ADXL345_data_0;
uint8_t acc_0_tx[12];
uint8_t fft_0_tx[36];

acceleration_t ADXL345_data_1;
uint8_t acc_1_tx[12];
uint8_t fft_1_tx[36];



for(int k = 0; k < NUM_SAMP; k++)
{
ADXL345_ReadAcc(&acc_0, &ADXL345_data_0);
ADXL345_ReadAcc(&acc_1, &ADXL345_data_1);

x_0_input[k] = ADXL345_data_0.ax;
y_0_input[k] = ADXL345_data_0.ay;
z_0_input[k] = ADXL345_data_0.az;

x_1_input[k] = ADXL345_data_1.ax; // This one!
y_1_input[k] = ADXL345_data_1.ay;
z_1_input[k] = ADXL345_data_1.az;
}


arm_mean_f32(x_0_input, 1000, &accel_x_0.sensor_float);
arm_mean_f32(y_0_input, 1000, &accel_y_0.sensor_float);
arm_mean_f32(z_0_input, 1000, &accel_z_0.sensor_float);

arm_mean_f32(x_1_input, 1000, &accel_x_1.sensor_float); // This one!
arm_mean_f32(y_1_input, 1000, &accel_y_1.sensor_float);
arm_mean_f32(z_1_input, 1000, &accel_z_1.sensor_float);


/* rFFTs */
arm_rfft_fast_f32(&fft_instance, x_0_input, x_0_fft, 0);
arm_rfft_fast_f32(&fft_instance, y_0_input, y_0_fft, 0);
arm_rfft_fast_f32(&fft_instance, z_0_input, z_0_fft, 0);

arm_rfft_fast_f32(&fft_instance, x_1_input, x_1_fft, 0); // This one!
arm_rfft_fast_f32(&fft_instance, y_1_input, y_1_fft, 0);
arm_rfft_fast_f32(&fft_instance, z_1_input, z_1_fft, 0);

/* Magnitudes */
arm_cmplx_mag_f32(x_0_fft, x_0_fft, NUM_SAMP/2);
arm_cmplx_mag_f32(y_0_fft, y_0_fft, NUM_SAMP/2);
arm_cmplx_mag_f32(z_0_fft, z_0_fft, NUM_SAMP/2);

arm_cmplx_mag_f32(x_1_fft, x_1_fft, NUM_SAMP/2); // This one!
arm_cmplx_mag_f32(y_1_fft, y_1_fft, NUM_SAMP/2);
arm_cmplx_mag_f32(z_1_fft, z_1_fft, NUM_SAMP/2);



fft_x_0_0.sensor_float = x_0_fft[0];
fft_x_0_1.sensor_float = x_0_fft[1];
fft_x_0_2.sensor_float = x_0_fft[2];

fft_y_0_0.sensor_float = y_0_fft[0];
fft_y_0_1.sensor_float = y_0_fft[1];
fft_y_0_2.sensor_float = y_0_fft[2];

fft_z_0_0.sensor_float = z_0_fft[0];
fft_z_0_1.sensor_float = z_0_fft[1];
fft_z_0_2.sensor_float = z_0_fft[2];

fft_x_1_0.sensor_float = x_1_fft[0];
fft_x_1_1.sensor_float = x_1_fft[1];
fft_x_1_2.sensor_float = x_1_fft[2]; // This one!

fft_y_1_0.sensor_float = y_1_fft[0];
fft_y_1_1.sensor_float = y_1_fft[1];
fft_y_1_2.sensor_float = y_1_fft[2];

fft_z_1_0.sensor_float = z_1_fft[0];
fft_z_1_1.sensor_float = z_1_fft[1];
fft_z_1_2.sensor_float = z_1_fft[2];

/* Pack acceleration data for BLE */
for(int i = 0; i < 4; i++)
{
acc_0_tx[i] = accel_x_0.sensor_bytes[i];
acc_1_tx[i] = accel_x_1.sensor_bytes[i];

acc_0_tx[i+4] = accel_y_0.sensor_bytes[i];
acc_1_tx[i+4] = accel_y_1.sensor_bytes[i];

acc_0_tx[i+8] = accel_z_0.sensor_bytes[i];
acc_1_tx[i+8] = accel_z_1.sensor_bytes[i];
}


/* Pack FFT data for BLE */
for(int j = 0; j < 4; j++)
{
fft_0_tx[j] = fft_x_0_0.sensor_bytes[j];
fft_0_tx[j+4] = fft_x_0_1.sensor_bytes[j];
fft_0_tx[j+8] = fft_x_0_2.sensor_bytes[j];

fft_0_tx[j+12] = fft_y_0_0.sensor_bytes[j];
fft_0_tx[j+16] = fft_y_0_1.sensor_bytes[j];
fft_0_tx[j+20] = fft_y_0_2.sensor_bytes[j];

fft_0_tx[j+24] = fft_z_0_0.sensor_bytes[j];
fft_0_tx[j+28] = fft_z_0_1.sensor_bytes[j];
fft_0_tx[j+32] = fft_z_0_2.sensor_bytes[j];

fft_1_tx[j] = fft_x_1_0.sensor_bytes[j];
fft_1_tx[j+4] = fft_x_1_1.sensor_bytes[j];
fft_1_tx[j+8] = fft_x_1_2.sensor_bytes[j]; // This one!

fft_1_tx[j+12] = fft_y_1_0.sensor_bytes[j];
fft_1_tx[j+16] = fft_y_1_1.sensor_bytes[j];
fft_1_tx[j+20] = fft_y_1_2.sensor_bytes[j];

fft_1_tx[j+24] = fft_z_1_0.sensor_bytes[j];
fft_1_tx[j+28] = fft_z_1_1.sensor_bytes[j];
fft_1_tx[j+32] = fft_z_1_2.sensor_bytes[j];
}


/* Send data packages over BLE */
Custom_STM_App_Update_Char(CUSTOM_STM_T_0, (uint8_t *)&temp_val_0.sensor_bytes);
Custom_STM_App_Update_Char(CUSTOM_STM_T_1, (uint8_t *)&temp_val_1.sensor_bytes);

Custom_STM_App_Update_Char(CUSTOM_STM_AC_0, (uint8_t *)&acc_0_tx);
Custom_STM_App_Update_Char(CUSTOM_STM_F_0, (uint8_t *)&fft_0_tx);

Custom_STM_App_Update_Char(CUSTOM_STM_AC_1, (uint8_t *)&acc_1_tx);
Custom_STM_App_Update_Char(CUSTOM_STM_F_1, (uint8_t *)&fft_1_tx); // This one
}