📄 real_dit_fft.lst
字号:
C166 COMPILER V6.04, REAL_DIT_FFT 09/04/2007 16:24:44 PAGE 1
C166 COMPILER V6.04, COMPILATION OF MODULE REAL_DIT_FFT
OBJECT MODULE PLACED IN real_DIT_FFT.OBJ
COMPILER INVOKED BY: C:\Keil\C166\BIN\C166.EXE real_DIT_FFT.c MODV2 BROWSE MODV2 DEBUG
stmt lvl source
1 /*******************************************************************************
2 ; Module: Real_DIT_FFT
3 ; Filename: Real_DIT_FFT.c
4 ; Project: DSP library for XC16x Microcontroller
5 ;------------------------------------------------------------------------------
6 ; Compiler: Keil
7 ;
8 ; Version: V1.2
9 ;
10 ; Description: Implementation of forward real Radix-2 decimation-in-time
11 ; Fast Fourie Transformation
12 ;
13 ; Date: May 2003
14 ;
15 ; Copyright: Infineon Technologies AG
16 ;
17 ; Author: Guangyu Wang
18 ;******************************************************************************/
19
20 /******************************************************************************
21 ; void real_DIT_FFT(
22 ; DataS* x, // input vector
23 ; DataS* index, // bit reversed input indecies
24 ; DataS exp, // exponent of vector size
25 ; DataS* table, // trigonomic function table
26 ; DataS* X // output of FFT
27 ; )
28 ;
29 ; INPUTS:
30 ; x the input value in 1Q15 format
31 ; index bit reversed input indecie
32 ; exp exponent of vector size
33 ; table trigonomic function table
34 ;
35 ; RETURN:
36 ; X the FFT output vector in 1Q15 format
37 ;
38 ; ALGORITHM: Radix-2 decimation-in-time FFT
39 ;
40 ; REGISTER USAGE:
41 ; 1. From .c file to .asm file:
42 ; R8 pointer of input vector x
43 ; R9 pointer of index vector
44 ; (R10) = exp
45 ; R11 pointer of trigonomic function table
46 ; R12 contains the pointer of output vector X
47 ;
48 ;
49 ; 2. From .asm file to .c file
50 ;
51 ; Assumptions:
52 ; 1. scale factor = 1/N (N=2^exp), preventing overflow
53 ; 2. FFT_of_x(k) = N*X(k)
54 ;
55 ;*****************************************************************************/
C166 COMPILER V6.04, REAL_DIT_FFT 09/04/2007 16:24:44 PAGE 2
56
57 /*========================= Define registers =================================
58
59 Outloop LIT 'R4' ; R4 counter
60 Midloop LIT 'R3' ; Midloop counter
61 Inloop LIT 'R1' ; Inloop counter
62 P_off LIT 'QR0' ; offset to P element in x
63 Q_off LIT 'QR1' ; offset to Q element in x
64 FFT_in LIT 'R8' ; Pointer to first element in x
65 index LIT 'R9' ; Pointer to first element in index
66 exp LIT 'R10' ; exp
67 table LIT 'R11' ; Pointer to first element in table
68 X LIT 'R12' ; Pointer to first element in X
69 counter LIT 'R13' ; 2^(exp)=N
70 ============================================================================*/
71
72 /* ---------------------------------------------------------
73 ; Butterfly macros used for radix-2 forward
74 ; decimation-in-time (DIT) FFT
75 ; ---------------------------------------------------------
76
77 ;**************************************************************
78 ;
79 ; n = stage
80 ;
81 ; Pn = Re(Pn) + Im(Pn)
82 ;
83 ; Qn = Re(Qn) + Im(Qn)
84 ;
85 ; Pn------------------->-------->(+)----------------->Pn+1
86 ; \ ^
87 ; \ /
88 ; \ /
89 ; \/
90 ; /\
91 ; / \
92 ; / \
93 ; / V
94 ; Qn------------------->-------->(+)----------------->Qn+1
95 ; k
96 ; W -1
97 ; N
98 ;
99 ; k
100 ; Pn+1 = Pn + W * Qn
101 ; N
102 ; k
103 ; Qn+1 = Pn - W * Qn
104 ; N
105 ;
106 ; k -j(2pi/N)k
107 ; W = e = cos(X) - j * sin(X)
108 ; N
109 ;
110 ; 2*pi
111 ; X = ( ---- )k
112 ; N
113 ;
114 ; Pn+1 = Re(Pn) + Re(Qn) * cos(x) + Im(Qn) * sin(x)
115 ; + j[Im(Pn) + Im(Qn) * cos(x) - Re(Qn) * sin(x)]
116 ;
117 ; Qn+1 = Re(Pn) - Re(Qn) * cos(x) - Im(Qn) * sin(x)
C166 COMPILER V6.04, REAL_DIT_FFT 09/04/2007 16:24:44 PAGE 3
118 ; + j[Im(Pn) - Im(Qn) * cos(x) + Re(Qn) * sin(x)]
119 ;----------------------------------------------------------*/
120
121
122 #include "DspLib_Keil.h"
123
124 void real_DIT_FFT(DataS* x, DataS* index, DataS exp, DataS* table, DataS* X)
125 {
126 1 __asm
127 1 {
128 1 //store the system state
129 1 PUSH R13
130 1 PUSH R14
131 1 PUSH R15
132 1
133 1 //initialization of registers
134 1 MOV R4,exp // (R4) = exp
135 1 SUB R4,#1h // (R4) = exp-1
136 1 MOV R13,#1h // (R13)=counter = 1
137 1 SHL R13,exp // (R13)=counter = 2^exp = N
138 1 MOV R5,R13 // (R5) = N
139 1 SHR R5,#1h // (R5) = N/2
140 1
141 1 //initialize the basic address of cosinus
142 1 ADD R5,table // (R5) = table + N/2= address of cos(x)
143 1
144 1 //reset R2
145 1 MOV R2,R13 // (R2) = N
146 1 SHL R2,#1h // (R2) = 2*N
147 1
148 1 //MAC registers initialization
149 1 MOV MCW,#0200h // MP=0, MS=1
150 1
151 1 OUT_LOOP:
152 1 MOV R3,#0 //(R3) = 0
153 1 MOV R6,R13 //(R6) = N
154 1 SHR R6,#2 //(R6) = N/4 = number of Inloops
155 1
156 1 MID_LOOP:
157 1 MOV R1,R6 // restore Inloop
158 1
159 1 EXTR #3
160 1 MOV QR0,R3 // (QR0) = offset of Pn in FFT_in
161 1 MOV QR1,QR0 // (QR1) = (QR0)
162 1 ADD QR1,R13 // (QR1) = offset of Qn in FFT_in
163 1 PUSH R13
164 1
165 1 //------Determination of Index for Twiddle-Factor
166 1 MOV R7,R3
167 1 SHR R7,R4
168 1
169 1 //------Determination of Twiddle-Factor
170 1 ADD R7,index // (R7)=(R7)+index
171 1 MOV R7,[R7] // (R7) = Bit reverse index
172 1
173 1 MOV R14,R5 // move basic address of cos(x) into R14
174 1 MOV R15,table // move basic address of sin(x) into R15
175 1 ADD R14,R7 // add offset
176 1 ADD R15,R7
177 1
178 1 MOV R14,[R14] // (R14) = cos(x)
179 1 MOV R15,[R15] // (R15) = sin(x)
C166 COMPILER V6.04, REAL_DIT_FFT 09/04/2007 16:24:44 PAGE 4
180 1
181 1 PUSH R5 // push basic address of cos(x)into stack
182 1 PUSH R6
183 1 PUSH R12
184 1
185 1 IN_LOOP:
186 1 //------use general butterfly
187 1
188 1 CoNOP [x+QR0]
189 1
190 1 // %Wk_Butterfly()
191 1 /*-----------------------------------------
192 1 ; %DEFINE (Wk_Butterfly ())(
193 1 ; general Butterfly
194 1 ; (R14) = cos(x)
195 1 ; (R15) = sin(x)
196 1 ; W = cos(x) - j * sin(x)
197 1 ------------------------------------------*/
198 1
199 1 //------Input Pn---------------------------
200 1 //(R5) = Re(Pn)
201 1 //(R6) = Im(Pn)
202 1 MOV R5,[x+] // (R5) = X[QR0] = Re(Pn)
203 1 // (R8) = (R8)+2
204 1 MOV R6,[x] // (R6) = X[QR0+1] = Im(Pn)
205 1 ASHR R5,#1 // Re(Pn)=Re(Pn)/2,
206 1 ASHR R6,#1 // Im(Pn)=Im(Pn)/2,
207 1
208 1 SUB x,#2h // (R8) = (R8)-2
209 1 CoNOP [x - QR0] // (R8) = (R8) - (QR0)
210 1 CoNOP [x + QR1] // (R8) = (R8) + (QR1)
211 1
212 1 //------Input Qn---------------------------
213 1 // ((R12)) = Re(Qn)
214 1 // ((R12+2)) = Im(Qn)
215 1
216 1 //------Calculation of Real Parts---------
217 1 //(R7) = Re(Pn+1) = Re(Pn) + Re(Qn) * cos(X) + Im(Qn) * sin(x)
218 1 MOV MAH,R5 // (ACC) = Re(Pn)
219 1 CoMAC R14,[x+] // (ACC) = Re(Pn) + (Re(Qn) * cos(x))
220 1 // (R8) = (R8)+2
221 1 CoMAC R15,[x-] // (ACC) = (ACC) + (Im(Qn) * sin(x))
222 1 // (R8) = (R8) - 2
223 1 CoSTORE R7,MAS // (R7) = Re(Pn+1)
224 1
225 1 //(R8) = Re(Qn+1) = Re(Pn) - Re(Qn) * cos(x) - Im(Qn) * sin(x)
226 1 MOV MAH,R5 // (ACC) = Re(Pn)
227 1 CoMAC- R14,[x+] // (ACC) = Re(Pn) - (Re(Qn) * cos(x))
228 1 // (R8) = (R8) + 2
229 1 CoMAC- R15,[x] // (ACC) = (ACC) - (Im(Qn) * sin(x))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -