****************************************************************************

Cfft2_2191_Px.asm      Example 2191 complex radix-2 FFT Program

Analog Devices, Inc.
DSP Division
Three Technology Way
P.O. Box 9106
Norwood, MA 02062

23-JUNE-2001 BJM

This directory contains an example ADSP-2191 single-core subroutine 
that implements radix-2 FFT of length 64 or greater on input data x(n). A 
detailed discussion of the complex radix-2 FFT algorithm can be found in the 
source header comments of "CFFT2_2191.ASM".

Files contained in this directory:

CFFT2_2191.ASM      ADSP-2191 source for a complex radix-2 FFT example.
ADSP-2191.LDF    Linker description file for the CFFT2_2191.ASM example
CFFT2_2191.DPJ      The VisualDSP project file for the complex radix-2 FFT.
INPUTREAL.DAT       Real part of complex input data
INPUTIMAG.DAT       Imaginary part of complex input data
TWID_SIN.DAT        Sin array FFT twiddle factors
TWID_COS.DAT        Cos array FFT twiddle factors

  _________________________________________________________________

CONTENTS

I.    FUNCTION/ALGORITHM DESCRIPTION
II.   IMPLEMENTATION DESCRIPTION
III.  DESCRIPTION OF INPUT DATA 
        1.  Input Samples 
        2.  Twiddle factors  

_______________________________________________________________

I. FUNCTION/ALGORITHM DESCRIPTION

The program CFFT2_2191.ASM is an implementation of a complex input radix-2 DIT 
FFT. 

This radix-2 FFT routine will take data lengths that are any power of two (>= 64 
points).


II.   IMPLEMENTATION DESCRIPTION

This FFT implementation takes advantage of the architecture of the 
ADSP-2191.

The following table of variables and their location is presented, where "N" is 
the length of the FFT:

                          Input                             Output
Routine           DM                PM                DM                PM
-------------------------------------------------------------------------------
CFFT2_2191:   
		 inputreal[N]                        refft[N]        inputreal[N]
                                inputimag[N]
		 twid_imag[N/2]
                                twid_real[N/2]
--------------------------------------------------------------------------------



    inputreal[N]       Real part of normal-ordered complex input stored in DM
    inputimag[N]       Imaginary part of normal-ordered complex input stored in PM
    refft[N]           Real part of frequency domain data (fft output) stored in DM 
    twid_imag[N]       Sin table stored in DM
    twid_real[N]       Cos table stored in DM



III.  DESCRIPTION OF INPUT DATA

1. INPUT SAMPLES:
-----------------

This FFT routine expects input data which conforms to the following criteria:

Gather input data such that an array of complex fixed point values are 
arranged in the following order:

inputreal[N]:
	real(0)
	real(1)
	real(2)
	etc...

inputimag[N]:
	imag(0)
	imag(1)
	imag(2)
	etc...


2. TWIDDLE FACTOR DATA:
----------------------- 

This FFT routine expects N/2 fixed point values of one half period of a 
sine waveform and N/2 fixed point values of a one half period of a cosine 
waveform to be used as twiddle factors.  These twiddles should be in
a bit-reversed order.

Generate twiddle data such that an array of twiddle factor values are 
arranged in the following order:

	cos(0)
	cos(1)
	cos(2)
	...
	...
	...
	cos(N/2)

	sin(0)
	sin(1)
	sin(2)
	...
	...
	...
	sin(N/2)

Then, bit reverse these sin and cosine twiddle arrays.  This can be done by
writing a small bit reversal program which utilizes the bit reversed 
addressing mode of DAG1 of the ADSP-2191.

The bit reversed array of twiddle factor values are arranged in the following
order:

twid_real[N]:

	cos(0)
	cos(N/4)
	cos(N/8)
	...
	...
	...
	cos(N/2)

twid_imag[N]:

	sin(0
	sin(N/4)
	sin(N/8)
	...
	...
	...
	sin(N/2)



2191 - Complex Radix-2 FFT (Cfft2_2191.asm)

In order to perform FFTs of different lengths, the following code changes are 
necessary:
(The rules/relations described in the source code must be followed!)

 - Modify N to reflect the length of the FFT to be performed (N must be a power of 2)
 - Modify log2n such that STAGES = (log2(N))
 - Mofify Mod_Value such that Mod_Value = ( 2^(16-LOG2N) )
 - Modifiy Refft_Bitrev and Inputreal_Bitrev to represent the bit reversed
   address of the output real and imaginary buffers

Cfft2_2191.asm code excerpt shown below:

/**********The constants below must be changed for different length FFTs*******

N         		= number of points in the FFT, must be a power of 2
log2N     		= log2(N)
Mod_Value 		= 2^(16-LOG2N)
Refft_Bitrev 		= bitrev addr of output real in dm
Inputreal_Bitrev 	= bitrev addr of output imag in dm

******************************************************************************/

/* Set Constants for N-point FFT */
#define     N           		1024         
#define     Ndiv2	     		(N/2)       
#define     log2N       		10          
#define		Mod_Value			64		
#define		Refft_Bitrev		0x0001  
#define		Inputreal_Bitrev	0x0009 	


