Lecture 39 The program is as follows .mmregs .def _c_int00 .data ; Reserve 8 locations for x(n) ;x(n) xn0 xn1 xn2 xn3 xn4 xn5 xn6 xn7 Q15 notation decimal value .word 0 ; 0h . word 16384 ; 4000h .word 23170 ; 5A82h . word - 24576 ; E000h .word 12345 ; 3039h .word 30000 ; 7530h .word 10940 ; 2ABCh .word 12345 ; 3039h ; Reserve 16 locations for X(k) X0R .word 0 X0Im .word 0 X1R .word 0 X1Im .word 0 X2R .word 0 X2Im .word 0 X3R .word 0 X3Im .word 0 X4R .word 0 X4Im .word 0 X5R . word 0 X5Im .word 0 X6R .word 0 X6Im .word 0 X7R .word 0 ;real part of X(0) =0 ;imaginary part of X(0) =0 0.0 0.5 0.707 -0.25 0.3767 0.9155 0.334 0.3767 X7Im .word 0 ; 8 locations for W08 to W38, twiddle factors W08R W08Im W18R W18Im W28R W28Im W38R W38Im .word 32767 .word 0 .word 23170 .word -23170 .word 0 .word -32767 .word -23170 .word -23170 ;cos(0)=1 ;-sin(0)=0 ;cos(pi/4)= 0.707 ;-sin(pi/4)= -0.707 ;cos(pi/2)= 0 ;-sin(pi/2)= -1 ;cos(3pi/4)= -0.707 ;-sin(3pi/4)= -0.707 ; 8 locations for Spectrum S0 .word 0 S1 .word 0 S2 .word 0 S3 .word 0 S4 .word 0 S5 .word 0 S6 .word 0 S7 .word 0 ;temporary locations TEMP1 .word 0 TEMP2 .word 0 ;Frequency content at 0 ;Frequency content at fs/8 ;Frequency content at 2fs/8 ;Frequency content at 3fs/8 ;Frequency content at 4fs/ ;Frequency content at 5fs/8 ;Frequency content at 6fs/8 ;Frequency content at 7fs/8 ;MAIN PROGRAM . text _c_int00: SSBX SXM ; set sign extension mode bit of ST1 CALL _clear CALL _bitrev Clear subroutine is shown in fig. 6.11. Sixteen locations meant for final results are cleared. AR2 is used as pointer to the locations. Bit reverse subroutine is shown in fig. 6.12. Here, AR1 is used as pointer to x(n). AR2 is used as pointer to X(k) locations. AR0 is loaded with 8 and used in bit reverse addressing. Instead of N/2 =4, it is loaded with N=8 because each X(k) requires two locations, one for real part and the other for imaginary part. Thus, x(n) is stored in alternate locations, which are meant for real part of X(k). AR3 is used to keep track of number of transfers. Fig. 6.11: Clear subroutine Butterfly subroutine is invoked 12 times. Part of the subroutine is shown in fig. 6.13. Real part and imaginary of A and B input data of butterfly structure is divided by 4 which is the scaling factor. Real part of A data which is divided by 2 is stored in temp location. It is used further in computation of eq (3) and eq (4) of butterfly. Division is carried out by shifting the data to the right by two places. AR5 points to real part of A input data, AR2 points to real part of B input data and AR3 points to real part of twiddle factor while invoking the butterfly subroutine. After all the four equations are computed, the pointers are in the same position as they were when the subroutine is invoked. Thus, the results are stored such that in-place computation is achieved. Fig. 6.14 through 6.17 show the butterfly subroutine for the computation of 4 equations. MVMM AR1,AR5 STM#TEMP1,AR4 Replace AR with AR/4 LD *AR5, -2, A STL A, *AR5+ STL A, 1,*AR4+ Store AR/2 in TEMP1 Replace AIm with AIm/4 LD *AR5, -2, A STL A, *AR5STL A, 1, *AR4- Store AIm/2 in TEMP2 LD *AR2, -2, A STL A, *AR2+ Replace BR with BR/4 LD *AR2, -2, A STL A, *AR2- Replace BIm with BI/4 Fig. 6.13: Butterfly Subroutine AR5 AR2 AR3 (1) AR= AR + BR x WR – BI x WI Round & store LD MPY MAS ADD ADD STH A= BR x W R #0, A *A R 2 + , *A R 3 + , A * A R 2 -, * A R 3 , A *A R 5 , 1 5 , A #1, 14, A A , 1 , *A R 5 + A =B R x W R – B I x W I M a k e A R 3 2 b it s a n d A= AR + BR x W R – BI x W I Fig. 6.14: Real part of A output of Butterfly AR5 AR2 AR3 Fig. 6.15: Imaginary part of A output of Butterfly ;(3 ) B R= A R – (B R x W R - B I x W I) LD Load A with AR scaled by 2 * A R 4 + ,A From this, subtract new AR S U B * A R 5 + ,A S T L A , *A R 2 + Store lower 16 bits as BR Fig. 6.16: Real part of B output of Butterfly ;(4) BI= AI – (BI x WR +BR x WI) LD *AR4 -, A SUB *AR5-, A STL A, *AR2R E T n o p n o p Fig. 6.17: Imaginary part of B output of Butterfly Figure 6.18 depicts the part of the main program that invokes butterfly subroutine by supplying appropriate inputs, A and B to the subroutine. The associated butterfly structure is also shown for quick reference. Figures 6.19 and 6.20 depict the main program for the computation of 2nd and 3rd stage of butterfly. STM #X0R,AR1 STM #X1R,AR2 STM #W08R,AR3 CALL _butterfly STM #X2R,AR1 STM #X3R,AR2 STM #W08R,AR3 CALL _butterfly xn 0 xn 4 xn 2 xn 6 STM #X4R,AR1 STM #X5R,AR2 STM #W08R,AR3 CALL _butterfly STM #X6R,AR1 STM #X7R,AR2 STM #W08R,AR3 CALL _butterfly xn1 X0R 0 . 2 5 1 X1R X2R 0 . 2 5 2 X3R 1 / 4 X4R 3 xn5 xn3 xn7 X5R 1 / 4 X6R 4 Fig. 6.18: First stage of Signal Flow graph of DITFFT X7R x (0) x (4) X0 STM #X1R,AR1 X1 X1 STM #X3R,AR2 1/ 4 X2 X2 1/ 4 X4 1/ 4 X6 1/ 4 X0 1 /4 STM #W28R,AR3 x (2) x (6) x (1) x (5) x (3) x (7) STM x (0) STM x (4) x (2) STM x (6) W X3 2 X3 X5 STM #X4R,AR1 X7 1 / 4 X0 1 / 4 X2 #X6R,AR2 #W08R,AR3 X1 CALL _butterfly #X5R,AR1 X3 STM STM CALL _butterfly #X7R,AR2 x (1) x (5) x (3) x (7) 1 / 4 X4 1 / 4 X6 X4 1 /4 X5 X7 X5 #W28R,AR3 CALL _butterfly X6 W 2 X7 Fig. 6.19: Second stage of Signal Flow graph of DITFFT Fig. 6.20: Third stage of Signal Flow graph of DITFFT After the computation of X(k), spectrum is computed using the eq(6.8). The pointer AR1 is made to point to X(k). AR2 is made to point to location meant for spectrum. AR3 is loaded with keeps track of number of computation to be performed. The initialization of the pointer registers before invoking the spectrum subroutine is shown in fig. 6.21. The subroutine is shown in fig. 6.22. In the subroutine, square of real and imaginary parts are computed and they are added. The result is converted to Q15 notation and stored. S ( k ) = ( X ( k )) / N 2 0 ...point (6.8) for AR1 k = to N −1to X(k) = ( X ( k ) X ( k )) / N Make * STM #X0R,AR1 Make AR2 to point to spectrum location STM #S0,AR2 STM #07,AR3 CALL _spectrum Set a counter to 7 Invoke spectrum subroutine Fig. 6.21: Initialization for Spectrum Computation _spectrum: LD #0, A LD #0, B SQUR *AR1+,A SQUR *AR1+,B ADD B,A STH A,1,*AR2 LD *AR2,13,A STH A,*AR2+ BANZ _spectrum,*AR3RET nop nop Clear both accumulators Square re & im parts. Add them Convert product to 16 bit Q15 notation Divide by 8 & store Fig. 6.22: Subroutine for Spectrum Computation Problem 6.8: Suggest a method to determine the length of the DFT for a sequence that is not power of 2. Solution: Pseudo algorithm: Let M be the length of the given sequence • • • • A=log2(M) B=ceil (A); select next higher integer N=2^B Eg.:M=9, N=16 Problem 6.9: Write pseudo code to determine 8 point DFT using DITFFT algorithm invoking Butterfly subroutine in a nested loop for each stage. Solution: Stage 1 First butterfly inputs: 2nd butterfly inputs: 3rd butterfly inputs: 4th butterfly inputs: A X0R X2R X4R X6R B X1R X3R X5R X7R Observation: Difference in address to A input or B input =4 (each X(k) occupies two locations, Re & Im part) Pseudo algorithm: • • • • • Stage 1: AR1=address of X0R AR2=address of X1R AR3= address of W0R Repeat 4 times Compute 4 butterfly equations AR1=AR1+4 AR2=AR2+4 • End repeat Stage 2 First butterfly inputs: A X0R B X2R 2nd butterfly inputs: 3rd butterfly inputs: X1R X4R X3R X6R 4th butterfly inputs: X5R X7R Observation: difference in address to A input or B input =not constant. The difference in address to A input or B input of the alternative butterfly=8. Pseudo algorithm: Stage 2: • • • • AR1=address of X0R AR2=address of X2R AR3= address of W0R Repeat 2 times Compute 4 butterfly equations AR1=AR1+8 AR2=AR2+8 • • • • • End repeat AR1=address of X1R AR2=address of X3R AR3= address of W2R Repeat 2 times Compute 4 butterfly equations AR1=AR1+8 AR2=AR2+8 • End repeat Stage 3 A B First butterfly inputs: X0R X4R 2nd butterfly inputs: X1R 3rd butterfly inputs: X2R X6R 4th butterfly inputs: X3R X5R X7R Observation: difference in address to A input or B input =2 • • • • • • Pseudo algorithm: Stage 3: AR1=address of X0R AR2=address of X4R AR3= address of W0R repeat 4 times Compute 4 butterfly equations AR1=AR1+2 AR2=AR2+2 AR3=AR3+2 End repeat
© Copyright 2026 Paperzz