This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to use fft function in TMD320C6657 DSP

Now I'm trying to use DSP_16x16_fft function.

but it's some different with matlab fft function. that function was short type but in matlab fft function was double type.

So I make input for short type. But Output was different with matlab..

#include <stdint.h>
#include <math.h>
#include <ti/dsplib/dsplib.h>
#include "gen_twiddle_fft16x16.h"
#include <time.h>
#define N 256
#pragma DATA_ALIGN(x_16x16, 8);
int16_t x_16x16 [2*N];
#pragma DATA_ALIGN(y_16x16, 8);
int16_t y_16x16 [2*N];
#pragma DATA_ALIGN(w_16x16, 8);
int16_t w_16x16 [2*N];
#pragma DATA_ALIGN(x_sp, 8);
float x_sp [2*N];
#pragma DATA_ALIGN(y_sp, 8);
float y_sp [2*N];
#pragma DATA_ALIGN(w_sp, 8);
float w_sp [2*N];
unsigned char brev[64] = {
0x0, 0x20, 0x10, 0x30, 0x8, 0x28, 0x18, 0x38,
0x4, 0x24, 0x14, 0x34, 0xc, 0x2c, 0x1c, 0x3c,
0x2, 0x22, 0x12, 0x32, 0xa, 0x2a, 0x1a, 0x3a,
0x6, 0x26, 0x16, 0x36, 0xe, 0x2e, 0x1e, 0x3e,
0x1, 0x21, 0x11, 0x31, 0x9, 0x29, 0x19, 0x39,
0x5, 0x25, 0x15, 0x35, 0xd, 0x2d, 0x1d, 0x3d,
0x3, 0x23, 0x13, 0x33, 0xb, 0x2b, 0x1b, 0x3b,
0x7, 0x27, 0x17, 0x37, 0xf, 0x2f, 0x1f, 0x3f
};
void generateInput () {
int32_t i, j;
for (i = 0; i < N; i++) {
x_16x16[2*i] = 1;
x_16x16[2*i + 1] = 1;
x_sp[2*i] = 1;
x_sp[2*i+1] = 1;
}
}
void gen_twiddle_fft_sp (float *w, int n)
{
int i, j, k;
const double PI = 3.141592654;

for (j = 1, k = 0; j <= n >> 2; j = j << 2)
{
for (i = 0; i < n >> 2; i += j)
{
#ifdef _LITTLE_ENDIAN
w[k] = (float) sin (2 * PI * i / n);
w[k + 1] = (float) cos (2 * PI * i / n);
w[k + 2] = (float) sin (4 * PI * i / n);
w[k + 3] = (float) cos (4 * PI * i / n);
w[k + 4] = (float) sin (6 * PI * i / n);
w[k + 5] = (float) cos (6 * PI * i / n);
#else
w[k] = (float) cos (2 * PI * i / n);
w[k + 1] = (float) -sin (2 * PI * i / n);
w[k + 2] = (float) cos (4 * PI * i / n);
w[k + 3] = (float) -sin (4 * PI * i / n);
w[k + 4] = (float) cos (6 * PI * i / n);
w[k + 5] = (float) -sin (6 * PI * i / n);
#endif
k += 6;
}
}
}

/*
The seperateRealImg function seperates the real and imaginary data
of the FFT output. This is needed so that the data can be plotted
using the CCS graph feature
*/

int16_t y_real_16x16 [N];
int16_t y_imag_16x16 [N];
int16_t x_real_16x16 [N];
int16_t x_imag_16x16 [N];
float y_real_sp [N];
float y_imag_sp [N];
float x_real_sp [N];
float x_imag_sp [N];

seperateInputRealImg () {
int32_t i, j;

for (i = 0, j = 0; j < N; i+=2, j++) {
x_real_16x16[j] = x_16x16[i];
x_imag_16x16[j] = x_16x16[i + 1];
}
}

seperateInputRealImgsp () {
int32_t i, j;

for (i = 0, j = 0; j < N; i+=2, j++) {
x_real_sp[j] = x_sp[i];
x_imag_sp[j] = x_sp[i + 1];
}
}

seperateRealImg () {
int32_t i, j;

for (i = 0, j = 0; j < N; i+=2, j++) {
y_real_16x16[j] = y_16x16[i];
y_imag_16x16[j] = y_16x16[i + 1];
}
}
seperateRealImgsp () {
int32_t i, j;

for (i = 0, j = 0; j < N; i+=2, j++) {
y_real_sp[j] = y_sp[i];
y_imag_sp[j] = y_sp[i + 1];
}
}


void main () {
/* Generate the input data */
generateInput ();
/* Genarate the various twiddle factors */
gen_twiddle_fft16x16(w_16x16, N);
gen_twiddle_fft_sp(w_sp, N);
seperateInputRealImg (x_16x16);
seperateInputRealImgsp (x_sp);
DSPF_sp_fftSPxSP(N, x_sp, w_sp, y_sp, brev, 2, 0, N);
/* Call the various FFT routines */
DSP_fft16x16(w_16x16, N, x_16x16, y_16x16);


/* Call the test code to seperate the real and imaginary data */
seperateRealImg (y_16x16);
seperateRealImgsp (y_sp);
}

follow photh is my input and output signal.

  ccs output

  matlab output

both of out put is different