You are on page 1of 62

Cranes Software International Ltd

TI - Solutions

USER MANUAL TMS320C5416 DSK

Cranes Software International Ltd
No.5, Airport Road, Domlur Layout, Bangalore – 560 071
Phone : 080-5352636,5352637 Fax : 080-5356299 E mail – tisales@cranessoftware.com

1

Cranes Software International Ltd

TI - Solutions

CONTENTS

1. DSK FEATURES 2. INSTALLATION PROCEDURE 3. INTRODUCTON TO CODE COMPOSER STUDIO 4. EXPERIMENTS USING DSK

! DESIGN & CONDUCT SIMPLE IIR HIGH PASS FILTER ! DESIGN & CONDUCT SIMPLE IIR LOW PASS FILTER ! DESIGN & CONDUCT ADVANCE FIR LOW PASS FILTER ! DESIGN & CONDUCT ADVANCE FIR HIGH PASS FILTER ! DESIGN & CONDUCT SIMPLE FIR LOW PASS FILTER ! DESIGN & CONDUCT SIMPLE FIR HIGH PASS FILTER

2

Cranes Software International Ltd

TI - Solutions

Package Contents

Overview The 5416 DSP Starter Kit (DSK) is a low-cost platform, which lets enables customers to evaluate and develop applications for the TI C54X DSP family. The primary features of the DSK are: • • • • 160 MHz TMS320VC5416 DSP PCM3002 Stereo Codec Four Position User DIP Switch and Four User LEDs On-board Flash and SRA

3

16-bit interface Stereo. 16-bit interface 256Kwords.Solutions DSK Board Features Feature TMS320VC5416 DSP CPLD External SRAM External Flash PCM3002 Codec 4 User LEDs 4 User DIP Switches 4 Jumpers Daughter card Expansion Interface HPI Expansion Interface Embedded JTAG Emulator Details 160MHz. 128Kwords internal RAM Programmable "glue" logic 64Kwords. mic. fixed point. 6KHz –48KHz sample rate. line-in.Cranes Software International Ltd TI . line-out and speaker jacks Writable through CPLD Readable through CPLD Selects power-on configuration and boot modes Allows user to enhance functionality with addon daughter cards Allows high speed communication with another DSP Provides high speed JTAG debug through widely accepted USB host interface 4 . 16 or 20 bit samples.

Troubleshooting/Support: Solutions for problems you might encounter. Diagnostic Utility: Host based diagnostics. TMS320VC5416 KEY FEATURES • • • • • 128Kwords memory – high-speed internal memory for maximum performance. Timer – generates periodic timer events as a function of the processor clock.Solutions Key Features of the C5416 DSK • • • • • • • • C5416 DSK Tutorial:Quick overview of the DSK and its contents. Board Support Library: Functions that provide an easy interface to DSK hardware. Examples: Example code that runs on the DSK. On-chip PLL – generates processor clock rate from slower external clock reference. Each McBSP can be used for high-speed serial data transmission with external devices or reprogrammed as general purpose I/Os.Cranes Software International Ltd TI . The EMIF provides a 16-bit bus on which external memories and other devices can be connected. Datasheets: Datasheets related to the DSK. 3 McBSPs – Multichannel buffered serial ports. getting started with Code Composer. • 5 . DMA Controller – 6 channel direct memory access controller for high speed data transfers without intervention from the DSP. Schematics: Schematics for the DSK. It also includes internal wait state and bank switching controls. Used by DSP/BIOS to create time slices for multitasking. Hardware: Detailed descriptions of the C5416 DSK hardware components. EMIF – External memory interface.

Install the CCS software for C5416 DSK. speaker. or Signal generator/CRO these must be plugged in properly before you connect power to the DSK • • • • • Plug the power cable into the board Plug the other end of the power cable into a power outlet The user LEDs should flash several times to indicate board is operational When you connect your DSK through USB for the first time on a Windows loaded PC the new hardware found wizard will come up. So. Install the drivers (The CCS CD contains the require drivers for C5416 DSK). Troubleshooting DSK Connectivity If Code Composer Studio IDE fails to configure your port correctly.Solutions INSTALLATION DSK HARDWARE INSTALLATION • • • Shut down and power off the PC Connect the supplied USB port cable to the board Connect the other end of the cable to the USB port of PC Note: If you plan to install a Microphone.Cranes Software International Ltd TI . perform the following steps: • Test the USB port by running DSK Port test from the start menu Use Start"Programs"Texas Instruments"Code Composer Studio"Code Composer Studio C5416 DSK Tools"C5416 DSK Diagnostic Utilities • • • • • • The below Screen will appear Select" Start"Select 5416 DSK Diagnostic Utility Icon from Desktop The Screen Look like as below Select Start Option Utility Program will test the board After testing Diagnostic Status you will get PASS 6 .

Solutions If the board still fails to detect Go to CMOS setup" Enable the USB Port Option (The required Device drivers will load along with CCS Installation) 7 .Cranes Software International Ltd TI .

if not. 8 .exe • Choose the option to install Code Composer Sutido If you already have C6000 CC Studio IDE installed on your PC. do not install DSK software.Cranes Software International Ltd SOFTWARE INSTALLATION TI . CC Studio IDE full tools supports the DSK platform • Respond to the dialog boxes as the installation program runs. goes to the windows Explorer and run setup.0 Service Pack 4 or higher Windows® 2000 Service Pack 1 Windows® Me Windows® XP The Installation program automatically configures CC Studio IDE for operation with your DSK and creates a CCStudio IDE DSK icon on your desktop. follow these instructions: • Insert the installation CD into the CD-ROM drive An install screen appears.7 or later) Local CD-ROM drive • • • • • • Recommended 500MHz or Higher Pentium – Compatible CPU with USB Ports 128MB RAM 16bit Color • • Supported Operating Systems Windows® 98 Windows NT® 4. • • • • • • • Minimum 233MHz or Higher PentiumCompatible CPU with USB Ports 600MB of free hard disk space 64MB of RAM SVGA (800 x 600 ) display Internet Explorer (4.0 or later) or Netscape Navigator (4. To install.Solutions You must install the hardware before you install the software on your system. The System requirements for the Host Machine are.

injection/extraction of data signals via file I/O.Cranes Software International Ltd INTRODUCTION TO CODE COMPOSER STUDIO TI . automated testing and customization via a C-interpretive scripting language and much more. and graphical algorithm scope probes Advanced graphical signal analysis Interactive profiling Automated testing and customization via scripting Visual project management system Compile in the background while editing and debugging Multi-processor debugging Help on the target DSP 9 . profile and manage projects from a single unified environment.Solutions Code Composer is the DSP industry's first fully integrated development environment (IDE) with DSP-specific functionality. build. CODE COMPOSER FEATURES INCLUDE: • • • • • • • • • • • • Note : IDE Debug IDE Advanced watch windows Integrated editor File I/O. With a familiar environment liked MS-based C++TM. Other unique features include graphical signal analysis. Probe Points. Code Composer lets you edit. debug. multi-processor debugging.

To avoid the wait temporarily unplug the network cable for this part of the install process .Solutions Troubleshooting Problem CCS does not support target error recovery for RTDX/BIOS applications Solution To re-enable RTDX/BIOS following target error recovery you must exit CCS and restart CCS. 10 . For the link to work you must have Adobe’s acrobat reader installed. When you build your project you must wait until the build process is complete before attempting to load the code into the target. There is no internal safety check for this. Nothing happens when you click on a help file link to the schematics or datasheets When you halt a program Code Composer will sometimes display a dialog box saying that it cannot find a source code or library file Installation and Startup Problem When you connect your DSK through USB for the first time on a Windows XP PC the new hardware found wizard may not find the driver for about 15 minutes Solution The drivers are on the CD but Windows XP does some network accesses before it even checks the CD. any time your want to re-run a program you cannot simply hit run again. If the program stops in a system library like the runtime library.Cranes Software International Ltd TI . If you wait long enough the process will complete normally. RTDX/BIOS will be target error recovery compliant in a later version of CCS. Some firewall configurations can cause the network accesses to fail and Windows will wait for a timeout period before it checks the CD. You can either find the source code if you want to debug it or click on the checkbox to ignore messages like this. When you halt a program Code Composer attempts to display the source code associated with the current program counter. Documents like the schematics and datasheets are stored in Adobe PDF format. DSP/BIOS or the board support library it will not be able to find the source code for debug. Can’t load program right after building it. Select the restart option or re-load the program to start again from the beginning. in addition. Otherwise RTDX/BIOS data transmission to/from the host is disabled.

The 5416 DSK must be installed in Administrator mode but most users will run the program in user mode. The program cannot modify certain pieces of the registry because were marked as read-only in Administrator mode during the install. The Busy LED really quickly. Both Code Composer and the Diagnostic Utility run fine in Administrator mode but not in user mode The solution is to relax the user mode privilege restrictions. (DS201) above the USB connector illuminates when the DSK is powered on during this period. If you build a project in Administrator mode you will not be able to rebuild it in user mode because CCS will not be able to overwrite the temporary files.Cranes Software International Ltd TI .Solutions Problem I can’t verify that the driver install was successful. 2000 and XP there is a large distinction between the privileges of programs running in administrator mode vs. Please see the section at the bottom of this page entitled "Relaxing Administrator Mode Restrictions". The exact problem depends on your system configuration but stems from two general problems: 1. The program cannot write to or execute a file because it was created in Administrator mode and User mode programs usually have read-only access to files created by the Administrator. Relaxing Administrator Mode Privileges On Windows NT. The following is a list of things you can do to relax the Administrator mode privileges so the user program can get full access to Code Composer related resources: 11 . The exact access restriction depends on your system configuration and the operations performed so no one thing will fix all problems. There should be one Spectrum Digital TMS320C5416 DSK installed in the class What are the factory default jumper CLKMD1-Off settings for JP4? CLKMD2-On CLKMD3-On MP/MC-On Code Composer won’t launch if I power Windows needs time to recognize a USB cycle the DSK and try to start CCS device and get it initializaed. user mode. 2. Solution Go into your device manager and look for the "SD USB Based Debug Tools" hardware class. . Do not launch Code Composer until the led turns off.

The new settings will be applied to all files and subdirectories of the Code Composer install directory. Type regedt32 (not regedit) to bring up the Registry Editor. Select the Users group. From the Window menu. Select the Security tab to see the privileges associated with the folder. Log in as Administrator..Solutions 1. Click on the Users group (or any other group you would like to change privileges for) to see the group specific privileges. Click on the Full Control box and hit Apply.. With GODSP selected. choose Security Permissions. Select the Properties menu option. from the menu. select HKEY_LOCAL_MACHINE on the Local Machine. Expand the SOFTWARE key. In the upper half of the Permissions for GODSP window there will be a list of all the users and groups that access the key.Cranes Software International Ltd TI . In the Permissions box. • • • • • • Give users full access to all files in the Code Composer program tree. • • • • • • • • • • • Allow user mode access to Code Composer’s registry settings. Power users are automatically granted more privileges than a normal user. Repeat steps e through i for HKLM\Software\Texas Instruments. Log in as an Administrator. Right click on the directory name in the Folders pane on the left. Open Windows Explorer and find the location of your install (usually c:\ti). locate the item Full Control and check the corresponding box under Allow. 3. Locate and select the sub-key GODSP. 2. Choose Start à Run from the Windows 2000 Start menu. 12 . On Windows 2000 and XP allow users that will be using the Code Composer Studio product access via a "Power User" account. You will see a set of tabs that contain settings for that folder.

If you select the "OK" button while waiting enumeration the application will terminate and return control back to CCS which will probably fail and give the normal target error dialog. Waiting for USB Enumeration. The on-chip emulation controller may be in a bad state. The loader will maintain the message until the C5416 DSK re-enumerates On Windows 2000/XP the "Waiting for USB Enumeration" will generally be active for less then 10 seconds. Loader could not download the C5416 DSK emulation app to the DSK. Failed: USB device is NOT enumerated or plugged in. WinME. Only one application is allowed to talk to the C5416 DSK over the USB channel. Failed: USB channel in use by another app. Failed: Load Usb Application Problem Your Windows operating system does not support USB Windows cannot find the C5416 DSK in the list of enumerated USB devices. On Windows 98/ME the enumeration process may take as long as 40 seconds. Another application is using the C5416 DSK USB communication channel. This is a status message which indicates that the C5416 DSK emulation application has been loaded.Cranes Software International Ltd TI . DSK may not be powered or the USB cable may not be plugged in.Solutions Error Messages Error Message Failed: Requires Win98. 13 . Do NOT select the "OK" button unless you have let the specified time expire. Win2k or WinXP. You may have to check for active applications using Windows task manager if nothing seems apparent. Cycle power on the DSK.

l) in Type of files Project " Add files to Project "hello.lib(Path: c:\ ti\c5400\cgtools\lib\rts_ext. Eg: sum. out To Execute project: Debug " Run.out). Compile: To Compile: Project " Compile To Rebuild: Project " rebuild.*. To Add Source files to Project Project " Add files to Project " sum.cmd) Note: Select Linker Command file(*.c To Add rts.lib) Note: Select Object & Library in(*. 14 . Vectors.lib Library files: rts_ext.cmd CMD file – Which is common for all non real time programs. Procedure to Load and Run program: Load the program to DSK: File " Load program " Vectors.lib file & hello.out executable file.(Eg.c).Cranes Software International Ltd TI . (Path: c:\ti\tutorial\dsk5416\hello1\hello.Solutions Procedure to work on Code Composer Studio To create the New Project Project " New (File Name.o. Which will create the final .cmd) in Type of files To Enable –mf option: Project" Build Options " Advanced (in Category) " –Use Far Calls (.pjt) To Create a Source file File " New " Type the code (Save & give file name.cmd: Project " Add files to Project "rts_ext.mf) (C548 and higher). Eg: Vectors. pjt .

4. 5. 2. } To Perform Single Step Debugging: 1. 8. 6. i++.c # include<stdio. Execution should halt at break point. of your project. printf("%d". 15 . See the changes happening in the watch window. Debug " Run.Cranes Software International Ltd TI . Repeat steps 2 to 6.) To set break point select icon from tool bar menu. Similarly go to view & select CPU registers to view the changes happening in CPU registers. 3. Keep the cursor on the on to the line from where u want to start single step debugging. Go to view and select Watch window. out file onto the target.(eg: set a break point on to first line int i=0. 7.i). Now press F10. Load the Vectors.h> main() { int i=0.Solutions sum.

4} h[k] = {1. pad with zero’s to make multiples of 4 . 20. 3. 3. 4. 2. 10.Cranes Software International Ltd TI .Values of n & k should be a multiple of 4. If n & k are not multiples of 4. r= n= 0 1 2 3 . y[ ]= Convolution output. Size of output sequence. 0 1 2 x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3] x[1]h[0] x[1]h[1] x[1]h[2] x[2]h[0] x[2]h[1] x[3]h[0] 3 4 5 6 x[1]h[3] x[2]h[2] x[2]h[3] x[3]h[1] x[3]h[2] x[3]h[3] Output: y[r] = { 1. Algorithm to implement ‘C’ or Assembly program for Convolution: Eg: x[n] = {1. Multiplication 3. 24. Addition 4.Solutions LINEAR CONVOLUTION To Verify Linear Convolution: Linear Convolution Involves the following operations. of Impulse response co-efficient. r= n+k-1 = 4+4-1 = 7. Folding 2. 1. of Input samples h = No. 16}. 25. 2. Shifting These operations can be represented by a Mathematical Expression as follows: x[ ]= Input signal Samples h[ ]= Impulse response co-efficient. 4} Where: n=4. n = No. k=4. of zero’s 16 . NOTE: At the end of input sequences pad ‘n’ and ‘k’ no.

(Path: c:\ti\tutorial\dsk5416\hello1\hello.j. for(j=0. ! Load the program(lconv. /*Impulse Response Co-efficients*/ /*At the end of input sequences pad ‘M’ and ‘N’ no.i++) printf("%d\n".i<m+n-1.0}. int x[10]={1.i++) { y[i]=0. } PROCEDURE: ! Open Code Composer Studio.4. /*Input Signal Samples*/ int h[10]={1. save it in a separate directory(c:\ti\myprojects) with name lconv.lib (Path: c:\ti\c5400\cgtools\lib\rts_ext.0. /*Lenght of i/p samples sequence*/ int n=4. ! Add the linker command file hello. ! Add the source file lconv.0}.2.0. ! Build the program using the ‘Project-Build’ pull down menu or by clicking the shortcut icon on the left side of program window.c #include<stdio. /*Lenght of impulse response Co-efficients */ int i=0.i<m+n-1. of zero’s*/ int y[10].cmd .0.pjt.0.3.4.0. ! Start a new project using ‘Project-new ‘ pull down menu.3. for(i=0.Solutions ‘C’ PROGRAM TO IMPLEMENT LINEAR CONVOLUTION lconv.y[i]).lib) ! Enable –mf option ! Compile the program using the ‘Project-compile’ pull down menu or by clicking the shortcut icon on the left side of program window.j++) y[i]+=x[j]*h[i-j].h> main() { int m=4.Cranes Software International Ltd TI .2.0.j<=i. } for(i=0.cmd) ! Add the run time support library file rts6700. 17 . make sure the DSP kit is turned on.out) in program memory of DSP chip using the ‘File-load program’ pull down menu.c to the project using ‘Project"add files to project’ pull down menu.

4. 3.0. 4. 2.Cranes Software International Ltd ! To View output graphically Select view " graph " time and frequency.Solutions 18 .0.0} OUTPUT: TI .0.0. 3.0. 2.0} h[k] = {1. Configure the graphical window as shown below INPUT x[n] = {1.0.

1 Subfigure 3.1 Subfigure 1.Cranes Software International Ltd TI . clockwise by n steps) Figure 2: Step 2 Step 3: Pointwise multiply the f[m] wheel and the h[n−m] wheel. except all index calculations are done "mod N" = "on the wheel" Steps for Cyclic Convolution Step1: “Plot f[m] and h[−m] Subfigure 1.e. h[n]. sum=y[n] Step 4: Repeat for all 0≤n≤N−1 Example 1: Convolve (n = 4) Subfigure 3. 19 .2 Figure 3: Two discrete-time signals to be convolved.Solutions CIRCULAR CONVOLUTION Steps for Cyclic Convolution: Steps for cyclic convolution are the same as the usual convolution.2 Step 2: "Spin" h[−m] n times Anti Clock Wise (counter-clockwise) to get h[n-m] (i. Simply rotate the sequence.

Solutions • h[−m] = Figure 4 Multiply f[m] and sum to yield: y[0] =3 • h[1−m] Figure 5 Multiply f[m] and sum to yield: y[1] =5 • h[2−m] Figure 6 Multiply f[m] and sum to yield: y[2] =3 • h[3−m] Figure 7 Multiply f[m] and sum to yield: y[3] =1 20 .Cranes Software International Ltd TI .

0} y[4]={3. for(i=0.j++) scanf("%d".j++) x2[j]=a[j-1].j<n. 3. a[0]=h[0]. m=n. void main() { printf(" enter the length of the first sequence\n"). printf(" enter the length of the second sequence\n").i++) scanf("%d". 0} h[4]={1.h> int m.k.i++) y[0]+=x[i]*a[i]. 5. if(m-n!=0) /*If length of both sequences are not equal*/ { if(m>n) /* Pad the smaller sequence with zero*/ { for(i=n.i++) x[i]=0.y[30].i++) h[i]=0. n=m.k<n. } IN PUT: Eg: x[4]={3. for(j=1. printf(" enter the second sequence\n").i<n. y[k]+=x[i]*x2[i].i<n.Cranes Software International Ltd TI . for(j=0. } } /*displaying the result*/ printf(" the circular convolution is\n").y[i]).j<n.j<n.x2[30]. /*Circular convolution*/ for(i=0.Solutions Program to Implement Circular Convolution #include<stdio.&n). 1} OUT PUT 21 . for(i=0. } for(i=m.i<n.i<n.i++) { a[i]=x2[i].&m). 1. /*circular shift*/ for(j=1.k++) { y[k]=0.i++) printf("%d \t". scanf("%d". printf(" enter the first sequence\n"). 0. scanf("%d". } y[0]=0.a[30]. 2.i.i<m. x2[0]=a[n-1].j.x[30].i<m.h[30].&h[j]).&x[i]).temp[30].j++) /*folding h(n) to h(-n)*/ a[j]=h[n-j].n. for(k=1. 1. for(i=0.

Cranes Software International Ltd

TI - Solutions

TMS320C5416 DSP Multi Channel Buffered Serial Port [McBSP] Configuration Using Chip Support Library
1.0 Unit Objective: To configure the Multi Channel Buffered Serial Port for a talk through program using the chip support library. 2.0 Prerequisites TMS320C5416 DSP Starter Kit, PC with Code Composer Studio, CRO, Audio Source, Speakers and Signal Generator.

3.0 Discussion on Fundamentals:
Refer McBSP topic under TMS320C5416 DSP Module 4.0 Procedure • All the Real time implementations covered in the Implementations module follow McBSP Configuration using chip support library. • The Chip Support Library (CSL) is a collection of functions, macros, and symbols used to configure and control on-chip peripherals. • The goal is peripheral ease of use, shortened development time, portability, hardware abstraction, and some level of standardization and compatibility among TI devices. • CSL is a fully scalable component of DSP/BIOS. It does not require the use of other DSP/BIOS components to operate. Source Code: McBSP Steps: 1. Connect CRO to the Socket Provided for LINE OUT. 2. Connect a Signal Generator to the LINE IN Socket. 3. Switch on the Signal Generator with a sine wave of frequency 500 Hz. 4. Now Switch on the DSK and Bring Up Code Composer Studio on the PC. 5. Create a new project with name XXXX.pjt. 6. From the File Menu # new # DSP/BIOS Configuration # select “dsk5416.cdb” and save it as “YYYY.cdb” and add it to the current project. 7. Double click on the “YYYY.cdb” from the project explorer and double click on the “chip support library” explorer. 8. Double click on the “MCBSP” under the “chip support library” where you can see “MCBSP Configuration Manager” and “MCBSP Resource Manager”. 9. Right click on the “MCBSP Configuration Manager” and select “Insert mcbspCfg” where you can see “mcbspCfg0” appearing under “MCBSP Configuration Manager”. 10. Right click on “mcbspCfg0” and select properties where “mcbspCfg0 properties” window appears. 11. Under “General” property set “Breakpoint Emulation” to “Do Not Stop”. 12. Under “Transmit modes” property set “clock polarity” to “Falling Edge”. 22

Cranes Software International Ltd

TI - Solutions

13. Under “Transmit Lengths” property set “Word Length Phase1” to “32-bits” and set “Words/Frame phase1” to “2”. 14. Under “Receive modes” property set “clock polarity” to “Rising Edge”. 15. Under “Receive Multichannel” property set “Rx Channel Enable” to “All 128 Channels”. 16. Under “Transmit Multichannel” property set “Tx Channel Enable” to “All 128 Channels”. 17. Under the Receive Lengths property set “Word Length Phase1” to “32-bits” and set “Words/Frame phase1” to “2”. 18. Under the “Sample-Rate Gen” property set “Generator Clock Source” to “BCLKR pin”. Set “Frame Width” to “32” and “Frame period” to “64”. 19. Select “Apply” and click “O.K”. 20. Select “McBSP2” under the “MCBSP Resource Manager”. 21. Right click on “McBSP2” and select properties where a “McBSP2 Properties” Window appears. Enable the “Open handle to McBSP” option and “preinitialization” option. Select “msbspCfg0” under the “Pre-initialize” pop-up menu and change the “Specify Handle Name” property to “C54XX_DMA_MCBSP_hMcbsp”. Select “Apply” and click “O.K”. 22. Add the generated “YYYYcfg.cmd” file to the current project. 23. Add the given “mcbsp_io.c” file to the current project which has the main function and calls all the other necessary routines. 24. View the contents of the generated file “YYYYcfg_c.c” and copy the include header file ‘YYYYcfg.h’ to the “mcbsp_io.c” file. 25. Add the library file “dsk5416f.lib” from the location “C:\ti\C5400\dsk5416\lib\dsk5416f.lib” to the current project 26. Select project#build options#Compiler# Advance and enable the “use Far # # # calls” option. 27. Build, Load and Run the program. 28. You can notice the input signal of 500 Hz. appearing on the CRO verifying the McBSP configuration. 29. You can also pass an audio input and hear the output signal through the speakers. 30. You can also vary the sampling frequency using the DSK5416_PCM3002_setFreq Function in the “mcbsp_io.c” file and repeat the above steps. 5.0 Conclusion: The Multichannel Buffered Serial Port is successfully configured using the chip support library and verified.

23

Cranes Software International Ltd

TI - Solutions

Mcbsp_io.c:
#include "YYYYcfg.h" #include <dsk5416.h> #include <dsk5416_pcm3002.h> short left_input,right_input;

DSK5416_PCM3002_Config setup = { 0x1ff, 0x1ff, 0x0, 0x0 }; // Set-Up Reg 0 - Left channel DAC attenuation // Set-Up Reg 1 - Right channel DAC attenuation // Set-Up Reg 2 - Various ctl e.g. power-down modes // Set-Up Reg 3 - Codec data format control

void main () {

DSK5416_PCM3002_CodecHandle hCodec; // Initialize the board support library DSK5416_init(); // Start the codec hCodec = DSK5416_PCM3002_openCodec(0, &setup); // Set codec frequency DSK5416_PCM3002_setFreq(hCodec, 48000); // Endless loop IO audio codec while(1){ // Read 16 bits of codec data, loop to retry if data port is busy while(!DSK5416_PCM3002_read16(hCodec, &left_input)); while(!DSK5416_PCM3002_read16(hCodec, &right_input)); // Write 16 bits to the codec, loop to retry if data port is busy while(!DSK5416_PCM3002_write16(hCodec, left_input)); while(!DSK5416_PCM3002_write16(hCodec, right_input)); } }

24

Analog filter design concepts. BACKGROUND CONCEPTS: An Infinite impulse response (IIR) filter possesses an output response to an impulse which is of an infinite duration. IMPLEMENTATION OF DISCRETE-TIME SYSTEMS: Discrete time Linear Time-Invariant (LTI) systems can be described completely by constant coefficient linear difference equations.then its output must produced for infinite duration of time. TMS320C5416 Architecture and instruction set. In the filter design process. we would take help of some basic implementation methods for realizations of LTI systems described by linear constant coefficient difference equation. 25 . we determine the coefficients of a causal IIR filter that closely approximates the desired frequency response specifications. PREREQUISITES: ✷ ✷ ✷ Concept of Discrete time signal processing. Representing a system in terms of constant coefficient linear difference equation is it’s time domain characterization. that is if you put in an impulse . the desired filter characteristics are specified in the frequency domain in terms of the desired magnitude and phase response of the filter. In this experiment we design a simple IIR filter so as to stop or attenuate required band of frequencies components and pass the frequency components which are outside the required band. UNIT OBJECTIVE: The aim of this laboratory exercise is to design and implement a Digital IIR Filter & observe its frequency response.Solutions IIR filter Designing Experiments GENERAL CONSIDERATIONS: In the design of frequency – selective filters. The impulse response is "infinite" since there is feedback in the filter.Cranes Software International Ltd TI . In the design of a simple frequency–selective filter.

Perform filter operation using above said difference equation and store filter Output at a memory location .A direct form I implementation approach is taken. Step 3 . • • • 26 .Solutions EQUIPMENTS NEEDED: ✷ ✷ ✷ Host (PC) with windows(95/98/Me/XP/NT/2000). • • • Step 1 .These coefficients are calculated using MATLAB. ALGORITHM TO IMPLEMENT: We need to realize the Butter worth band pass IIR filter by implementing the difference equation y[n] = b0x[n] + b1x[n-1]+b2x[n-2]-a1y[n-1]-a2y[n-2] where b0 – b2.Cranes Software International Ltd TI . Step 5 . specify the initial conditions. a0-a2 are feed forward and feedback word coefficients respectively [Assume 2nd order of filter]. Oscilloscope and Function generator.Initialize the McBSP. TMS320C5416 DSP Starter Kit (DSK). take average of input data read from left and right channel .Take sampled data from codec while input is fed to DSP kit from the signal generator. “Kindly refer the Topic Configuration of 5416 McBSP using CSL” Step 2 . that is .Go to step 3. Step 6 .Initialize the discrete time system . the DSP board and the on board codec.Output the value to codec (left channel and right channel) and view the output at Oscilloscope. Store sampled data at a memory location. Step 4 . Since Codec is stereo . Generally zero initial conditions are assumed.

y[-2]=y[-1] and Y[-1] = output . x[-3] = x[-2].Cranes Software International Ltd TI . Do y[-3] = y[-2].y[-2]a2 x[-1]=x[0] Poll for ready bit Write ‘output’ to analog i/o.y[-1]a1 .Solutions FLOWCHART FOR IIR IMPLEMENTATION: Start Initialize the DSP Board. Set initial conditions of discrete time system by making x[0]-x[2] and y[0]-y[2] equal to zeros and a0-a2.b0-b2 with MATLAB filter coefficients Take a new input and store it in x[0]. x[-2]=x[-1] output = x[0]b0+x[-1]b1+ x[-2]b2 . Stop F. 27 .1 : Flowchart for implementing IIR filter.

%f}.%f.%f. fprintf(fid. fprintf(fid.\n%f.\n%f.%f.\n'. % cutoff frequency .%f}. fprintf(fid. fprintf(fid.%f.den_cb1]=cheby1(order.'\nfloat num_cb2[9]={').%f.%f. 28 . fprintf(fid.%f.\n'.24000 order = 2.'wt'). fprintf(fid. fprintf(fid. fprintf(fid. fprintf(fid.%f.\n%f. fid=fopen('IIR_LP_CHEB Type1.2500 [num_bw1. winopen('IIR_LP_BW.num_bw2).%f. fprintf(fid.%f.%f.den_cb2).\n%f.txt'.'\nfloat den_bw2[9]={').'%f.\n%f.%f.%f.\n%f.den_bw2]=butter(order.%f.%f.'wt').%f.Cranes Software International Ltd TI . fprintf(fid.'\nfloat den_bw1[9]={').'%f. fprintf(fid.%f.\n'. fprintf(fid. [num_cb1.cf(2)). % cutoff frequency .%f. fprintf(fid.num_bw1).%f.%f.den_bw1]=butter(order.'\n\n\n\t\t-----------Pass band range: 0-8000Hz----------\n').%f.Solutions MATLAB PROGRAM TO GENRATE FILTER CO-EFFICIENTS % IIR Low pass Butterworth and Chebyshev filters % sampling rate .'%f.\n%f.'\nfloat den_cb1[9]={').3.%f. fprintf(fid.cf(1)).\n'.%f.'\t\t-----------Magnitude response: Monotonic-----\n\n\').%f.%f.'%f.%f.%f.%f}.%f.%f.%f.%f.'\n\n\n\t\t-----------Pass band range: 8000Hz----------\n').%f}. fprintf(fid.%f.%f}.'%f.cf(1)).'%f.cf(2)).\n'.%f. fclose(fid).8000/12000.\n'. cf=[2500/12000. fprintf(fid. fprintf(fid.%f.\n'. fprintf(fid.%f.'\nfloat num_cb1[9]={').'\t\t-----------Magnitude response: Rippled (3dB)-----\n\n'). fprintf(fid. fprintf(fid.%f.%f.num_cb1). fprintf(fid.'\nfloat num_bw2[9]={').%f.'\t\t-----------Magnitude response: Rippled (3dB) -----\n\n\'). fprintf(fid.1600/12000].den_bw2).%f.%f.%f.den_bw1).den_cb1).'%f.'\nfloat den_cb2[9]={').'\t\t-----------Pass band range: 0-2500Hz----------\n').%f. [num_cb2.%f.%f.%f.8000 [num_bw2.num_cb2).%f.den_cb2]=cheby1(order. fid=fopen('IIR_LP_BW. fprintf(fid.'%f.'\t\t-----------Magnitude response: Monotonic-----\n\n').%f.txt').3.txt'.'\t\t-----------Pass band range: 2500Hz----------\n').%f}.%f}.%f.'\n float num_bw1[9]={').\n%f.\n'.%f}.

title('Magnitude response in the passband').'color'.000000 0.20*log10(abs(h)).005147 1. w=(w/max(w))*12000.'linewidth'. [h.'Chebyshev Type-1 (Ripple: 3dB)').2.den_cb1).709088 0. axis([0 12000 -20 20]).den_bw1).000000 -1. title('Magnitude response of Low pass IIR filters (Fc=2500Hz)').20*log10(abs(h)).044408 0.'linewidth'.'color'.20*log10(abs(h)).20*log10(abs(h)).w]=freqz(num_bw1. plot(w.2) hold on [h. ylabel('Magnitude in Decibels').354544 1. plot(w.412427 0.'r') grid on legend('Butterworth'. plot(w. plot(w.354544 0.010295 0. figure(2).w]=freqz(num_cb1.530009 0.844881 0. TI . xlabel('Frequency in Hertz'). w=(w/max(w))*12000. w=(w/max(w))*12000.den_cb2). ylabel('Magnitude in Decibels').873965 Fixed Point Values(Q15) 168 168[B1/2] 168 32767 -30225[A1/2] 28637 15 Fc=8000Hz Floating Point Values 0.'linewidth'. [h. 29 .'r') grid on legend('Butterworth'.473218 Fixed Point Values(Q15) 11617 11617[B1/2] 11617 32767 8683[A1/2] 15506 Note: We have Multiplied Floating Point Values with 32767(2 ) to get Fixed Point Values. w=(w/max(w))*12000.000000 -1.den_bw2).w]=freqz(num_bw2.005147 0. %%%%%%%%%%%%%%%%%% figure(1).'Chebyshev Type-1').txt').663336 Fixed Point Values(Q15) 1455 1455[B1/2] 1455 32767 -23140[A1/2] 21735 Fc=800Hz Floating Point Values 0.088815 0.Solutions IIR_CHEB_LP FILTER CO-EFFICIENTS: CoEffici ents B0 B1 B2 A0 A1 A2 Fc=2500Hz Floating Point Values 0.'linewidth'.Cranes Software International Ltd fclose(fid).w]=freqz(num_cb2.2) hold on [h.2. xlabel('Frequency in Hertz').044408 1. winopen('IIR_LP_CHEB Type1.

109229 0.398152 Fixed Point Values(Q15) 2366 2366[B1/2] 2366 32767 -18179[A1/2] 13046 Fc=800Hz Floating Point Values 0.398152 Fixed Point Values(Q15) 20539 -20539[B1/2] 20539 32767 -18173[A1/2] 13046 Fc=4000Hz Floating Point Values 0.388513 -0.009526 1.588691 Fixed Point Values(Q15) 3842 -3842[B1/2] 3842 32767 12360[A1/2] 19289 Note: We have Multiplied Floating Point Values with 32767(2 ) to get Fixed Point Values.705552.240408 Fixed Point Values(Q15) 15241 -15241[B1/2] 15241 32767 -10161[A1/2] 7877 15 Fc=7000Hz Floating Point Values 0. IIR_CHEB_HP FILTER CO-EFFICIENTS: CoEffici ents B0 B1 B2 A0 A1 A2 Fc=2500Hz Floating Point Values 0. 30 .560534 Fixed Point Values(Q15) 9268 -9268[B1/2] 9268 32767 -7395[A1/2] 18367 15 Fc=7000Hz Floating Point Values 0.000000 -1.451410 0.000000 0.Cranes Software International Ltd IIR_BUTTERWORTH_LP FILTER CO-EFFICIENTS: CoEffici ents B0 B1 B2 A0 A1 A2 TI .000000 -0.743655 Fixed Point Values(Q15) 312 312[B1/2] 312 32767 -27943[A1/2] 24367 15 Fc=8000Hz Floating Point Values 0.118450 0.Solutions Fc=2500Hz Floating Point Values 0.009526 0.000000 -1.282850 1.000000 -1.307566 0.019052 0. 0.626845 -1.000000 -1.388513 1.253691 0.072231 1.220195 1.645091 Fixed Point Values(Q15) 12730 -12730[B1/2] 12730 32767 -18324[A1/2] 21137 Fc=4000Hz Floating Point Values 0.626845 1.000000 -0.144462 0.188345 Fixed Point Values(Q15) 7215 -7215[B1/2] 7215 32767 5039[A1/2} 6171 Note: We have Multiplied Floating Point Values with 32767(2 ) to get Fixed Point Values.109229 0.282850 -0.777027 0. IIR_BUTTERWORTH_HP FILTER CO-EFFICIENTS: CoEffici ents B0 B1 B2 A0 A1 A2 Fc=2500Hz Floating Point Values 0.930306 0.000000 0.754476 0.117279 -0.620204 0.465153 1.220195 -0.620204 0.117279 1.072231 0.565700 0.234557 0.465153 1.000000 0.465153 0.930306 0.465153 -0.240408 Fixed Point Values(Q15) 15241 15241[B1/2] 15241 32767 10161[A1/2] 7877 Note: We have Multiplied Floating Point Values with 32767(2 ) to get Fixed Point Values.440389 0.

&setup).48.15803/*fc=7000 -HP */ //22586.-10161. power-down modes // Set-Up Reg 3 . left_output)).27695/*fc=1000*/ //11617.96.32767.Right channel DAC attenuation // Set-Up Reg 2 .15505/*fc=8000*/ //1455.32767.h" #include <dsk5416.259. left_input).11617. // Write 16 bits to the codec.h> Int16 left_input.21735/*fc=2500*/ //5058. void main () { DSK5416_PCM3002_CodecHandle hCodec. loop to retry if data port is busy while(!DSK5416_PCM3002_write16(hCodec. // Start the codec hCodec = DSK5416_PCM3002_openCodec(0. &left_input)). &right_input)).48.24000).20539.15241.5058.32767.h> #include <dsk5416_pcm3002.-22586.Various ctl e. // Endless loop IO audio codec while(1) { // Read 16 bits of codec data. 32767. right_output)).1455. } } // Set-Up Reg 0 .9995.32767.Solutions }. 29322 //96.Cranes Software International Ltd ‘C’ PROGRAM TO IMPLEMENT IIR FILTER #include "filtercfg.1455.Left channel DAC attenuation // Set-Up Reg 1 . // Set codec frequency DSK5416_PCM3002_setFreq(hCodec. /*Select particular set of co-efficients different Cut-off frequencies from given Tables */ DSK5416_PCM3002_Config setup = { 0x1ff. while(!DSK5416_PCM3002_write16(hCodec.29614 /*fc=600*/ //188.-20539.-5058. while(!DSK5416_PCM3002_read16(hCodec.188.7877 TI .g.-15241. -30949.-23140. // Initialize the board support library DSK5416_init().32767.32767.15649 //20539.32767.13046 //15241.Codec data format control 31 .-20964. 0x1ff. 0x0 }.96. Int16 right_output.-18173. left_output=IIR_FILTER(&filter_Coeff . 0x0. Int16 left_output.22586. Int16 right_input. const signed int filter_Coeff[ ] = { 48.32767.-29498.11617. right_output=left_output.-30918. loop to retry if data port is busy while(!DSK5416_PCM3002_read16(hCodec.8683.

/* x(n). Must be static */ static signed int y[6] = { 0. x(n-2). temp -= ( (long)h[4] * y[1]). 0. x[0] = (signed int) temp. 0.Solutions signed int IIR_FILTER(const signed int * h. temp -= ( (long)h[4] * y[1]). 0. y(n-2). temp = ( (long)h[0] * x[0]) . 0. } else if ( temp < -32767) { temp = -32767. /* y(n-1) = y(n) */ x[2] = x[1]. 0 }. /* x(n-2) = x(n-1) */ x[1] = x[0]. 0.Cranes Software International Ltd TI . temp += ( (long)h[2] * x[2]). y(n-1). temp = x1. temp -= ( (long)h[5] * y[2]). x(n-1). /* y(n-2) = y(n-1) */ y[1] = y[0]. if ( temp > 32767 ) { temp = 32767. 0. /* y(n). /* Divide temp by coefficients[A0] */ temp >>= 15. Must be static */ long temp=0. 0. 0. signed int x1) { static signed int x[6] = { 0. } y[0] = (short int) ( temp ). } /* Copy input to temp */ /* Copy input to x[stages][0] */ /* B0 * x(n) */ /* B1/2 * x(n-1) */ /* B1/2 * x(n-1) */ /* B2 * x(n-2) */ /* A1/2 * y(n-1) */ /* A1/2 * y(n-1) */ /* A2 * y(n-2) */ 32 . temp += ( (long)h[1] * x[1]). temp += ( (long)h[1] * x[1]). /* Shuffle values along one place for next time */ y[2] = y[1]. /* x(n-1) = x(n) */ /* temp is used as input next time through */ return ((short int)temp*1). 0 }.

33 . the DSP board and the on board codec.c source file from the project if you have already added). “Kindly refer the Topic Configuration of 5416 McBSP using CSL” ! Add the given above ‘C’ source file to the current project(remove mcbsp_io. ! Create a new project Project " New (File Name. ! Run the program using F5. ! Connect the speaker jack to the input of the CRO. ! Open the Code Composer Studio. Eg: Filter. pjt . ! Load the generated object file(*.pjt) ! Initialize the McBSP. ! Build the program. ! Observe the waveform that appears on the CRO screen.Cranes Software International Ltd TI .out) on to Target board.Solutions Procedure: ! Switch on the DSP board.

Solutions 34 .Cranes Software International Ltd TI .

In the design of a simple frequency–selective filter. In this experiment we design a simple FIR filter so as to pass required frequencies components (less than 1000 Hz) and stop or attenuate the frequency components which are outside the required band ( greater than 1824 Hz). then its output must produced for finite duration of time. Analog filter design concepts. IMPLEMENTATION OF DISCRETE-TIME SYSTEMS : Discrete time Linear Time-Invariant (LTI) systems can be described completely by constant coefficient linear difference equations. that is if you put in an impulse. we would take help of some basic implementation methods for realizations of LTI systems described by linear constant coefficient difference equation. 35 . The impulse response is "finite" since there is no feedback in the filter. the desired filter characteristics are specified in the frequency domain in terms of the desired magnitude and phase response of the filter. BACKGROUND CONCEPTS : A Finite impulse response (FIR) filter possess an output response to an impulse which is of infinite duration. TMS320C5416 Architecture and instruction set. PREREQUISITES : ✷ ✷ ✷ Concept of Discrete time signal processing. In the filter design process. we determine the coefficients of a causal FIR filter that closely approximates the desired frequency response specifications.Solutions FIR filter Designing Experiments GENERAL CONSIDERATIONS : In the design of frequency – selective filters. UNIT OBJECTIVE : The aim of this laboratory exercise is to design and implement Digital Kaiser low pass FIR Filter & observe its frequency response. Representing a system in terms of constant coefficient linear difference equation is it’s time domain characterization.Cranes Software International Ltd TI .

Step 5 . ALGORITHM TO IMPLEMENT : We need to realize the Kaiser high pass FIR filter by implementing the difference equation y[n] = b0x[n] + b1x[n-1])+b2x[n-2]…b2x[n-25] where b0 – b25 are feed forward coefficients [Assume 25thorder of filter] . These coefficients are calculated using MATLAB. A direct form I implementation approach is taken. “Kindly refer the Topic Configuration of 5416 McBSP using CSL” Step 2 . Step 6 .Take sampled data from codec while input is fed to DSP kit from the signal generator.Cranes Software International Ltd EQUIPMENTS NEEDED : ✷ ✷ ✷ TI .Perform filter operation using above said difference equation and store filter Output at a memory location .Solutions Host (PC) with windows(95/98/Me/XP/NT/2000). Step 4 . take average of input data read from left and right channel .Go to step 3. Since Codec is stereo . specify the initial conditions. • • • Step 1 . Oscilloscope and Function generator. • • • 36 . Store sampled data at a memory location.Initialize the McBSP. DSP kit with TMS 320C5416 chip and driver software. Step 3 . that is . the DSP board and the on board codec.Output the value to codec (left channel and right channel) and view the output at Oscilloscope.Initialize the discrete time system . Generally zero initial conditions are assumed.

USING MATLAB TO DETERMINE FILTER COEFFICIENTS : Using FIR1 Function on Matlab B = FIR1(N.kaiser(N+1. Hanning. ..0..'DC-0') makes the first band a stopband. Wn = [W1 W2 W3 W4 W5 . 'high'. 37 . WN]. I. B = FIR1(N. W1 < W < W2. highpass and bandstop filters.N+1. Other available windows. B = FIR1(N.Wn..Wn. III. By default FIR1 uses a Hamming window. B = FIR1(N. IV. For filters with a passband near Fs/2. The cut-off frequency Wn must be between 0 < Wn < 1.boxcar(31))..Wn. The filter B is real and has linear phase. If Wn is a multi-element vector. even symmetric coefficients obeying B(k) = B(N+2-k). Wc . Kaiser and Chebwin can be specified with an optional trailing argument.1*pie Compute the desired Impulse Response h d (n) using particular Window Eg: b_rect1=fir1(order. Bartlett.'stop') is a bandstop filter if Wn = [W1 W2]. including Boxcar.g. B = FIR1(N. Convolve input sequence with truncated Impulse Response x (n)*h (n) II.. B = FIR1(N. e. If Wn is a two-element vector. For example.Wn) designs an N'th order lowpass FIR digital filter and returns the filter coefficients in length N+1 vector B.Wn.4)) uses a Kaiser window with beta=4. Blackman.'DC-1') makes the first band a passband.Cranes Software International Ltd DESIGNING AN FIR FILTER : TI . with 1. FIR1 returns an order N multiband filter with bands 0 < W < W1. Wn = [W1 W2]..0 corresponding to half the sample rate. Compute the cut-off frequency W c Eg: Wc = 2*pie* fc / Fs = 2*pie* 400/8000 = 0.2. k = 1.Solutions Following are the steps to design linear phase FIR filters Using Windowing Method.e. Eg: Order = 30..Wn. Sampling Rate = 8000 samples/sec Cut off Freq.. = 400 Hz. i.. N must be even. FIR1 returns an order N bandpass filter with passband W1 < W < W2.'high') designs a highpass filter.. WN < W < 1. Clearly specify the filter specifications..

cf--> contains set of cut-off frequencies[Wc ] % cutoff frequency .500 b_rect1=fir1(order.'noscale').'Cutoff -800Hz'). triangular and kaiser windows % sampling rate .1000 b_rect2=fir1(order.kaiser(31.txt'. fprintf(fid.'noscale'). fprintf(fid. Matlab Program to generate ‘FIR Filter-Low Pass’ Coefficients using FIR1 % FIR Low pass filters using rectangular.-1.%f. % cutoff frequency . e.Wn.1500 b_rect3=fir1(order. 38 .\n'.%f.\n'.bartlett(31)).%f.boxcar(31)).Wn. the filter is scaled so the center of the first pass band has magnitude exactly one after windowing.8)).boxcar(31)).cf(3).%f. fprintf(fid.').Wn.cf(2).%f. B = FIR1(N.'}.%f.Solutions B = FIR1(N.8000 order = 30.%f. Kaisar [Where 8-->Beta Co-efficient] % cutoff frequency .%f.').%f.R)) uses a Chebyshev window.'high'.cf(3).'\t\t\t\t\t\t%s\n'.bartlett(31)).%f.Wn.%f. fprintf(fid.'\n\n\n\n'). B = FIR1(N.bartlett(31)).1500/4000].-1.b_rect2).'\nfloat b_rect1[31]={').'%f. fseek(fid.%f.%f.kaiser(31. fid=fopen('FIR_lowpass_rectangular. fprintf(fid.cf(1). cf=[500/4000. fprintf(fid.1000/4000. fprintf(fid. b_tri2=fir1(order.%f.8)).'wt').0).'Cutoff -400Hz').%f.Cranes Software International Ltd TI .kaiser(31. fprintf(fid.'\t\t\t\t\t\t%s\n'. fseek(fid. Triangular b_kai1=fir1(order. Use a trailing 'noscale' argument to prevent this scaling. By default.cf(1).cf(2). fprintf(fid.'\nfloat b_rect2[31]={').%f.cf(3). B = FIR1(N.'}. b_kai3=fir1(order.'%f.%f.0). b_kai2=fir1(order.'high'.boxcar(31)).'noscale'). b_tri3=fir1(order.b_rect1).8)). Rectangular b_tri1=fir1(order.cf(1).g.wind.cf(2).%f.chebwin(N+1.

%f.000000.138255.0.386435.034909.0.0.0.0.043293.-0.029339.0. -0.%f.0.-0.029339.%f. 0.-0.0.027335. 39 .0.041491.0.062306.-0.0.015895. fprintf(fid.0.0.033416.%f.%f.0.0.003511.0.007551.-0.001046.020203.221349.000000.018176.039383.0.025020.011411.-0.014970. -0.000609. 0.0.-0.060710.0.-0.021481.000000. Cutoff -1000Hz float b_rect2[31]={-0.028462.003150.-0.-0.0.000000.-0.2 :Matlab generated Coefficients for FIR Low Pass Rectangular filter Cutoff -500Hz float b_rect1[31]={-0.017782.0.124473.0.000609.047257.-0.000000.001414.055693. 0. -0.000000. -0.0.001451. -0.-0. fprintf(fid.041491.078762.0.064504.007410.0.017782.000234.029370.088016.020655.0.001414.167080.020126.-0. 0.0.-0.-0. -0.0.000246.062306.-1.003421.0. fprintf(fid.-0.0.0.-0.-0.-0.0.026254.128279.0.115971.029569.0.0.001046.000000.-0.-0.-0.000000.0.-0.0.0.-0.027335.0.026254.374978.0.%f.000046.0.236286.0.0.0.000454.0.000000.0.000000.-0.148863.134729.0.000000. 0.000166.').-0.004838.'}.078762.047257. winopen('FIR_highpass_rectangular.033672.-0.065053.033755.016567.0.0.-0.0.024895.-0.-0.000000. fclose(fid).028462.134729.Solutions fprintf(fid.023869.0.0.001933. T.064504.009656.017764.-0.-0.086494.008982.0.019247.000246.0.0.0.0.000000.025020.000166.289209.000234.000046}.023194.-0.009656.000000.039383.-0.029569.043293.000000.034909.108421.0.025105.0.018176.0.0.-0.148863.002593.020126.001451.023194.015752.0. 0.000170.013596.-0.013596.005671.-0.082004.221349.0).0.-0. -0.-0.-0.-0.029370.115971.0.0.105263.'%f.021481.0.108031.024895.005671. fseek(fid.122944.-0.0. 0.000035}.004838.0.'\t\t\t\t\t\t%s\n'.000000.007551.0.0.0.-0.-0.0.0.0.033672.b_rect3). 0.124473.041842.003421.000000.0.086494.303048.%f.0. 0.0. fprintf(fid.0.003511.0.-0.000454. Cutoff -1500Hz float b_kai3[31]={-0. Cutoff -1500Hz float b_rect2[31]={-0.-0.0. -0.038657.016567.108031.003150.0.023869.Cranes Software International Ltd TI .-0.000170.000000.000000.262448.007410.-0.249983.-0.-0.%f.105263.055693.-0.'Cutoff -1200Hz').-0.000019}.-0.-0.014970.0.001933.'\n\n\n\n').060710.025105.txt').015752}.033755.0.000019. Cutoff -1000Hz float b_kai2[31]={-0.-0.\n'.041842.-0.002593.0.108421.0.017764.065053.0.236286.167080.082004.-0.0.020655.-0.0.289209.0.033416.0.-0.-0.011411.0.008982}.-0.038657.-0.303048.0.0.088016.-0. 0.1 : Matlab generated Coefficients for FIR Low Pass Kaiser filter: Cutoff -500Hz float b_kai1[31]={-0.%f.000035.-0.019247.122944.000000. T.-0.-0.-0.015895.020203}.0.'\nfloat b_rect3[31]={').

005868. b_kai3=fir1(order.'high'.000000.220534.-0. .002423.005467.000000.007731.005988.107877.001185. % cutoff frequency .boxcar(31)).023194.-0.000000.-0.001287.0.400 b_rect1=fir1(order.0.0.003043.'high'. b_kai2=fir1(order.0.000000. cf=[400/4000.008298.cf(2).cf(3).0.cf(2).0.0.001104.003336.-0.107877.033474.8000 order = 30.0.cf(1).0.-0.-0. 40 .060136. b_tri2=fir1(order.0.000000.'high'.0.bartlett(31)).cf(1).0. b_tri3=fir1(order.'high'.-0.001287.001591.bartlett(31)).043368.100508.-0.0. b_kai1=fir1(order.-0.'high'.0.003336.'high'. 0.007885.0.005728.043368.-0.0.kaiser(31.8)).282844.000000.-0. Where Kaiser(31.800 b_rect2=fir1(order.-0.-0.-0.0. MATLAB Program to generate ‘FIR Filter-High Pass’ Coefficients using FIR1 % FIR High pass filters using rectangular.010502.0.-0. Cutoff -1000Hz float b_tri2[31]={0.0.-0.144802.cf(1).018003.010502.007731.0. 0.bartlett(31)). % cutoff frequency .cf(3).0.-0. -0.063010.000000}.024895.386435.063010.0.000000}.033416.0.-0.0. 0.0.-0.001591.cf--> contains set of cut-off frequencies[Wc] % cutoff frequency .013469.002423.011139.024895.-0.0.0.008298.0.125747.cf(3).-0.023089.262448.-0.0.220534.kaiser(31.000000.144802.001104.010265.-0.0.0. 0.016737.-0.boxcar(31)).0.8)).cf(2).1200 b_rect3=fir1(order. b_tri1=fir1(order.Solutions T.033474.000000.800/4000.013469.3 : Matlab generated Coefficients for FIR Low Pass Triangular filter Cutoff -500Hz float b_tri1[31]={0.031505.0.000000.0.100508.125747.023089.0.000000.086737. 0.0.Cranes Software International Ltd TI .005467.-0.1200/4000].0.-0.003043.064545.0.-0.007885.0.-0.-0. Cutoff -1500Hz float b_tri3[31]={0.033416.023194.010265.0.0.011139.0.282844. -0.086737.064545.005868.kaiser(31.'high'.005728.-0.005988.0.0.018003.0.138255.'high'.-0.8)--> '8'defines the value of 'beta'. 0.001185.016737.boxcar(31)).000000.8)). -0. triangular and kaiser windows % sampling rate .0.-0.000000.0.060136.000000}.'high'.0.000000.031505.-0.

-0.001345.%f.000611.0.015556.086763.%f.-0.txt').-0.'%f.018287.000000.000050.0.%f.%f.0.b_rect2).035687.'}.012033.087505.000198.').0.%f.%f.%f.0.%f.-0.Solutions fid=fopen('FIR_highpass_rectangular.000000. fprintf(fid.001607.'%f.-0.0.0.%f.0.-0.253270.000831.'\nfloat b_rect1[31]={').096739.'}.000223.%f.016731. fseek(fid.899998. fprintf(fid.073805.0.0).-0.%f. fprintf(fid.-0.-0.%f.-0.0.0.001345.%f.016731. fprintf(fid.-0.007437.'\t\t\t\t\t\t%s\n'.0.%f.0.%f. fseek(fid. -0.'Cutoff -800Hz').-0. -0.-0. fprintf(fid.-0.035687.-0.%f.-0.001345.-0.0.'Cutoff -400Hz').001345.'wt').\n'.002478.015556.-0.000831.-0.000000.012033. fprintf(fid.-0.0. -0.\n'.000138.-0.0.0.005942. 0.'\nfloat b_rect3[31]={').-0.000520.-0.0).006489.016731.0.000138.%f.000138.000000.-0.253270.-0.b_rect3).800005.-0. fprintf(fid.000223.%f.%f. • Cutoff -1200Hz • float b_kai3[31]={-0.-0. fseek(fid.-1. fclose(fid).-0. fprintf(fid.012033.000000}.002212.-0.-0.-0.028191.041539.035687.'\n\n\n\n').041538.1 : MATLAB generated Coefficients for FIR High Pass Kaiser filter: Cutoff -400Hz float b_kai1[31]={0.000000.000000.004714. Cutoff -800Hz float b_kai2[31]={0.000000. -0.000845.0. -0.Cranes Software International Ltd TI .035687. 41 .057742.141589.-0.%f.0.141588.012033.-0.%f.018287. fprintf(fid.'%f.141588. -0.-0.-0.0).0.001607.b_rect1).016731.0.086763.000845.000000.0.'\n\n\n\n').000520.-0.%f.0.002212.\n'.057742.027071.087505.-0. fprintf(fid.000050.-0.002478.%f. fprintf(fid.000050}.'}.0.007437.141589.0.184011.184011.'Cutoff -1200Hz').041539. -0.').027071.-0.000611.%f.041538.'\t\t\t\t\t\t%s\n'. fprintf(fid.005942. 0.0.0.txt'.0.006489. fprintf(fid. fprintf(fid.-1.000000.000050}.%f. T.').-0.028191.073805.0.0.-0.004714.%f.-0.000198.-0.000138.-0. winopen('FIR_highpass_rectangular.700008.-0.'\t\t\t\t\t\t%s\n'.-1.0.-0.-0.'\nfloat b_rect2[31]={').-0.096739.0.%f.

022944.-0.-0. -0.055647.-0.0.034707.002648.0.-0.Solutions T.101609.005080. Cutoff -1200Hz float b_tri3[31]={0.-0.0.175834.0.0.005105.017782.-0.011581.068853.-0.000000.0.000000.006317.-0.0.188394.0.-0.000000.0.686050.030562.0.017782.-0.077266.032134.0.003127.013772.152414.-0.-0. -0.042554.064994.0. -0.132092.068853. -0.000000.000901.-0.805541.0.064994.-0.000000.-0.002391.0.132736.-0.047098.043547.003126.025402.-0.243196.023225.-0.031399.023877.-0.132736.0.-0.243196.019672.000000}. Cutoff -800Hz float b_rect2[31]={0.-0.020798}.-0.087636.-0.017127.0.-0.-0.000000.-0.000000.-0.-0.042944.252386.0.0.-0.0.000000.-0.0.0.148349.-0.013457.-0.013772.0.019672.000897.-0.045842.-0.000000}.024725.0.007583.0.004567.034539.-0.030562.017868.0.0. -0.-0.-0.0.077266.0.100422.007583.-0.-0.0.-0.005105.0. 0.-0.-0.0.000000.000000.043547.0.018931.051511.-0.034539.252386. 0.0.010943.020224.-0.0.037558.-0.003127. 0.0.-0.013098.026541.-0.0.095507.Cranes Software International Ltd TI .022076.-0.023877.-0.0.000000.021665.132092.-0.0.708287.010943.013098.0.000000}.015918.020798.188394.-0.0.0.-0.024725.-0.092048.-0. -0.087636.011158.0.009129.-0.030353. -0.-0.0.023225.000897.011581.-0.101609.-0.000000.-0.062393.100422.051511.028043.-0.-0.-0.0. 42 .034707.0.037087.032134. Cutoff -1200Hz float b_rect3[31]={-0.026541. -0.000000.025402.-0.-0.0.0.0. T.175834.0.001445.000000.0.030353.001021.017127.2 :MATLAB generated Coefficients for FIR High Pass Rectangular filter Cutoff -400Hz float b_rect1[31]={0.004383.062393.-0.-0.042554.-0.055647.-0.-0.020224.-0.007416.045842.-0.-0.148349.805541.081287.007416.-0.020933.004567.-0.037087.021665}.-0.-0.918834.003126.0.000000.0.023448.0.-.0. -0.-0.3 : MATLAB generated Coefficients for FIR High Pass Triangular filter Cutoff -400Hz float b_tri1[31]={0.038103.0.-0.018839. -0.000000.004383.037558.-0.022076.0.018839.002648.047098.006317.017868.000000.022944.000000.081287.028043.-0.095507.081290.0.-0.902380.-0.0.000901.0.0.-0.-0.-0.-0. Cutoff -800Hz float b_tri2[31]={0.0.009129.001445.0.038103.-0.020933.0.0.-0.015918.000000.152414.081290.092048.023448.013457.042944.031399. -0.008373.-0.008373.011158. -0. -0.002391.-0. -0.000000}.-0.0. -0.000000.0.-0.0.001021.-0.0.005080.018931.

x[-1]=x[0] Poll the ready bit.Cranes Software International Ltd TI . Set initial conditions of discrete time system by making x[0]x[25] equal to zeros and b0-b25 with matlab filter coefficients Take a new input and store it in x[0]. when asserted proceed. Do x[-25]=x[-24]……….1 : Flowchart for implementing FIR filter. +x[-25]b25 Write ‘output’ to analog i/o. output = x[0]b0+x[-1]b1+x[-2]b2+…. x[-2]=x[-1]. 43 . Stop F.Solutions FLOWCHART FOR FIR IMPLEMENTATION : Start Initialize the DSP Board.

0. // Set codec frequency DSK5416_PCM3002_setFreq(hCodec.h" #include <dsk5416. float filter_Coeff[] ={-0. 0x0 }.0. loop to retry if data port is busy while(!DSK5416_PCM3002_read16(hCodec.016731.028191. left_output=FIR_FILTER(&filter_Coeff .g.-0.000138. 0.000198.0.002212.000138.-0.-0.253270.141589.-0. power-down modes // Set-Up Reg 3 .000000. -0. loop to retry if data port is busy while(!DSK5416_PCM3002_write16(hCodec.h> Int16 left_input.-0. // Start the codec hCodec = DSK5416_PCM3002_openCodec(0.0.700008. 0.-0. Int16 left_output.141589. &left_input)).Various ctl e.005942. Int16 right_input.0. static short in_buffer[100]. &setup).Left channel DAC attenuation // Set-Up Reg 1 .041539.-0.001345.h> #include <dsk5416_pcm3002.Cranes Software International Ltd TI .Solutions ‘C’ Program to implement FIR filter: #include "filtercfg.253270.0.041539. while(!DSK5416_PCM3002_write16(hCodec.Codec data format control void main () { DSK5416_PCM3002_CodecHandle hCodec.0.035687.-0.0.0. /*Select particular set of co-efficients different Cut-off frequencies from above given Tables */ DSK5416_PCM3002_Config setup = { 0x1ff.006489. right_output)).-0. left_output)).-0.0.0.left_input).000050}. while(!DSK5416_PCM3002_read16(hCodec. // Initialize the board support library DSK5416_init().Right channel DAC attenuation // Set-Up Reg 2 .-0. 0x0. // Endless loop IO audio codec while(1) { // Read 16 bits of codec data.035687.002212.012033.012033.000050.000198.005942.-0. // Set-Up Reg 0 .028191.-0.006489. right_output=left_output. } } 44 .001345.0.000000. // Write 16 bits to the codec.8000).016731. &right_input)). 0x1ff. Int16 right_output.-0.-0.

! Load the generated object file(*. pjt . /* shuffle the buffer */ for(i=0. ! Open the Code Composer Studio.Solutions Procedure: ! Switch on the DSP board.i>0. the DSP board and the on board codec.Cranes Software International Ltd signed int FIR_FILTER(float * h.i++) output = output + h[i] * in_buffer[i]. ! Create a new project Project " New (File Name.c source file from the project if you have already added). signed long output=0.out) on to Target board. ! Connect the speaker jack to the input of the CRO. signed int x) { int i=0.pjt) ! Initialize the McBSP. ! Build the program. /* new input at buffer[0] */ for(i=31. ! Observe the waveform that appears on the CRO screen.i<32. ! Run the program using F5. “Kindly refer the Topic Configuration of 5416 McBSP using CSL” ! Add the above given ‘C’ source file to the current project (remove mcbsp_io. in_buffer[0] = x. } TI . 45 . return(output).i--) in_buffer[i] = in_buffer[i-1]. Eg: Filter.

Low Pass FIR filter (Fc=1000Hz) 46 .Cranes Software International Ltd TI .Solutions MATLAB GENERATED FREQUENCY RESPONSE High Pass FIR filter(Fc= 800Hz).

That the vectors are symmetric 3. it goes round and round the circle !!) 2. Note that 1.e. there is a factor called the Twiddle Factor where N = number of samples.g. It is periodic. (i. Even a simple eight sample signal would require 49 complex 47 . Why the FFT? If you look at the equation for the Discrete Fourier Transform you will see that it is quite complicated to work out as it involves many additions and multiplications involving complex numbers.Cranes Software International Ltd TI . e. The vectors are equally spaced around the circle. If we take an 8 bit sample sequence we can represent the twiddle factor as a vector in the unit circle.Solutions Fast Fourier Transforms(FFT) The DFT Equation Twiddle Factor In the Definition of the DFT.

See "Shuffled Inputs" 4. The DFT requires (N-1)^2 complex multiplications and N(N-1) complex additions as opposed to the FFT's approach of breaking it down into a series of 2 point samples which only require 1 multiplication and 2 additions and the recombination of the points which is minimal. Compute (N / 2) eight sample DFT's from the four sample DFT's. to break up the original N point sample into two (N / 2) sequences. however a realistic signal could have 1024 samples which requires over 20. of N samples. and it is shown step by step in the list below. Therefore we use the FFT. e. e. Bit reverse the input sequence. The idea behind the FFT is the divide and conquer approach. The Fast Fourier Transform is a simply a method of laying out the computation. For example Seismic Data contains hundreds of thousands of samples and would take months to evaluate the DFT. See "Shuffled Inputs" 48 . Compute (N / 2) two sample DFT's from the shuffled inputs. 500 samples are padded to 512 (2^9) 2. See "Shuffled Inputs" 5. 3 = 011 goes to 110 = 6 3.Solutions multiplications and 56 complex additions to work out the DFT.000 complex multiplications and additions. which is much faster for large values of N. As you can see the number of calculations required soon mounts up to unmanageable proportions. It is an ingenious way of achieving rather than the DFT's clumsy P^2 timing.Cranes Software International Ltd TI . with ZERO's until the number of samples is the nearest power of two. Compute (N / 4) four sample DFT's from the two sample DFT's. Pad input sequence. This is because a series of smaller problems is easier to solve than one large one.g. FFT Algorithm The FFT has a fairly easy algorithm to implement. At this level it is still manageable. where N is the number of samples in the sequence. Thjis version of the FFT is the Decimation in Time Method 1.g.000.

6. 4. 1. 7 But after decimation the order is 0. 1.Cranes Software International Ltd 6. 3. 5. 49 . 6. 5. 7 At first it may look as if there is no order to this new sequence.Solutions Shuffled Inputs The process of decimating the signal in the time domain has caused the INPUT samples to be re-ordered. 4. BUT if the numbers are represented as binary a patter soon becomes apparent. 2. 3. Until the all the samples combine into one N-sample DFT TI . For an 8 point signal the original order of the samples is 0. 2.

of points for FFT(Eg: 64) Step 2 – Generate a sine wave of frequency ‘f ‘ (eg: 10 Hz with a sampling rate = No.Solutions What has happened is that the bit patterns representing the sample number has been reversed. of Points of FFT(eg. Step 4 – Use Graph option to view the Input & Output. 50 . of points & frequencies.Repeat Step-1 to 4 for different no. ALGORITHM TO IMPLEMENT FFT: • • • • • Step 1 .Cranes Software International Ltd TI . This new sequence is the order that the samples enter the FFT. Step 5 .Take sampled data and apply FFT algorithm . Step 3 .Select no. 64)) using math library function.

14159265358979 //# of points for FFT typedef struct {float real. i++) //swap buffers { iobuffer[i] = sin(2*PI*10*i/64.0. samples[i].real = cos(2*PI*i/(PTS*2. int n).0.Solutions Main. i < PTS .real=0.c (fft 256.h> #define PTS 64 #define PI 3. //FFT prototype //as input and output buffer //intermediate buffer //general purpose index //number of new samples in //set to 1 by ISR when //twiddle constants stored in //primary working buffer main() { for (i = 0 . variable short buffercount = 0. w COMPLEX samples[PTS].0)).imag. //Im component of twiddle constants } for (i = 0 . float x1[PTS].> freq. short i.Cranes Software International Ltd C PROGRAM TO IMPLEMENT FFT : TI . iobuffer full COMPLEX w[PTS].imag=0. i++) // set up twiddle constants in w { w[i].imag =-sin(2*PI*i/(PTS*2.c): #include <math.0). //Re component of twiddle constants w[i]. 64 -> sampling freq*/ samples[i].0)). iobuffer short flag = 0. void FFT(COMPLEX *Y. i<PTS ./*10. } 51 . float iobuffer[PTS].} COMPLEX.

i++) samples[i]. step. int N) //input sample array. //twiddle constants stored in w void FFT(COMPLEX *Y. //log(base2) of N points= # of stages 52 .PTS). //difference between upper/lower leg int num_stages = 0.real*samples[i].imag = 0. i < PTS .j.c: #define PTS 64 //# of points for FFT typedef struct {float real.Solutions for (i = 0 .} COMPLEX. //temporary storage variables int i. //buffer with new data } for (i = 0 .real + samples[i].Cranes Software International Ltd TI . } } //end of main fft. //call function FFT. lower_leg.imag*samples[i]. i < PTS .k.0. # of points { COMPLEX temp1. i < PTS . //index/step through twiddle constant i = 1.imag). extern COMPLEX w[PTS]. //imag components = 0 FFT(samples.c for (i = 0 .real=iobuffer[i]. i++) //compute magnitude { x1[i] = sqrt(samples[i]. //number of FFT stages (iterations) int index. i++) //swap buffers { samples[i]. //loop counter variables int upper_leg.temp2. //index of upper/lower butterfly leg int leg_diff.imag.

if (i<j) { temp1.real*(w[index]).real = temp1.imag +temp2.imag = (Y[upper_leg]). (Y[j]). //step between values in twiddle.imag*(w[index]). upper_leg += (2*leg_diff)) { lower_leg = upper_leg+leg_diff.imag = temp2.imag*(w[index]). (Y[lower_leg]). temp1.imag. leg_diff = N/2. temp1. (Y[j]).real. } leg_diff = leg_diff/2.real = (Y[upper_leg]). i++) //bit reversal for resequencing data { k = N/2.real + (Y[lower_leg]). for (i = 1.imag = (Y[j]). j < leg_diff.real.k.imag .imag. i < (N-1).imag = temp1.real*(w[index]). }while (i!=N).i < num_stages.real -temp2.real = (Y[j]).real = (Y[i]).Cranes Software International Ltd TI . } j = j + k. temp2.h for (i = 0. temp2. (Y[lower_leg]).real .imag.Solutions do { num_stages +=1. //difference between upper&lower legs step = (PTS*2)/N.imag = (Y[i]).imag = (Y[upper_leg]).(Y[lower_leg]). upper_leg < N.(Y[lower_leg]).real = (Y[upper_leg]). (Y[upper_leg]). i = i*2. j++) { for (upper_leg = j. for (j = 0.real.imag. temp1.real. step *= 2. (Y[upper_leg]).real = temp2.imag.real.imag. k = k/2.real. } j = 0.imag + (Y[lower_leg]). } index += step. i++) //for N-point FFT { index = 0. while (k <= j) { j = j . 53 .

Solutions Input: Output: 54 .real. (Y[i]). } TI . } } return.imag.imag = temp1.real = temp1.Cranes Software International Ltd (Y[i]).

! Add the linker command file “hello.Cranes Software International Ltd TI . save it in a separate directory(c:\ti\myprojects) with name “FFT. ! Start a new project using ‘Project-new ‘ pull down menu.C” in the project using ‘Project"add files to project’ pull down menu.lib” ! Set ‘-mf ‘option ! Compile the program using the ‘Project-compile’ pull down menu or by clicking the shortcut icon on the left side of program window. make sure the DSP kit is turned on.Solutions HOW TO PROCEED ! Open Code Composer Studio. ! Add the source files “FFT256. ! Run the program and observe output using graph utility.cmd” . ! Add the rts file “rts_ext.c“ and “FFT. ! Load the program in program memory of DSP chip using the ‘File-load program’ pull down menu.pjt”. 55 .

) E.: For a process x(n) correlation is defined as: R (τ ) = E { x ( n ) x ( n + τ ) } = lim N → ∞ 1 N ∑ N x(n ) x (n + τ ) n =1 Power Spectral Density is a Fourier transform of the auto correlation. To compute PSD We compute the auto-correlation of the signal and then take its FFT. The total area under the Power Spectrum or PSD is equal to the total avg.Cranes Software International Ltd TI .g. (Another estimation method called “period gram” uses sampled FFT to compute the PSD. S ( ω ) = F T ( R (τ )) = lim R (τ ) = F T −1 N→∞ τ = − N +1 ∑ N −1 ˆ R (τ ) e − jω τ jω τ ( S ( ω )) = 1 2π ∫ S (ω ) e dω 56 . The auto-correlation function and PSD are a Fourier transform pair. We are most often interested in the PSD or the Power Spectrum. power of the signal. The PSD is an even function of frequency or in other words To compute PSD: The value of the auto-correlation function at zero-time equals the total power in the signal.Solutions POWER SPECTRUM The total or the average power in a signal is often not of as great an interest. We often want to see is how the input power has been redistributed by the channel and in this frequency-based redistribution of power is where most of the interesting information lies.

Step 4 . of Points of FFT(eg.Select no. of points for FFT(Eg: 64) TI .Repeat Step-1 to 4 for different no. 57 . of points & frequencies.Cranes Software International Ltd ALGORITHM TO IMPLEMENT PSD: • • • • • • Step 1 . apply FFT algorithm .Compute the Auto Correlation of Sine wave Step4 . Step 3 . Step 5 . 64)) using math library function.Take output of auto correlation.Solutions Step 2 – Generate a sine wave of frequency ‘f ‘ (eg: 10 Hz with a sampling rate = No.Use Graph option to view the PSD.

j=0. COMPLEX samples[PTS].0)).0)).c: /************************************************************* * FILENAME * Non_real_time_PSD. COMPLEX w[PTS]. i++) // set up twiddle constants in w { w[i].Cranes Software International Ltd TI .14159265358979 typedef struct {float real.imag.0 .i.i++) { x[i] = sin(2*PI*5*i/PTS). for (i = 0 . * x1 --> use in graph window to view PSD /*===========================================================*/ #include <math. /*Re component of twiddle constants*/ w[i]. float iobuffer[PTS].imag =-sin(2*PI*i/(PTS*2.k.sum=0.x[PTS].} COMPLEX. main() { //# of points for FFT //FFT prototype //as input and output buffer //intermediate buffer //general purpose index variable //number of new samples in iobuffer //set to 1 by ISR when iobuffer full //twiddle constants stored in w //primary working buffer float j. float y[128].c * DESCRIPTION * Program to Compute Non real time PSD * using the TMS320C6711 DSK. int n. float x1[PTS].h> #define PTS 128 #define PI 3. int n).i<PTS. 58 . // Signal *************************/ x(Fs)=sin(2*pi*f*i/Fs). short i. *************************************************************** * DESCRIPTION * Number of points for FFT (PTS) * x --> Sine Wave Co-Efficients * iobuffer --> Out put of Auto Correlation.real = cos(2*PI*i/(PTS*2.Solutions ‘C’ Program to Implement PSD: PSD. short buffercount = 0. short flag = 0. void FFT(COMPLEX *Y.a. /*Im component of twiddle constants*/ } /****************Input Signal X(n) for(i=0. i<PTS .

Solutions /********************Auto Correlation of X(n)=R(t) ***********/ for(n=0.PTS). for(k=0. } iobuffer[n] = sum. //indexof upper/lower butterfly leg int leg_diff. i < PTS .0.imag*samples[i].k<PTS-n. //loop counter variables int upper_leg. //buffer with new data } for (i = 0 .0. //temporary storage variables int i. //index/step through twiddle constant 59 . i < PTS . i++) //swap buffers { samples[i]. lower_leg.imag. # of points { COMPLEX temp1.real + samples[i].temp2.n<PTS.c /******************** PSD ********************/ for (i = 0 . } TI .j. samples[i].n++) { sum=0.imag=0. //twiddle constants stored in w void FFT(COMPLEX *Y. step.} COMPLEX. } } //end of main FFT.real=iobuffer[i].real=0.Cranes Software International Ltd samples[i]. i++) //compute magnitude { x1[i] = sqrt(samples[i].c: #define PTS 128 //# of points for FFT typedef struct {float real.real*samples[i]. i < PTS . } /********************** FFT of R(t) ***********************/ for (i = 0 .imag). //difference between upper/lower leg int num_stages = 0. i++) samples[i]. // Auto Correlation R(t) //imag components = 0 //call function FFT.0.k++) { sum=sum+(x[k]*x[n+k]).imag = 0. //number of FFT stages (iterations) int index. int N) //input sample array. FFT(samples.k. extern COMPLEX w[PTS].

imag.imag.imag + (Y[lower_leg]). while (k <= j) { j = j . step *= 2. j < leg_diff. leg_diff = N/2.real. //log(base2) of N points= # of stages do { num_stages +=1.real = temp1. i = i*2.real. (Y[i]).real + (Y[lower_leg]). } j = 0.real . } leg_diff = leg_diff/2.(Y[lower_leg]).real = (Y[upper_leg]).real = (Y[upper_leg]). k = k/2. //difference between upper&lower legs step = (PTS*2)/N.Solutions i = 1.real = (Y[i]).real = (Y[j]). (Y[lower_leg]).imag = temp1. temp2. } } return. (Y[upper_leg]). //step between values in twiddle.real.imag.Cranes Software International Ltd TI .i < num_stages. temp1.real = temp1.imag .k.imag.real. (Y[lower_leg]).imag. i++) //bit reversal for resequencing data { k = N/2.imag.imag = (Y[i]).imag = temp2.imag = (Y[j]). }while (i!=N).imag.real*(w[index]). temp1. upper_leg < N.real.imag = (Y[upper_leg]). for (j = 0.(Y[lower_leg]).real. (Y[j]).real -temp2. (Y[i]). upper_leg += (2*leg_diff)) { lower_leg = upper_leg+leg_diff.imag*(w[index]). i < (N-1).imag = (Y[upper_leg]).real*(w[index]). } 60 . if (i<j) { temp1. temp2. (Y[j]). for (i = 1. } index += step. (Y[upper_leg]).real.real = temp2. i++) //for N-point FFT { index = 0. } j = j + k.h// 512 for (i = 0.imag = temp1. temp1.imag +temp2. j++) { for (upper_leg = j.imag*(w[index]).

save it in a separate directory(c:\ti\myprojects) with name “PSD. ! Add the rts file “rts_ext. ! Add the linker command file “hello. ! Start a new project using ‘Project-new ‘ pull down menu. ! Run the program and observe output using graph utility. ! Add the source files “PSD. ! Load the program in program memory of DSP chip using the ‘File-load program’ pull down menu.Solutions ! Open Code Composer Studio.lib” ! Compile the program using the ‘Project-compile’ pull down menu or by clicking the shortcut icon on the left side of program window.pjt”.c“ and “FFT.cmd” .Cranes Software International Ltd HOW TO PROCEED TI . OUT PUT: 61 .c” in the project using ‘Project"add files to project’ pull down menu. make sure the DSP kit is turned on.

Cranes Software International Ltd TI .Solutions 62 .