?? real_t_fft.c
字號:
/******************************************************************************
* Module: main()
* Filename: real_T_FFT.c
* Project: DSP library for XC166 microcontroller
*------------------------------------------------------------------------------
* Compiler: Keil
*
* Version: V1.2
*
* Description:
* This example demonstrates the usage of the function
* real_T_FFT() which implements the real-valued forward
* Fast Fourie Transform (FFT) with decimation-in-time.
* The input values are real in 1Q15 format within [1,-1].
*
* Usage: To make the program runing, the following files are needed to
* add into the project:
* 1. real_DIT_FFT.c (forward Fourier transform)
* 2. FloatTo1Q15.c (format change from floting to 1Q15)
* 3. Bit_reverse.c (bit reverse of the input indices)
*
* References: 1. <C166S V2 User Manual>
*
* Date May 2003
*
* Copyright: Infineon Technologies AG
******************************************************************************/
#include "DspLib_Keil.h"
#include <stdio.h>
#include <stdlib.h>
#define ABSVAL(A) ((A) >= 0 ? (A) : (-A))
#define MAXERROR 10
#define N_x 16
//input data vector in 1Q15 format
DataS sdata x[N_x] ={
21061, /* 0 */ -3624, /* 1 */ 7564, /* 2 */ 19130, /* 3 */ 27641, /* 4 */
15609, /* 5 */ -21215, /* 6 */ -6180, /* 7 */ 28536, /* 8 */ 27319, /* 9 */
-5880, /* 10 */ 25795, /* 11 */ -28972, /* 12 */ -9642, /* 13 */ 20521, /* 14 */
-32119, /* 15 */
};
//reference output vector in 1Q15 format
DataS sdata rtest[N_x+2] = {
5347, 0, /*Re{X(0)}, Im{X(0)}*/ /* DC element */
-2077, -3242, /*Re{X(1)}, Im{X(1)}*/
288, -4611, /*Re{X(2)}, Im{X(2)}*/
-2424, 5522, /*Re{X(3)}, Im{X(3)}*/
2954, -1440, /*Re{X(4)}, Im{X(4)}*/
-3389, -4056, /*Re{X(5)}, Im{X(5)}*/
6077, -4313, /*Re{X(6)}, Im{X(6)}*/
6019, 1334, /*Re{X(7)}, Im{X(7)}*/
810, 0, /*Re{X(8)}, Im{X(8)}*/ /* Nyquist point */
};
float Fdata [N_x];
DataS Idata [N_x];
//DataS i, exp;
// DataS X[N_x+2], table[3*N_x/4];
DataS table[3*N_x/4];
float Ftable[3*N_x/4];
//DataS index[N_x/2];
//float y;
//DataS diff, errflag=0;
void main()
{
DataS i, exp;
DataS X[N_x+2];// table[3*N_x/4];
DataS index[N_x/2];
float y;
DataS diff, errflag=0;
//float Fdata [N_x];
//DataS Idata [N_x];
for(i=0;i<N_x;i++)
{
Fdata[i]=Q15toFloat(x[i]);
Idata[i]=FloatTo1Q15(Fdata[i]);
}
//generate trigonomic function table
for(i=0; i<3*N_x/4; i++)
{
if(i<=N_x/2)
{//change the format from floating to 1Q15
y = FloatTo1Q15(2.*i/N_x);
table[i] = Sine(y);
Ftable[i]=Q15toFloat(table[i]);
}
else
{//change the format from floating to 1Q15
y = FloatTo1Q15(2.*(i-N_x)/N_x);
table[i] = Sine(y);
Ftable[i]=Q15toFloat(table[i]);
}
}
//generate the reverse index table
for(i=0; i<N_x/2; i++)
index[i] = i;
exp = Bit_reverse(index, N_x/2);
exp = exp+1; //N_x = 2^exp
// To point to the memory address, it needed to multiplay the indices by 4
for(i=0; i<N_x/2; i++)
index[i] = index[i] * 4;
/************ Perform the Fourier Transform *************/
//call real_DIT_FFT routine to perform real forward Fourier Transform
real_DIT_FFT(x, index, exp, table, X);
/*------ test the function ------*/
//print the results, reference results and their difference
//the difference should be less than 10.
for(i=0; i<N_x+2; i++)
{
diff = rtest[i] - X[i];
if(ABSVAL(diff) > MAXERROR)
errflag = -1;
printf("Y[%d] = %6d, %6d, %6d\n", i, X[i], rtest[i], ABSVAL(diff));
}
if(errflag == -1)
printf("\nTest result: error \n");
else
printf("\nTest result: ok\n");
}
// End of file
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -