This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

cFFT using CMSIS in the TI Tiva/Stellaris

Hi,

I'm starting to test/study the CMSIS lib in the Stellaris/Tiva. Using the paper "Using the CMSIS DSP Library in Code Composer Studio™ for TM4C MCUs", I got build the library and it works fine. The examples return the expected state.

Now I'm trying to use the cFFT in a signal. To the test I created a pure sine wave with amplitude of 1000 and 10 cycles in an array of 1024 samples, as in the image.

array float.png

After the processing the indexer return the correct harmonic (10th), but I don't understand the result of the magnitude. The magnitude of the 10th hamonic is 727.98. How it relates to the amplitude of the harmonic? The RMS value, if yes, why the error?

This is the principal part of code:


#define     N_points    1024

...


uint32_t ifftFlag = 1;
uint32_t doBitReverse = 1;

/* Process the data through the CFFT/CIFFT module */
arm_cfft_f32(&arm_cfft_sR_f32_len512, wave_float, ifftFlag, doBitReverse);

/* Process the data through the Complex Magnitude Module for calculating the magnitude at each bin */
arm_cmplx_mag_f32(wave_float, wave_out, N_points/2);

/* Calculates maxValue and returns corresponding BIN value */
arm_max_f32(wave_out, N_points/2, &maxValue, &testIndex);

I tried to scale the sine wave between 1 and -1, but the result was the same. Instead of 727 the magnitude of the harmonic was 0.727.

It's strange because for different numbers of cycles the result of respective "bin" change.

Maintaining the same buffer size (1024) I changed to just one cycle and the result was around 708, very close to the RMS value. See this little list:

1024 samples

01 cycle -> 708.8323

02 cycles -> 710.9644

04 cycles -> 715.2491

08 cycles -> 723.74

16 cycles -> 740.4352

I tried to change the buffer size to 64 samples to test. In this case the result of one cycle was around 740.

I'm reading about how to obtain the amplitude, but in this moment I'm lost!

Parents
  • Hi agaelema,

    I commend you if everything work smoothly now, I'll just give additional thoughts since this topic may still be useful for us in the future.

    I asked for the numerical data of the input signal because of the following:

    • There could be some settings in your signal generation tool, such as delay or phase etc., that you overlooked and the effects were not accounted in your input data.
    • You used the Complex FFT function but the input data may not be in the proper arrangement, the real and the imaginary components must be interleaved.
    • You can use a real input signal for the Complex FFT function by supplying 0s to the imaginary components but you forgot to do so.

    To avoid swamping your list of things to mind, I deferred to state any of these until you provide a detailed information about your input and output data, meanwhile I just assumed you know that you are using a Complex version of FFT. This is water under the bridge now.

    Although you switched to Real FFT it may worth stating some concerns about the Complex FFT function since you may stumble upon it again.

    • The ifftFlag is just to get things in the proper perspective since you intend to do a forward FFT. If it is set to 1, as you did, your output will still show just two impulses (at index=1 and it's conjugate at index=N-1) when you used just one cycle at 1024 and 64 samples. Note, however, that the numerical values will be scaled differently had you used ifftFlag = 0.
    • There are issues that you should be aware of regarding the parameter arm_cfft_instance_f32 and DFT/FFT in general. The data buffer size is twice the FFT length, you've got it now. However, from your description and graph of the input signal it's clear that you generated 1024 samples. You're supposed to do a 1024-point FFT and you should have used arm_cfft_sR_f32_len1024, the data buffer size would be 2048. In your original setting the argument arm_cfft_sR_f32_len512 worked without harmful effects, the Complex FFT function just operated through half of your samples.

    If you have used 10 cycles in 1024 samples in your recent experiment, arm_cfft_sR_f32_len512 will work. The reason is that you are just actually giving only half of your samples (512) to FFT and the first half of your input data is the same as the second half, just as in your previous test.

    You can try to prove what I am pointing out by trying just one cycle at 1024 samples and use arm_cfft_sR_f32_len512. The defect will become obvious when you work with it.

    If you used 10 cycles in 1024 samples in your recent experiment, you will not get a faithful spectrum from your FFT until you do something about the spectral leakage that Daniel white mentioned in his reply to your original post.

    Regards,

    Goodwin

Reply
  • Hi agaelema,

    I commend you if everything work smoothly now, I'll just give additional thoughts since this topic may still be useful for us in the future.

    I asked for the numerical data of the input signal because of the following:

    • There could be some settings in your signal generation tool, such as delay or phase etc., that you overlooked and the effects were not accounted in your input data.
    • You used the Complex FFT function but the input data may not be in the proper arrangement, the real and the imaginary components must be interleaved.
    • You can use a real input signal for the Complex FFT function by supplying 0s to the imaginary components but you forgot to do so.

    To avoid swamping your list of things to mind, I deferred to state any of these until you provide a detailed information about your input and output data, meanwhile I just assumed you know that you are using a Complex version of FFT. This is water under the bridge now.

    Although you switched to Real FFT it may worth stating some concerns about the Complex FFT function since you may stumble upon it again.

    • The ifftFlag is just to get things in the proper perspective since you intend to do a forward FFT. If it is set to 1, as you did, your output will still show just two impulses (at index=1 and it's conjugate at index=N-1) when you used just one cycle at 1024 and 64 samples. Note, however, that the numerical values will be scaled differently had you used ifftFlag = 0.
    • There are issues that you should be aware of regarding the parameter arm_cfft_instance_f32 and DFT/FFT in general. The data buffer size is twice the FFT length, you've got it now. However, from your description and graph of the input signal it's clear that you generated 1024 samples. You're supposed to do a 1024-point FFT and you should have used arm_cfft_sR_f32_len1024, the data buffer size would be 2048. In your original setting the argument arm_cfft_sR_f32_len512 worked without harmful effects, the Complex FFT function just operated through half of your samples.

    If you have used 10 cycles in 1024 samples in your recent experiment, arm_cfft_sR_f32_len512 will work. The reason is that you are just actually giving only half of your samples (512) to FFT and the first half of your input data is the same as the second half, just as in your previous test.

    You can try to prove what I am pointing out by trying just one cycle at 1024 samples and use arm_cfft_sR_f32_len512. The defect will become obvious when you work with it.

    If you used 10 cycles in 1024 samples in your recent experiment, you will not get a faithful spectrum from your FFT until you do something about the spectral leakage that Daniel white mentioned in his reply to your original post.

    Regards,

    Goodwin

Children
No data