📄 real_t_fft.lst
字号:
C166 COMPILER V6.04, REAL_T_FFT 09/04/2007 16:24:44 PAGE 1
C166 COMPILER V6.04, COMPILATION OF MODULE REAL_T_FFT
OBJECT MODULE PLACED IN real_T_FFT.OBJ
COMPILER INVOKED BY: C:\Keil\C166\BIN\C166.EXE real_T_FFT.c MODV2 BROWSE MODV2 DEBUG
stmt lvl source
1 /******************************************************************************
2 * Module: main()
3 * Filename: real_T_FFT.c
4 * Project: DSP library for XC166 microcontroller
5 *------------------------------------------------------------------------------
6 * Compiler: Keil
7 *
8 * Version: V1.2
9 *
10 * Description:
11 * This example demonstrates the usage of the function
12 * real_T_FFT() which implements the real-valued forward
13 * Fast Fourie Transform (FFT) with decimation-in-time.
14 * The input values are real in 1Q15 format within [1,-1].
15 *
16 * Usage: To make the program runing, the following files are needed to
17 * add into the project:
18 * 1. real_DIT_FFT.c (forward Fourier transform)
19 * 2. FloatTo1Q15.c (format change from floting to 1Q15)
20 * 3. Bit_reverse.c (bit reverse of the input indices)
21 *
22 * References: 1. <C166S V2 User Manual>
23 *
24 * Date May 2003
25 *
26 * Copyright: Infineon Technologies AG
27 ******************************************************************************/
28
29 #include "DspLib_Keil.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32
33
34 #define ABSVAL(A) ((A) >= 0 ? (A) : (-A))
35 #define MAXERROR 10
36
37 #define N_x 16
38
39 //input data vector in 1Q15 format
40 DataS sdata x[N_x] ={
41 21061, /* 0 */ -3624, /* 1 */ 7564, /* 2 */ 19130, /* 3 */ 27641, /* 4 */
42 15609, /* 5 */ -21215, /* 6 */ -6180, /* 7 */ 28536, /* 8 */ 27319, /* 9 */
43 -5880, /* 10 */ 25795, /* 11 */ -28972, /* 12 */ -9642, /* 13 */ 20521, /* 14 */
44 -32119, /* 15 */
45 };
46
47 //reference output vector in 1Q15 format
48 DataS sdata rtest[N_x+2] = {
49 5347, 0, /*Re{X(0)}, Im{X(0)}*/ /* DC element */
50 -2077, -3242, /*Re{X(1)}, Im{X(1)}*/
51 288, -4611, /*Re{X(2)}, Im{X(2)}*/
52 -2424, 5522, /*Re{X(3)}, Im{X(3)}*/
53 2954, -1440, /*Re{X(4)}, Im{X(4)}*/
54 -3389, -4056, /*Re{X(5)}, Im{X(5)}*/
55 6077, -4313, /*Re{X(6)}, Im{X(6)}*/
C166 COMPILER V6.04, REAL_T_FFT 09/04/2007 16:24:44 PAGE 2
56 6019, 1334, /*Re{X(7)}, Im{X(7)}*/
57 810, 0, /*Re{X(8)}, Im{X(8)}*/ /* Nyquist point */
58 };
59
60 float Fdata [N_x];
61 DataS Idata [N_x];
62 //DataS i, exp;
63 // DataS X[N_x+2], table[3*N_x/4];
64 DataS table[3*N_x/4];
65 float Ftable[3*N_x/4];
66 //DataS index[N_x/2];
67 //float y;
68
69 //DataS diff, errflag=0;
70
71 void main()
72 {
73 1 DataS i, exp;
74 1 DataS X[N_x+2];// table[3*N_x/4];
75 1 DataS index[N_x/2];
76 1 float y;
77 1
78 1 DataS diff, errflag=0;
79 1 //float Fdata [N_x];
80 1 //DataS Idata [N_x];
81 1 for(i=0;i<N_x;i++)
82 1 {
83 2 Fdata[i]=Q15toFloat(x[i]);
84 2 Idata[i]=FloatTo1Q15(Fdata[i]);
85 2 }
86 1
87 1 //generate trigonomic function table
88 1 for(i=0; i<3*N_x/4; i++)
89 1 {
90 2 if(i<=N_x/2)
91 2 {//change the format from floating to 1Q15
92 3 y = FloatTo1Q15(2.*i/N_x);
93 3 table[i] = Sine(y);
94 3 Ftable[i]=Q15toFloat(table[i]);
95 3 }
96 2 else
97 2 {//change the format from floating to 1Q15
98 3 y = FloatTo1Q15(2.*(i-N_x)/N_x);
99 3 table[i] = Sine(y);
100 3 Ftable[i]=Q15toFloat(table[i]);
101 3 }
102 2 }
103 1
104 1 //generate the reverse index table
105 1 for(i=0; i<N_x/2; i++)
106 1 index[i] = i;
107 1
108 1 exp = Bit_reverse(index, N_x/2);
109 1 exp = exp+1; //N_x = 2^exp
110 1
111 1 // To point to the memory address, it needed to multiplay the indices by 4
112 1 for(i=0; i<N_x/2; i++)
113 1 index[i] = index[i] * 4;
114 1
115 1 /************ Perform the Fourier Transform *************/
116 1
117 1 //call real_DIT_FFT routine to perform real forward Fourier Transform
C166 COMPILER V6.04, REAL_T_FFT 09/04/2007 16:24:44 PAGE 3
118 1 real_DIT_FFT(x, index, exp, table, X);
119 1
120 1 /*------ test the function ------*/
121 1 //print the results, reference results and their difference
122 1 //the difference should be less than 10.
123 1 for(i=0; i<N_x+2; i++)
124 1 {
125 2 diff = rtest[i] - X[i];
126 2 if(ABSVAL(diff) > MAXERROR)
127 2 errflag = -1;
128 2 printf("Y[%d] = %6d, %6d, %6d\n", i, X[i], rtest[i], ABSVAL(diff));
129 2
130 2 }
131 1
132 1 if(errflag == -1)
133 1 printf("\nTest result: error \n");
134 1 else
135 1 printf("\nTest result: ok\n");
136 1
137 1 }
138
139 // End of file
MODULE INFORMATION: INITIALIZED UNINITIALIZED
CODE SIZE = 480 --------
NEAR-CONST SIZE = 63 --------
FAR-CONST SIZE = -------- --------
HUGE-CONST SIZE = -------- --------
XHUGE-CONST SIZE = -------- --------
NEAR-DATA SIZE = 168 --------
FAR-DATA SIZE = -------- --------
XHUGE-DATA SIZE = -------- --------
IDATA-DATA SIZE = -------- --------
SDATA-DATA SIZE = 68 --------
BDATA-DATA SIZE = -------- --------
HUGE-DATA SIZE = -------- --------
BIT SIZE = -------- --------
INIT'L SIZE = 76 --------
END OF MODULE INFORMATION.
C166 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -