 ## Aim

To perform the 8 point FFT using DIF process from a given discrete sequence in TMS320F2812 KIT.

☞CCS v3.3

☞USB Cable

## Theory

Fast Fourier transform (FFT) is an efficient algorithm to compute the discrete Fourier transform (DFT) and its inverse. There are many distinct FFT algorithms involving a wide range of mathematics, from simple complex number arithmetic to group theory and number theory.

DFT decomposes a sequence of values into components of different frequencies. This operation is useful in many fields (see discrete Fourier transform for properties and applications of the transform) but computing it directly from the definition is often too slow to be practical. An FFT is a way to compute the same result more quickly: computing a DFT of N points in the naive way, using the definition, takes O(N2) arithmetical operations, while an FFT can compute the same result in only O(N log N) operations. The difference in speed can be substantial, especially for long data sets where N may be in the thousands or millions—in practice, the computation time can be reduced by several orders of magnitude in such cases, and the improvement is roughly proportional to N / log(N). This huge improvement made many DFT based algorithms practical; FFTs are of great importance to a wide variety of applications, from digital signal processing and solving partial differential equations to algorithms for quick multiplication of large integers.

The most well known FFT algorithms depend upon the factorization of N, but there are FFTs with O(N log N) complexity for all N, even for prime N. Many FFT algorithms only depend on the fact that is an th primitive root of unity, and thus can be applied to analogous transforms over any finitue field, such as number theoretic transforms. Since the inverse DFT is the same as the DFT, but with the opposite sign in the exponent and a 1/N factor, any FFT algorithm can easily be adapted for it.

## Procedure for build a project on FFT 8 Point DIF Using TMS320F2812 DSP

Note: Once you install the Code Composer Studio v 3.3 software, the two icons will display in desktop

☞Setup Code Composer Studio v3.3

☞Code Composer Studio

1. Open Setup Code Composer Studio v3.3.

2. In System Configuration, select the board then → Remove all → yes.

☞In family, select C28xx.

☞In platform, select xds100 usb emulator.

☞In Endianness, select little.

☞Select F2812 XDS100 USB Emulator  add  save & quit  no.

Note: The above two steps only for first time to setup the processor in CCS.

3. Open Code Composer Studio v3.3.

4. Project → New.

☞ Project name : type the project name.

☞ Location : Browse, select the project location .

☞ Project Type : Executable(.out)

☞ Target : TMS320C28XX.  Finish.

5. File → New → Source file.

☞Type the program in untitled window.

6. File → Save.

☞Browse our project location then type our project name.c ( .c extension is must) → save.

7. Paste the following two cmd files in our project folder.

☞F2812_EzDSP_RAM_lnk.cmd

☞DSP281x_GlobalVariableDefs.c

8. Project → Add files to project.

☞ In file of type : All files

☞Ctrl + Select the following files     –  projectname.c     –  DSP281x_GlobalVariableDefs.c     –  F2812_EzDSP_RAM_lnk.cmd     –  DSP281x_Headers_nonBIOS.cmd  open.

9. Project → Build Option.

In compiler tab, select Preprocessor

☞Search path(-i) : C:\CCStudio_v3.3\C2000\cgtools\lib

☞ Incl libraries(-l) : rts2800_ml.lib.

☞Stack Size(-stack) : 0x400  ok.

10. Project → Build (or) Rebuild all.

11. Connections for TMS320F2812 KIT

☞Connect 5v adpter to TMS320F2812 KIT

☞Connect usb cable to TMS320F2812 KIT from pc.

☞Power on the TMS320F2812 KIT.

12. Debug → connect.

13. File → Load Program → Browse and select the projectname.out file → open

14. Debug → Go main.

15. View → memory

Enter An Address : 0x3F9200  Enter.

Type the input.

For example

```0x3F9200 – 0x0001
0x3F9201 – 0x0002
0x3F9202 – 0x0003
0x3F9203 – 0x0004
0x3F9204 – 0x0004
0x3F9205 – 0x0003
0x3F9206 – 0x0002
0x3F9207 – 0x0001
```

16. View → Watch window → watch1.

Type the following array variable.

☞tr( real part output)

☞ti( imaginary part output)

17. Debug → Run.

18. Debug → Halt

19. See the output at following location, View → memory

Enter An Address : 0x3F9210 → Enter.(real part output)

For example

```0x3F9210 – 0x0014
0x3F9111 – 0xFFFB (-5)
0x3F9112 – 0x0000
0x3F9113 – 0x0000
0x3F9210 – 0x0000
0x3F9210 – 0x0000
0x3F9210 – 0x0000
0x3F9210 – 0xFFFB (-5)
```

20. View → memory

Enter An Address: 0x3F9220 → Enter.(imaginary part output)

For example

```0x3F9220 – 0x0000
0x3F9121 – 0xFFFE (-2)
0x3F9122 – 0x0000
0x3F9123 – 0x0000
0x3F9220 – 0x0000
0x3F9220 – 0x0000
0x3F9220 – 0x0000
0x3F9220 – 0x0002
```

21. Or see the ouput at watch window.

Note: watch window will show exact decimal values, processor memory location will show a hexadecimal values.

## Program for FFT 8 Point DIF Using TMS320F2812 DSP

``````#include "DSP281x_Device.h"
#include
#define PI      3.14159
void InitSystem();
float x,tr,ti,s1r,s1i,s2r,s2i,Xr,Xi,Yr,Yi;
const float W0r = 1,
W0i = 0,
W1r = 0.707,
W1i = -0.707,
W2r = 0,
W2i = -1,
W3r = -0.707,
W3i = -0.707;
void main()
{
int *Input,*Real_out,*Imag_out;
int i=0;
Input = (int *)0x003F9200;
Real_out = (int *)0x003F9210;
Imag_out = (int *)0x003F9220;
InitSystem();
for(i=0;i<8;i++)
{
x[i] = 0;
x[i] = *(Input + i);
}
// stage one process
s1r = (int)(x + x);
s1i = 0;
s1r = (int)(x + x);
s1i = 0;
s1r = (int)(x + x);
s1i = 0;
s1r = (int)(x + x);
s1i = 0;
s1r = (int)(x - x) * W0r;
s1i = 0;
s1r = (int)(x - x) * W1r;
s1i = (int)(x - x) * W1i;
s1r = 0;
s1i = (int)(x - x) * W2i;
s1r = (int)(x - x) * W3r;
s1i = (int)(x - x) * W3i;
// stage two process
s2r = (s1r + s1r);
s2i = (s1i + s1i);
s2r = (s1r + s1r);
s2i = (s1i + s1i);
s2r = (s1r - s1r) * W0r;
s2i = 0; // (s1i - s1i) * W0i;
s2r = 0; // (s1r - s1r) * W2r;
s2i = (s1r - s1r) * W2i;
s2r = (s1r + s1r);
s2i = (s1i + s1i);
s2r = (s1r + s1r);
s2i = (s1i + s1i);
s2r = (s1r - s1r) * 1;
s2i = (s1i - s1i) * 1;
Yr = s1r - s1r;
Yi = s1i - s1i;
Yr = ((Yr * W2r) - (Yi * W2i));
Yi = ((Yr * W2i) + (Yi * W2r));
s2r = Yr;
s2i = Yi;
//  output
Xr = (s2r + s2r);
Xi = (s2i + s2i);
Xr = (s2r - s2r);
Xi = (s2i - s2i);
Xr = (s2r + s2r);
Xi = (s2i + s2i);
Xr = (s2r - s2r);
Xi = (s2i - s2i);
Xr = (s2r + s2r);
Xi = (s2i + s2i);
Xr = (s2r - s2r);
Xi = (s2i - s2i);
Xr = (s2r + s2r);
Xi = (s2i + s2i);
Xr = (s2r - s2r);
Xi = (s2i - s2i);
// bit reversal
tr = Xr;
ti = Xi;
tr = Xr;
ti = Xi;
tr = Xr;
ti = Xi;
tr = Xr;
ti = Xi;
tr = Xr;
ti = Xi;
tr = Xr;
ti = Xi;
tr = Xr;
ti = Xi;
tr = Xr;
ti = Xi;
// sending output array to memory location
for(i=0;i<8;i++)
{
*Real_out ++= tr[i];
*Imag_out ++= ti[i];
}

for(;;);
}

void InitSystem()
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;            // Setup the watchdog                                                                      //0x0068  to disable the Watchdog , Prescaler = 1                                                                    // 0x00AF  to NOT disable the Watchdog, Prescaler = 64
SysCtrlRegs.SCSR = 0;                  // Watchdog generates a RESET
SysCtrlRegs.PLLCR.bit.DIV = 10;        // Setup the Clock PLL to multiply by 5
SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to divide by 2
SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to divide by 4
// Peripheral clock enables set for the selected peripherals.
SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;