2

I am working on a project where I have to compute FFT of a signal. Same signal is fed through both MATLAB and STM32 controller and results are compared.

Results seems to be different from each other. I don't know what I am doing wrong.

The STM32 Code is below.

//Pre-FFT
arm_fill_f32(0, &tempBuff_1[FrameLen], 256-(FrameLen)); //zero padding

PreFFTProcess(tempBuff_1, tempBuff_2, 256); //Convert format from Real[0],Real[1],Real[2],Real[3].. to Real[0],Img[0],Real[1],Img[1]...

//FFT
arm_cfft_f32(&fftInstance, tempBuff_2 , 0, 1); //FFT

arm_cmplx_mag_f32(tempBuff_2, tempBuff_1, 256); //ABS

The MATLAB code: Out = abs(fft(Input,256));

The results:

MATLAB vs STM32 FFT Result1

MATLAB vs STM32 FFT Result1

MATLAB vs STM32 FFT Result2

MATLAB vs STM32 FFT Result2

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • and if you do `Out = abs(fft(single(Input),256));` ? The difference looks fairly small to be fair. I am not sure if numerical precission level small, but quite small anyway. When working with numerical algorithms in computers you always need to accept that there will be a small mismatch, is this difference worrying to you? – Ander Biguri Jan 11 '23 at 09:07
  • @AnderBiguri, casting single didn't make any difference. I expected closer results. I don't know if fft algorithm of CMSIS and MATLAB is same, maybe this causes the difference in output. – user19402326 Jan 11 '23 at 10:23
  • Yes I suspect that may be it, but I'd say those plots look very close to each other, it almost seems that its noise that makes the difference. Precission is always dependent on the target task though, so only you can decide if this is good enough. I do not know much of CMSIS, so I can't help pinpoint if this is a algorithm issue or a code issue. A [mcve] would help, though. – Ander Biguri Jan 11 '23 at 10:43
  • 1
    The inputs to the FFT are likely different. We don’t see how the data is prepared, so can’t comment on that. Please read [mre]. – Cris Luengo Jan 11 '23 at 15:05
  • 1. what are you measuring ; Volts Amps Watts? 2. really comparing? or are you feeding the measurement obtained with the STM to MATLAB? 3. frequency seems quite accurate, yet there also seems to be a 0.1 [V? A? W?] difference between both, the cable between STM and computer? any damage on the cable? sharp elbow? worn/loose connector? – John BG Jan 15 '23 at 12:57

0 Answers0