#include <stdio.h> #include <stdint.h> #include <math.h> #include <dsplib.h> #define NUMSAMP 16 #define LENGTH NUMSAMP * 2 #define TAU 2 * 3.14159265358979323846 #pragma DATA_ALIGN(cosine, 8); float cosine[LENGTH]; #pragma DATA_ALIGN(plot, 8); int16_t plot[LENGTH]; #pragma DATA_ALIGN(fft, 8); int16_t fft[LENGTH]; #pragma DATA_ALIGN(twiddle, 8); int16_t twiddle[LENGTH]; #pragma DATA_ALIGN(itwiddle, 8); int16_t itwiddle[LENGTH]; #pragma DATA_ALIGN(result, 8); int16_t result[LENGTH]; void main(void) { int i; int m = 0; float f0Tc = 0.25; for(i = 0; i<LENGTH; i = i+2) { cosine[i] = (float)cos(TAU * m * f0Tc); cosine[i+1] = (float)0.0; m++; } DSP_fltoq15(cosine, plot, (short)LENGTH); gen_twiddle_fft16x16(twiddle, (int)NUMSAMP); gen_twiddle_ifft16x16(itwiddle, (int)NUMSAMP); DSP_fft16x16(twiddle, (int)NUMSAMP, plot, fft); DSP_ifft16x16(itwiddle, (int)NUMSAMP, fft, result); }
EDIT: both problems with FFT and IFFT are solved
Hello everybody,
I guess someone who read my previous thread about using the last release of C6455 DSPLIB with CCS v3.3 could see this coming: I've got some trouble making the DSP_fft16x16 function work.
Let me describe the context: I'm using CCS v3.3 with the C6455 Little Endian Simulator. CGT version is 6.0.8 and DSPLIB version is 3.0.0.8, which is the last one available. I include the library adding some information in the Project->Build Options->Linker->Libraries menu:
Search Path (-i): path of the folder where the library is located
Incl. Libraries (-l): dsplib.a64P
At first I tried to use the DSP_fltoq15 function and it worked fine, except for the following warning message I got:
" warning: creating output section $build.attributes without SECTIONS specification"
Then I tried to use the DSP_fft16x16 function and troubles began: results are not the ones I expect and following the fft with an ifft unsurprisingly does not give back the original sequence.
In the project I included:
-the dsplib.h header file from the "inc" folder created after installing the libraries
-the source codes of gen_twiddle_fft16x16 and gen_twiddle_ifft16x16 from a zip package named "ti_dsplib_src_c64Px_3_0_0_8" available in the "components" folder created after installing the libraries; when I built the project the corresponding .h files were included
-a command file for the linker taken from CSL examples (I have no experience with command files syntax so I took a file that gave no problem in my previous coding experiments; the lnk.cmd file that came with the DSPLIB example referred to DDR2 memory, which I'm not planning to use, and IRAM, which-at the moment- I don't know what it is)
Other building options are:
Target version: C64x+ (-mv6400+)
Endianness: Little Endian
The test code I wrote simulates the sampling of a 1 kHz sine wave and produces a sequence of 16 samples; then converts its values from floating point to Q15 format. It calculates twiddle coefficients for both FFT and IFFT and then applies the FFT routine to the sequence, following that with a IFFT to get the original sequence again.
I know for sure that the float to Q15 conversion is ok; I checked it using both the Watch Window the graph tools of CCS to be sure. But something goes wrong with the FFT, can't say if the problem is how the twiddle coefficients are generated or the FFT itself...or something related to compiling and linking issues I'm not aware of. The FFT gives as output a sequence which is -2 0 0 0 0 0 0 0 0 and then repeats three more times over the 32 points of the sequence.
Included with this post comes the code, so you can make it run and see if you get the same weird results as me. Hope this can be solved.
Regards,
Francesco Annese