2026-03-30 3:31 AM
Hello. I'm using a combo of a wba board and a LSM6dsv IMU sensor. I collect sampoles from the imu and then send them to my pc to do some fft there and als odo fft on board using the cmsis dsp libraries. The thing is that my pyrhon spectrum appears to be correct. I'm using a vibrator to make sure about that it [produces the requested frequency and monitor the results with the integrated vibrator's sensor. The python sprectrum appears to match the vibrator's sensor sprectrum whereas the cmsis results appear a lot more noisy and have an almost mirrored in the middle huge harmonic. Lets say than my sensor'f sampling rate is 4 KHz, so im able to do fft on up to 2 KHz event freq. If my vibrator is at 300 Hz i will see a huge harmonic in lets say 1600-1700 hz which gets closer the more i go to 1000 Hz. At 900- 1200 Hz the spectrum appears to be a complete mess and at 1300 HZ and afterwards it is simply beautiful.
Here is the mcu code. I do a hanning window and median removal before doing the onboard fft. I also tried using a seperate buffer but got the same results.
float mean_x = 0.0f, mean_y = 0.0f, mean_z = 0.0f;
arm_mean_f32(inplace_FFT_array_x, FFT_SIZE, &mean_x);
arm_mean_f32(inplace_FFT_array_y, FFT_SIZE, &mean_y);
arm_mean_f32(inplace_FFT_array_z, FFT_SIZE, &mean_z);
arm_offset_f32(inplace_FFT_array_x, -mean_x, inplace_FFT_array_x, FFT_SIZE);
arm_offset_f32(inplace_FFT_array_y, -mean_y, inplace_FFT_array_y, FFT_SIZE);
arm_offset_f32(inplace_FFT_array_z, -mean_z, inplace_FFT_array_z, FFT_SIZE);
LOG_INFO_APP("FRAME_START RAW\r\n");
for (int i = 0; i < FFT_SIZE; i++) {
LOG_INFO_APP("%.2f\r\n", inplace_FFT_array_z[i] + mean_z);
}
LOG_INFO_APP("FRAME_END RAW\r\n");
/////////////////////////// APPLY HANNING WINDOW
for(int i = 0; i < FFT_SIZE; i++)
{
float w = 0.5f * (1.0f - cosf(2 * PI * i / (FFT_SIZE - 1)));
inplace_FFT_array_z[i] *= w;
}
////////////////////////// FFT FUNCTION CALCULATION
arm_rfft_fast_f32(&fft_instance, inplace_FFT_array_z,
inplace_FFT_array_z, 0);
LOG_INFO_APP("FRAME_START FFT\r\n");
////////////////////////// FREQ MAG CALCULATION AND NORMALIZATION
for (uint32_t k = 1; k < FFT_SIZE / 2; k++)
{
float re = inplace_FFT_array_z[2*k];
float im = inplace_FFT_array_z[2*k + 1];
float mag = sqrtf(re * re + im * im);
// mag /= (FFT_SIZE / 2);
float freq = ((float)k * HG_SENSOR_FREQ) / FFT_SIZE;
LOG_INFO_APP("%.2f,%.2f\r\n", freq, mag);
}
LOG_INFO_APP("FRAME_END FFT\r\n");
2026-03-30 5:04 AM - edited 2026-03-30 5:57 AM
Hi,
> is at 300 Hz i will see a huge harmonic in lets say 1600-1700 hz
-- so you see the the mirror image (0 + 300 + 2000 - 300 ) -> probably you simply fill the input array wrong.
Or you use a full FFT and look at all output data (4k in -> 4K out, there always is the mirrored spectrum.)
+
Check your FFT settings with an calculated sine in the data array , to find out , whats wrong.
2026-03-30 5:54 AM
Device sampling rate is almost 4 Khz, meaning that i can sample event up to 1.8-2 KHz, which i do.
I've included the calculations for freq and magnitude. I don't use the whole fft output, just the first half.
2026-03-30 6:13 AM
So maybe you didnt read , in arm_rfft_init_f32 :
>Supported FFT Lengths are 128, 512, 2048. <
Is your fft size > 2048 ?
+
Check your FFT settings with an calculated sine in the data array , to find out , whats wrong.
2026-03-30 11:08 PM
Im using a 1024 point FFT. It says here that this size is supported but i will do some other test and also do what you advised me.