1
votes

I'm currently trying to use the ARM CMSIS DSP library on my cortex m3 PSoC 5lp chip.
I ran into some issues using some of the functions and I have a question about using the functions arm_cfft_q15 (or any of the arm_cfft_*** functions).

Say I have

    q15_t ADC_samples[1024];
    q15_t MAG_of_fft[1024];

and I run

    arm_cfft_q15(1024pt_fft, ADC_samples, sample_length);

this does the transforms 'in place'. Now because of that, since the FFT returns both real and imaginary values, it will in fact only be able to return an fft of length 512 or is it 512 of the 1024 FFT samples? After getting the FFT I do

    arm_cmplx_mag_q15(ADC_samples, MAG_of_fft, fftlength);

where fftlength is 1024.

This returns MAG_of_fft and when I plot it, it does indeed seem to be the shape that I am expecting to see but I do not know exactly how to interpret the results since I don't know how long my FFT is exactly. I am telling it I am doing a 1024pt FFT but it seems to be only returning a 512pt FFT, or only half of the 1024pt FFT, one or the other.

So am I getting this right? This means that the ADC_samples array must be twice as long as the data in it order for me to get a 1024 pt FFT? and then I can calculate the magnitude of the FFT using that 2048 array by telling it the length of the FFT is 1024?

Can someone explain to me how to properly interpret these functions and what length FFT I should expect?

1

1 Answers

1
votes

The arm_cfft family of functions operate on complex valued signals. In other word a 1024-point FFT performed with arm_cfft_q15 requires 1024 complex input samples which are represented by 2048 q15_t values (interleaved real and imaginary parts, as described in the CMSIS DSP Software Library documentation). Upon return the buffer contains 1024 complex values (2048 q15_t values) corresponding to the frequency domain representation of the complex input signal.

So adapting this example to your case, you would compute the FFT with:

q15_t ADC_samples[2048];
arm_cfft_q15(1024pt_fft, ADC_samples, 0, 1);

The subsequent call

q15_t MAG_of_fft[1024];
arm_cmplx_mag_q15(ADC_samples, MAG_of_fft, fftlength);

with fftlength=1024 then reduces the 1024 complex values (2048 q15_t values) in ADC_samples to 1024 real magnitude values (1024 q15_t values), and stores the result in MAG_of_fft.

As as side note, if you are in fact dealing with real valued signals, then you could use the same functions and filling every second index (the imaginary parts) of the ADC_samples buffer with zeros (thus using an ADC_samples buffer that is twice as large as your actual number of real samples). Alternatively, you can use the more efficient arm_rfft family of functions (described in this section of the documentation).