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
  • I opened the TI E2E Community link you provided, and these are my views about your discussion:

    • Whether you can expect to recover the time domain amplitude of 1000 in the frequency domain depends on the particular definition used for the DFT. You have to be aware that there are slight variations in the definition of DFT, different implementations may use different scaling. For most references (textbooks, journals, articles, appnotes, and other publications) that I've previously read about DFT, the magnitude can grow by a factor of DFT length (1024 in your test) that's why I recommended that you use a smaller peak value.
    • Although the DFT/FFT is for discrete data, we don't have to worry about the discontinuity of the data all the time. In these settings that you used:

    1 cycle at 1024 samples, 1 cycle at 64 samples

    if we properly use the FFT Function we can get a faithful spectrum, that is, a spectrum that is free from harmonics, other form of aliasing, or forms of distortion (of course the amplitude is subjected to round-off errors but we don't have to get bothered by this for the moment).

    • Martin Valencia's "baby step" outlines the operations you have to do when building a spectrum analyzer. In my reply to you I focused only on FFT. There are also other ways of computing and formatting the spectrum and other information such as SNR, THD, SINAD, etc.

    Enjoy working with your Tiva/Stellaris.

Reply
  • I opened the TI E2E Community link you provided, and these are my views about your discussion:

    • Whether you can expect to recover the time domain amplitude of 1000 in the frequency domain depends on the particular definition used for the DFT. You have to be aware that there are slight variations in the definition of DFT, different implementations may use different scaling. For most references (textbooks, journals, articles, appnotes, and other publications) that I've previously read about DFT, the magnitude can grow by a factor of DFT length (1024 in your test) that's why I recommended that you use a smaller peak value.
    • Although the DFT/FFT is for discrete data, we don't have to worry about the discontinuity of the data all the time. In these settings that you used:

    1 cycle at 1024 samples, 1 cycle at 64 samples

    if we properly use the FFT Function we can get a faithful spectrum, that is, a spectrum that is free from harmonics, other form of aliasing, or forms of distortion (of course the amplitude is subjected to round-off errors but we don't have to get bothered by this for the moment).

    • Martin Valencia's "baby step" outlines the operations you have to do when building a spectrum analyzer. In my reply to you I focused only on FFT. There are also other ways of computing and formatting the spectrum and other information such as SNR, THD, SINAD, etc.

    Enjoy working with your Tiva/Stellaris.

Children
No data