You are on page 1of 92

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

TABLE OF CONTENTS
S.NO. NAME OF THE EXPERIMENT PAGE NO

To study the CSA/Instructions

architecture

of

DSP

chipsTMS

320

2 3 4

To verify Linear Convolution To verify Circular Convolution To design FIR filter (LP/HP) using Windowing technique: a. Using Rectangular Window b. Using Triangular Window c. Using Kaiser Window

19 23

27

5 6 7

To design IIR filter (LP/HP) 5. N point FFT algorithm MATLAB program to generate sum of sinusoidal signal algorithm

39 47 55

MATLAB program to find frequency response of analog LP/HP filters To compute Power Density Spectrum of a sequence To find the FFT of given 1-D signal and plot ADDITIONAL EXPERIMENTS

59 67 75

9 10

11 12

Basic signals generation using MATLAB Signal smoothing using MATLAB

83 91

1
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

2
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

LAB INTERNAL EVALUATION


S.No Name of the Experiment Date Remarks

3
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

TMS320C6713 DSK Overview Block Diagram

4
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

TO STUDY THE ARCHITECTURE OF DSP CHIPS TMS 320 CSA / INSTRUCTIONS


AIM: To study the architecture of DSP processor TMS 320C6713 / Instructions.

TOOLS REQUIRED: TMS 320 C6713Kit, Code Composer Studio Software, Personal Computer The C6713 Digital Signal Processor (DSP) Starter Kit (DSK) builds on Texas Instruments (TI's) industry-leading line of low cost, easy-to-use DSK development boards. The high-performance board features the TMS320C6713 floating-point DSP. Capable of performing 1350 Million Floating-point Operations Per Second (MFLOPS), the C6713 DSP makes the C6713 DSK the most powerful DSK development board. The DSK is USB port interfaced platform that allows to efficiently develop and test applications for the C6713. The DSK consists of a C6713-based printed circuit board that will serve as a hardware reference design for TIs customers products. With extensive host PC and target DSP software support, including bundled TI tools, the DSK provides ease-of-use and capabilities that are attractive to DSP engineers. The C6713 DSK has a TMS320C6713 DSP onboard that allows full-speed verification of code with Code Composer Studio. The C6713 DSK provides: A USB Interface SDRAM and ROM An analog interface circuit for Data conversion (AIC) An I/O port Embedded JTAG emulation support

The C6711 DSK includes a stereo codec. This analog interface circuit (AIC) has the following characteristics: 1. High-Performance Stereo Codec 90-dB SNR Multibit Sigma-Delta ADC (A-weighted at 48 kHz) 100-dB SNR Multibit Sigma-Delta DAC (A-weighted at 48 kHz) 1.42 V 3.6 V Core Digital Supply: Compatible With TI C54x DSP Core Voltages 2.7 V 3.6 V Buffer and Analog Supply: Compatible Both TI C54x DSP Buffer Voltages 8-kHz 96-kHz Sampling-Frequency Support
5
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

6
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

2. Software Control Via TI McBSP-Compatible Multiprotocol Serial Port I 2 C-Compatible and SPI-Compatible Serial-Port Protocols Glueless Interface to TI McBSPs

3. Audio-Data Input/Output Via TI McBSP-Compatible Programmable Audio Interface I 2 S-Compatible Interface Requiring Only One McBSP for both ADC and DAC Standard I 2 S, MSB, or LSB Justified-Data Transfers 16/20/24/32-Bit Word Lengths The C6713DSK has the following features: The 6713 DSK is a low-cost standalone development platform that enables customers to evaluate and develop applications for the TI C67XX DSP family. The DSK also serves as a hardware reference design for the TMS320C6713 DSP. Schematics, logic equations and application notes are available to ease hardware development and reduce time to market. The DSK uses the 32-bit EMIF for the SDRAM (CE0) and daughter card expansion interface (CE2 and CE3). The Flash is attached to CE1 of the EMIF in 8-bit mode. An on-board AIC23 codec allows the DSP to transmit and receive analog signals. McBSP0 is used for the codec control interface and McBSP1 is used for data. Analog audio I/O is done through four 3.5mm audio jacks that correspond to microphone input, line input, line output and headphone output. The codec can select the microphone or the line input as the active input. The analog output is driven to both the line out (fixed gain) and headphone (adjustable gain) connectors. McBSP1 can be re-routed to the expansion connectors in software. The DSK includes 4 LEDs and 4 DIP switches as a simple way to provide the user with interactive feedback. Both are accessed by reading and writing to the CPLD registers. An included 5V external power supply is used to power the board. On-board voltage regulators provide the 1.26V DSP core voltage, 3.3V digital and 3.3V analog voltages. A voltage supervisor monitors the internally generated voltage, and will hold the board in reset until the supplies are within operating specifications and the reset button is released. If desired, JP1 and JP2 can be used as power test points for the core and I/O power supplies. Code Composer communicates with the DSK through an embedded JTAG emulator with a USB host interface. The DSK can also be used with an external emulator through the external JTAG connector. TMS320C6713 DSP Features Highest-Performance Floating-Point Digital Signal Processor (DSP):

Eight 32-Bit Instructions/Cycle 32/64-Bit Data Word 300-, 225-, 200-MHz (GDP), and 225-, 200-, 167-MHz Clock Rates 3.3-, 4.4-, 5-, 6-Instruction Cycle Times 2400/1800, 1800/1350, 1600/1200, and 1336/1000 MIPS /MFLOPS Rich Peripheral Set, Optimized for Audio Highly Optimized C/C++ Compiler Extended Temperature Devices Available
7

SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

TMS320C6713 DSP Block Diagram

8
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Advanced Very Long Instruction Word (VLIW) TMS320C67x DSP Core Eight Independent Functional Units: Two ALUs (Fixed-Point) Four ALUs (Floating- and Fixed-Point) Two Multipliers (Floating- and Fixed-Point) Load-Store Architecture with 32 32-Bit General-Purpose Registers Instruction Packing Reduces Code Size All Instructions Conditional Instruction Set Features Native Instructions for IEEE 754 Single- and Double-Precision Byte-Addressable (8-, 16-, 32-Bit Data) 8-Bit Overflow Protection Saturation; Bit-Field Extract, Set, Clear; Bit-Counting; Normalization L1/L2 Memory Architecture 4K-Byte L1P Program Cache (Direct-Mapped) 4K-Byte L1D Data Cache (2-Way) 256K-Byte L2 Memory Total: 64K-Byte L2 Unified Cache/Mapped RAM, and 192KByte Additional L2 Mapped RAM Device Configuration Boot Mode: HPI, 8-, 16-, 32-Bit ROM Boot Endianness: Little Endian, Big Endian 32-Bit External Memory Interface (EMIF) Glueless Interface to SRAM, EPROM, Flash, SBSRAM, and SDRAM 512M-Byte Total Addressable External Memory Space Enhanced Direct-Memory-Access (EDMA) Controller (16 Independent Channels) 16-Bit Host-Port Interface (HPI) Two Multichannel Audio Serial Ports (McASPs) Two Independent Clock Zones Each (1 TX and 1 RX) Eight Serial Data Pins Per Port: Individually Assignable to any of the Clock Zones Each Clock Zone Includes: Programmable Clock Generator Programmable Frame Sync Generator TDM Streams From 2-32 Time Slots Support for Slot Size: 8, 12, 16, 20, 24, 28, 32 Bits Data Formatter for Bit Manipulation Wide Variety of I2S and Similar Bit Stream Formats Integrated Digital Audio Interface Transmitter (DIT) Supports: S/PDIF, IEC60958-1, AES-3, CP-430 Formats Up to 16 transmit pins Enhanced Channel Status/User Data Extensive Error Checking and Recovery Two Inter-Integrated Circuit Bus (I2C Bus) Multi-Master and Slave Interfaces Two Multichannel Buffered Serial Ports: Serial-Peripheral-Interface (SPI) High-Speed TDM Interface AC97 Interface
9

SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Procedure used for running Code Composer Studio: 1. Click on the Code Composer Studio. And create the project of your own i.e. as shown below:

2. To create the new source file, Click on File-> NEW-> Source file

3. Write the program in edit window and save the file in your project as *.C (for C Program) or *.asm (Assembly Language Program)

10
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

TMS320C6713 CPU Datapath

Two 32-Bit General-Purpose Timers Dedicated GPIO Module With 16 pins (External Interrupt Capable) Flexible Phase-Locked-Loop (PLL) Based Clock Generator Module IEEE-1149.1 (JTAG ) Boundary-Scan-Compatible Package Options: 208-Pin Power PAD Plastic (Low-Profile) Quad Flat pack (PYP) 272-BGA Packages (GDP and ZDP) 0.13-m/6-Level Copper Metal Process CMOS Technology 3.3-V I/Os, 1.2 -V Internal (GDP & PYP) 3.3-V I/Os, 1.4-V Internal (GDP)(300 MHz only)

The TMS320C6713 CPU contains : 1. 2. 3. 4. 5. 6. 7. 8. Program Fetch unit Instruction dispatch unit Instruction decode unit Two data paths, each with four functional units 32 32-bit registers Control registers Control logic Test, emulation, and interrupt logic

11
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

4. Click on Project ->Add files to Project-> click your Source file.

5. Click on Project ->Add files to Project ->C:\CCStudio\cgtools\lib\rts6700.lib (File type is Object and Library Files *.o, *.l)

6. Click Project ->Add files to Project -:\CCStudio\Tutorial\dsk6713\hello1\hello.cmd (File type is Linker Command File *.cmd)

12
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Mapping Between Instructions and Functional Units : The following Table shows which instructions can be executed in which of the functional units for fixed point instructions.

13
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

6. Click on Project -> Compile your file.

8.

Click on Project-> Build your File.

9. Click on File-> Load project.

14
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Mapping Between Instructions and Functional Units : The following Table shows which instructions can be executed in which of the functional units for floating point instructions.

15
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

10. Disassembly file is available in the below Window.

11. Click on Debug -> Run (see the result in the Output window.)

16
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Program: .global _main _main: MVKL ABS ZERO ADD SUB MPY NOP 1 SUB B B3 NOP 5 RESULT:

.S1 -5, A4 .L1 A4, A4 .L1 A3 .L1 A4, A4, A3 .L1 A3, A4, A5 .M1 A3, A4, A0 .L2X A0, B0, B0

17
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

MODEL GRAPH:

18
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

TO VERIFY LINEAR CONVOLUTION


AIM: To write a program to compute the response of a discrete LTI system with input sequence x(n) and impulse response h(n) by using linear convolution. TOOLS REQUIRED: TMS 320 C6713Kit, Code Composer Studio Software, Personal Computer PROCEDURE: 1. Create a Project in Code Composer Studio. 2. Create a Source file in C language for Linear Convolution and add it to the project. 3. Add both hello.cmd & rts6700.lib files to the current project folder from the following locations: C:\CCStudio\tutorial\dsk6713\hello1 and C:\CCStudio\c6000\cgtools\lib 4. Compile C file for debugging errors. 5. Build the project. 6. Load Program (.out file) into DSK from file menu. 7. Run the program from Debug menu. 8. Plot the Graph of linear convolution from View graph menu. C-PROGRAM FOR LINEAR CONVOLUTION: #include<stdio.h> int x[20],h[20],y[20],N1,N2,n,m; main() { printf("Enter the length of input sequence x(n)\t:N1="); scanf("%d",&N1); printf("Enter the length of impulse response h(n)\t:N2="); scanf("%d",&N2); printf("Enter %d samples for input sequence x(n):\n",N1); for(n=0;n<N1;n++) scanf("%d",&x[n]); printf("Enter %d samples for impulse response h(n):\n",N2); for(n=0;n<N2;n++) scanf("%d",&h[n]); printf("Input sequence \nx(n)=");
19
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

GRAPH:

20
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

for(n=0;n<N1;n++) printf("\t%d",x[n]); printf("\nImpulse Response \nh(n)="); for(n=0;n<N2;n++) printf("\t%d",h[n]); for(n=0;n<N1+N2-1;n++) { y[n]=0; for(m=0;m<=n;m++) y[n]=y[n]+x[m]*h[n-m]; } printf("\n Response of LT1 system is\ny(n)="); for(n=0;n<N1+N2-1;n++) printf("\t%d",y[n]); }

INPUT: Enter the length of input sequence x(n) :N1= Enter the length of impulse response h(n):N2= Enter 4 samples for input sequence x(n): Enter 4 samples for impulse response h(n): Response of LT1 system is y(n) =

RESULT:

21
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

MODEL GRAPH:

22
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

TO VERIFY CIRCULAR CONVOLUTION


AIM: To write a program to compute the response of a discrete LTI system with input sequence x(n) and impulse response h(n) by using Circular convolution. TOOLS REQUIRED: TMS 320 C6713Kit, Code Composer Studio Software, Personal Computer PROCEDURE: 1. Create a Project in Code Composer Studio. 2. Create a Source file in C language for Circular Convolution and add it to the project. 3. Add both hello.cmd & rts6700.lib files to the current project folder from the following locations: C:\CCStudio\tutorial\dsk6713\hello1 and C:\CCStudio\c6000\cgtools\lib 4. Compile C file for debugging errors. 5. Build the project. 6. Load Program (.out file) into DSK from file menu. 7. Run the program from Debug menu.

8. Plot the Graph of Circular convolution from View graph menu.


C-PROGRAM FOR CIRCULAR CONVOLUTION: #include<stdio.h> int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30]; void main() { printf(" enter the length of the first sequence\n"); scanf("%d",&m); printf(" enter the length of the second sequence\n"); scanf("%d",&n); printf(" enter the first sequence\n"); for(i=0;i<m;i++) scanf("%d",&x[i]); printf(" enter the second sequence\n"); for(j=0;j<n;j++) scanf("%d",&h[j]); if(m-n!=0) {
23
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

/*If length of both sequences are not equal*/

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

GRAPH:

CALUCLATION: Enter the length of input sequence x(n) :N1= Enter the length of impulse response h(n):N2= Enter 4 samples for input sequence x(n): Enter 4 samples for impulse response h(n): Input sequence after zero padding x(n)= Impulse Response after zero padding h(n)= Response of LT1 system is y(n)=

24
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

if(m>n)

/* Pad the smaller sequence with zero*/

for(i=n;i<m;i++) h[i]=0; n=m; } for(i=m;i<n;i++) x[i]=0; m=n; } y[0]=0; a[0]=h[0]; for(j=1;j<n;j++) a[j]=h[n-j]; /*Circular convolution*/ for(i=0;i<n;i++) y[0]+=x[i]*a[i]; for(k=1;k<n;k++) { y[k]=0; /*circular shift*/ for(j=1;j<n;j++) x2[j]=a[j-1]; x2[0]=a[n-1]; for(i=0;i<n;i++) { a[i]=x2[i]; y[k]+=x[i]*x2[i]; } } /*displaying the result*/ printf(" the circular convolution is\n"); for(i=0;i<n;i++) printf(%d \t,y[i]); } Result:
25
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

/*folding h(n) to h(-n)*/

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT: Rectangular Window


50 Gain in dB --> 0 50 Gain in dB --> 0

-50

-50

-100

0.5 Normalised

-100

0.5 Normalised

50 Gain in dB --> 0

20 Gain in dB --> 0 -20

-50

-40 -60

-100

0.5 Normalised

0.5 Normalised

OUTPUT:

Triangular Window
0 Gain in dB --> -20 20 Gain in dB --> 0

-40

-20

-60

0.5 Normalised

-40

0.5 Normalised

0 Gain in dB --> -20

5 Gain in dB --> 0 -5

-40

-10 -15

-60

0.5 Normalised

0.5 Normalised

26
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

DESIGN OF FIR FILTER USING WINDOWING TECHNIQUES


AIM: To write a program to design a FIR filters using different windowing techniques. TOOLS REQUIRED: MATLAB Software, Personal Computer. ALGORITHM: 1. Get the pass band and stop band ripples. 2. Get the pass band and stop band edge frequencies. 3. Get the sampling frequency. 4. Calculate the order of filter. 5. Find filter coefficients. 6. Draw the magnitude and phase response. MATLAB PROGRAM FOR FIR FILTER USING RECTANGULAR WINDOW: clc; clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*fp; ws=2*fs; w1=wp/f; w2=ws/f; num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); n1=n+1; if (rem(n,2)~=0) n1=n; n=n-1; end
27
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Kaiser window:

28
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

%low pass filter y=boxcar(n1); n1 b=fir1(n,w1,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,1); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency'); %high pass filter y=boxcar(n1); n1 b=fir1(n,w1,'high',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,2); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency'); %band pass filter wn=[w2 w1]; y=boxcar(n1); wn n1 b=fir1(n,wn,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,3); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency'); %band stop filter wn=[w2 w1]; y=boxcar(n1); n1 b=fir1(n,wn,'stop',y); [h,o]=freqz(b,1,256);
29
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Gaph:

30
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

m=20*log10 (abs(h)); subplot(2,2,4); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency'); MATLAB PROGRAM FOR FIR FILTER USING TRIANGULAR WINDOW: clc; clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*fp; ws=2*fs; w1=wp/f; w2=ws/f; num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); n1=n+1; if (rem(n,2)~=0) n1=n; n=n-1; end %low pass filter y=triang(n1); n1 b=fir1(n,w1,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,1); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency');

31
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Graph:

32
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

%high pass filter y=triang(n1); n1 b=fir1(n,w1,'high',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,2); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency'); %band pass filter wn=[w2 w1]; y=triang(n1); n1 b=fir1(n,wn,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,3); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency'); %band stop filter wn=[w2 w1]; y=triang(n1); n1 b=fir1(n,wn,'stop',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,4); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency');

33
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Graph:

34
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

MATLAB PROGRAM FOR FIR FILTER USING KAISER WINDOW: clc; clear all; close all; beta=0.5; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*fp; ws=2*fs; w1=wp/f; w2=ws/f; num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); n1=n+1; if (rem(n,2)~=0) n1=n; n=n-1; end %low pass y=kaiser(n1,beta); b=fir1(n,w1,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,1); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency'); %high pass y=kaiser(n1,beta); b=fir1(n,w1,'high',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,2); plot(o/pi,m);
35
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

36
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

ylabel('Gain in dB -->'); xlabel('Normalised frequency'); %band pass y=kaiser(n1,beta); wn=[w2 w1]; wn n1 b=fir1(n,wn,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,3); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency'); %band stop y=kaiser(n1,beta); wn=[w2 w1]; b=fir1(n,wn,'stop',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,4); plot(o/pi,m); ylabel('Gain in dB -->'); xlabel('Normalised frequency');

RESULT:

37
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT:
BUTTERWORTH HIGH PASS FILTER 0 Gain in dB -100 -200 -300 -400 0 0.1 0.2 0.3 0.4 0.5 0.6 (a) Normalised frequency 0.7 0.8 0.9 1

Phase in radians 4 2 0 -2 -4 0 0.1 0.2 0.3 0.4 0.5 0.6 (b) Normalised frequency 0.7 0.8 0.9 1

OUTPUT:

38
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

To design IIR filter (LP/HP)


AIM: Design of IIR Butter worth, Chebyshev high pass & low pass digital filters using MATLAB. TOOLS REQUIRED: MATLAB Software, Personal Computer. MATLAB PROGRAM FOR IIR BUTTERWORTH HIGH PASS FILTER: clc; clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*pi*fp; ws=2*pi*fs; w1=wp/f; w2=ws/f; [N,WN]=buttord(w1,w2,rp,rs); [B,A]=butter(N,WN,'HIGH'); w=0:0.01:pi; [H1,om]=freqz(B,A,w); m=20*log10(abs(H1)); an=angle(H1); subplot(2,1,1); plot(om/pi,m); xlabel(' (a) Normalised frequency'); ylabel(' Gain in dB'); title('BUTTERWORTH HIGH PASS FILTER'); grid; subplot(2,1,2); plot(om/pi,an); xlabel(' (b) Normalised frequency'); ylabel(' Phase in radians'); grid;
39
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT:
CHEBYSHEV TYPE-1 HIGH PASS FILTER 0 Gain in dB -100 -200 -300 -400

0 0.1 Phase in radians 4 2 0 -2 -4

0.2

0.3

0.4 0.5 0.6 (a) Normalised frequency

0.7

0.8

0.9

0.1

0.2

0.3

0.4 0.5 0.6 (b) Normalised frequency

0.7

0.8

0.9

OUTPUT:
CHEBYSHEV TYPE-1 LOW PASS FILTER 0 Gain in dB -100 -200 -300 -400

0.1

0.2

0.3

Phase in radians 4 2 0 -2 -4

0.4 0.5 0.6 (a) Normalised frequency

0.7

0.8

0.9

0.1

0.2

0.3

0.4 0.5 0.6 (b) Normalised frequency

0.7

0.8

0.9

40
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

MATLAB PROGRAM FOR IIR BUTTERWORTH LOW PASS FILTER clc; clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*pi*fp; ws=2*pi*fs; w1=wp/f; w2=ws/f; [N,WN]=buttord(w1,w2,rp,rs); [B,A]=butter(N,WN,'LOW'); w=0:0.01:pi; [H1,om]=freqz(B,A,w); m=20*log10(abs(H1)); an=angle(H1); subplot(2,1,1); plot(om/pi,m); xlabel(' (a) Normalised frequency'); ylabel(' Gain in dB'); title('BUTTERWORTH LOW PASS FILTER'); grid; subplot(2,1,2); plot(om/pi,an); xlabel(' (b) Normalised frequency'); ylabel(' Phase in radians'); grid; MATLAB PROGRAM FOR IIR CHEBYSHEV HIGH PASS FILTER: clc; clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple');
41
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Graph:

42
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*pi*fp; ws=2*pi*fs; w1=wp/f; w2=ws/f; [N,WN]=cheb1ord(w1,w2,rp,rs); [B,A]=cheby1(N,rp,WN,'high'); w=0:0.01:pi; [H,om]=freqZ(B,A,w); m=20*log10(abs(H)); an=angle(H); subplot(2,1,1); plot(om/pi,m); xlabel(' (a) Normalised frequency'); ylabel(' Gain in dB'); title('CHEBYSHEV TYPE-1 HIGH PASS FILTER'); grid; subplot(2,1,2); plot(om/pi,an); xlabel(' (b) Normalised frequency'); ylabel(' Phase in radians'); grid;
MATLAB PROGRAM FOR IIR CHEBYSHEV LOW PASS FILTER:

clc; clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*pi*fp; ws=2*pi*fs; w1=wp/f; w2=ws/f; [N,WN]=cheb1ord(w1,w2,rp,rs);
43
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

[B,A]=cheby1(N,rp,WN,'LOW'); Graph:

44
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

w=0:0.01:pi; [H,om]=freqZ(B,A,w); m=20*log10(abs(H)); an=angle(H); subplot(2,1,1); plot(om/pi,m); xlabel(' (a) Normalised frequency'); ylabel(' Gain in dB'); title('CHEBYSHEV LOW PASS FILTER'); grid; subplot(2,1,2); plot(om/pi,an); xlabel(' (b) Normalised frequency'); ylabel(' Phase in radians'); grid;

RESULT:

45
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

GRAPH PROPERTY DIALOG SETTINGS:

MODEL GRAPH:

46
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

N-POINT FFT ALGORITHM


AIM: To obtain the frequency spectrum of the given sampled data (input signal) by using Fast Fourier Transform on TMS320C6713 DSK Kit (or Simulator). TOOLS REQUIRED: TMS 320 C6713Kit, Code Composer Studio Software, Personal Computer PROCEDURE: 1. Create a Project in Code Composer Studio. 2. Create Source files in C language for Main.C and FFT.C and add them to the project. 3. Add both hello.cmd & rts6700.lib files to the current project folder from the following locations: C:\CCStudio\tutorial\dsk6713\hello1 and C:\CCStudio\c6000\cgtools\lib 4. Compile C file for debugging errors. 5. Build the project. 6. Load Program (.out file) into DSK from file menu. 7. Run the program from Debug menu. 8. Plot the Graph for input and output from View graph menu. C SOURCE CODE FOR MAIN.C #include <math.h> #define PTS 8 #define PI 3.14159265358979 typedef struct {float real,imag;} COMPLEX; void FFT(COMPLEX *Y, int n); float iobuffer[PTS]; float x1[PTS],a[PTS]={1,1,1,1,2,2,2,2},y1[PTS],y2[PTS]; short i; short buffercount = 0; short flag = 0; COMPLEX w[PTS]; COMPLEX samples[PTS]; main() {
47
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

//# of points for FFT

//FFT prototype //as input and output 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

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

48
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

for (i = 0 ; i<PTS ; i++) { w[i].real = cos(2*PI*i/(PTS*2.0)); w[i].imag =-sin(2*PI*i/(PTS*2.0)); } for (i = 0 ; i < PTS ; i++) { iobuffer[i] =a[i]; samples[i].real=0.0; samples[i].imag=0.0; } for (i = 0 ; i < PTS ; i++) { samples[i].real=iobuffer[i]; /* iobuffer[i] = x1[i]; } for (i = 0 ; i < PTS ; i++) samples[i].imag = 0.0; FFT(samples,PTS); for (i = 0 ; i < PTS ; i++) {

// set up twiddle constants in w //Re component of twiddle constants //Im component of twiddle constants //swap buffers

//swap buffers //buffer with new data //processed frame to iobuffer*/

//imag components = 0 //call function FFT.c //compute magnitude

x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag); y1[i]=samples[i].real; y2[i]=samples[i].imag; printf("%i+j%f\n",samples[i].real,samples[i].imag); } } C SOURCE CODE FOR FFT.C #define PTS 8 typedef struct {float real,imag;} COMPLEX; extern COMPLEX w[PTS]; void FFT(COMPLEX *Y, int N) { COMPLEX temp1,temp2; int i,j,k; int upper_leg, lower_leg; //temporary storage variables //loop counter variables //index of upper/lower butterfly leg
49
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

//# of points for FFT //twiddle constants stored in w //input sample array, # of points

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

50
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

int leg_diff; int num_stages = 0; int index, step; i = 1; do { num_stages +=1; i = i*2; }while (i!=N); leg_diff = N/2; step = (PTS*2)/N;

//difference between upper/lower leg //number of FFT stages (iterations) //index/step through twiddle constant //log(base2) of N points= # of stages

//difference between upper&lower legs //step between values in twiddle.h // 512

for (i = 0;i < num_stages; i++) //for N-point FFT { index = 0; for (j = 0; j < leg_diff; j++) { for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff)) { lower_leg = upper_leg+leg_diff; temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real; temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag; temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real; temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg]).real = temp2.real*(w[index]).real - temp2.imag*(w[index]).imag; (Y[lower_leg]).imag = temp2.real*(w[index]).imag + temp2.imag*(w[index]).real; (Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag = temp1.imag; } } leg_diff = leg_diff/2; step *= 2; } j = 0; for (i = 1; i < (N-1); i++) { k = N/2; while (k <= j) { j = j - k;
51
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

index += step;

//bit reversal for resequencing data

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

52
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

k = k/2; } j = j + k; if (i<j) { temp1.real = (Y[j]).real; temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real; (Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real; (Y[i]).imag = temp1.imag; } } return; }

RESULT:

53
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

MODEL GRAPH:
SUM OF SIN WAVES 1 AMPLITUDE 0 -1 0

10 12 TIME INDEX

14

16

18

20

1 AMPLITUDE 0 -1 0

10 12 TIME INDEX

14

16

18

20

2 AMPLITUDE 0 -2 0

10 12 TIME INDEX

14

16

18

20

54
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

MATLAB PROGRAM TO GENERATE SUM OF SINUSOIDAL SIGNALS


AIM: To generate sum of sinusoidal signals using MATLAB TOOLS REQUIRED: MATLAB Software, Personal Computer. MATLAB PROGRAM: clc; clear all; close all; t=0:0.01:20; x1=sin(2*pi*t/5); subplot(3,1,1); plot(t,x1); xlabel('TIME INDEX'); ylabel('AMPLITUDE'); title('SUM OF SIN WAVES'); x2=sin(2*pi*t/7); subplot(3,1,2); plot(t,x2); xlabel('TIME INDEX'); ylabel('AMPLITUDE'); x=x1+x2; subplot(3,1,3); plot(t,x); xlabel('TIME INDEX'); ylabel('AMPLITUDE');

55
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Graph:

56
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Result:

57
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT:
BUTTERWORTH HIGH PASS FILTER 500 Gain in dB 0

-500

-1000

0.1

0.2

0.3

0.4 0.5 0.6 (a) Normalised frequency

0.7

0.8

0.9

4 Phase in radians 2 0 -2 -4

0.1

0.2

0.3

0.4 0.5 0.6 (b) Normalised frequency

0.7

0.8

0.9

OUTPUT:
CHEBYSHEV TYPE-1 HIGH PASS FILTER 0 Gain in dB -100 -200 -300 -400

0.1

0.2

0.3

0.4 0.5 0.6 (a) Normalised frequency

0.7

0.8

0.9

Phase in radians 4 2 0 -2 -4

0.1

0.2

0.3

0.4 0.5 0.6 (b) Normalised frequency

0.7

0.8

0.9

58
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

MATLAB PROGRAM TO FIND FREQUENCY RESPONSE OF ANALOG LP/HP FILTERS


AIM: Design of IIR Butter worth and Chebyshev LP/HP filters using MATLAB. TOOLS REQUIRED: MATLAB Software, Personal Computer. MATLAB PROGRAM FOR ANALOG BUTTERWORTH HIGH PASS FILTER: clc; clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*pi*fp; w1=wp/f; ws=2*pi*fs; w2=ws/f;

[N,WN]=buttord(w1,w2,rp,rs,'s'); [B,A]=butter(N,WN,'HIGH','s'); w=0:0.01:pi; [H1,om]=freqs(B,A,w); m=20*log10(abs(H1)); an=angle(H1); subplot(2,1,1); plot(om/pi,m); xlabel(' (a) Normalised frequency'); ylabel(' Gain in dB'); title('BUTTERWORTH HIGH PASS FILTER'); grid; subplot(2,1,2); plot(om/pi,an); xlabel(' (b) Normalised frequency'); ylabel(' Phase in radians'); grid;
59
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT:
BUTTERWORTH LOW PASS FILTER 100 Gain in dB 0 -100 -200 -300

0.1

0.2

0.3

0.4 0.5 0.6 (a) Normalised frequency

0.7

0.8

0.9

Phase in radians 4 2 0 -2 -4

0.1

0.2

0.3

0.4 0.5 0.6 (b) Normalised frequency

0.7

0.8

0.9

OUTPUT:
CHEBYSHEV LOW PASS FILTER 0 Gain in dB -50

-100

-150

0.1

0.2

0.3

0.4 0.5 0.6 (a) Normalised frequency

0.7

0.8

0.9

Phase in radians 4 2 0 -2 -4

0.1

0.2

0.3

0.4 0.5 0.6 (b) Normalised frequency

0.7

0.8

0.9

60
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

MATLAB PROGRAM FOR ANALOG CHEBYSHEV HIGH PASS FILTER: clc; clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*pi*fp; ws=2*pi*fs; w1=wp/f; w2=ws/f; [N,WN]=cheb1ord(w1,w2,rp,rs,'s'); [B,A]=cheby1(N,rp,WN,'high','s'); w=0:0.01:pi; [H,om]=freqs(B,A,w); m=20*log10(abs(H)); an=angle(H); subplot(2,1,1); plot(om/pi,m); xlabel(' (a) Normalised frequency'); ylabel(' Gain in dB'); title('CHEBYSHEV TYPE-1 HIGH PASS FILTER'); grid; subplot(2,1,2); plot(om/pi,an); xlabel(' (b) Normalised frequency'); ylabel(' Phase in radians'); grid;

61
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Graph:

62
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

MATLAB PROGRAM FOR ANALOG BUTTERWORTH LOW PASS FILTER: clc; clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*pi*fp; ws=2*pi*fs; w1=wp/f; w2=ws/f; [N,WN]=buttord(w1,w2,rp,rs,'s'); [B,A]=butter(N,WN,'LOW','s'); w=0:0.01:pi; [H1,om]=freqs(B,A,w); m=20*log10(abs(H1)); an=angle(H1); subplot(2,1,1); plot(om/pi,m); xlabel(' (a) Normalised frequency'); ylabel(' Gain in dB'); title('BUTTERWORTH LOW PASS FILTER'); grid; subplot(2,1,2); plot(om/pi,an); xlabel(' (b) Normalised frequency'); ylabel(' Phase in radians'); grid; MATLAB PROGRAM FOR ANALOG CHEBYSHEV LOW PASS FILTER: clear all; close all; fp=input('enter the pass band frequency'); fs=input('enter the stop band frequency'); rp=input('enter the pass band ripple');

63
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Graph:

64
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

rs=input('enter the stop band ripple'); f=input ('enter the sample frequency'); wp=2*pi*fp; ws=2*pi*fs; w1=wp/f; w2=ws/f; [N,WN]=cheb1ord(w1,w2,rp,rs,'s'); [B,A]=cheby1(N,rp,WN,'LOW','s'); w=0:0.01:pi; [H,om]=freqs(B,A,w); m=20*log10(abs(H)); an=angle(H); subplot(2,1,1); plot(om/pi,m); xlabel(' (a) Normalised frequency'); ylabel(' Gain in dB'); title('CHEBYSHEV LOW PASS FILTER'); grid; subplot(2,1,2); plot(om/pi,an); xlabel(' (b) Normalised frequency'); ylabel(' Phase in radians'); grid;

RESULT:

65
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Graph:

66
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

TO COMPUTE POWER DENSITY SPECTRUM OF A SEQUENCE


AIM: To write a Program to compute non real time Power Spectral Density. TOOLS REQUIRED: TMS 320 C6713Kit, Code Composer Studio Software, Personal Computer PROCEDURE: 1. Create a Project in Code Composer Studio. 2. Create Source files in C language for Main.C and FFT.C and add them to the project. 3. Add both hello.cmd & rts6700.lib files to the current project folder from the following locations: C:\CCStudio\tutorial\dsk6713\hello1 and C:\CCStudio\c6000\cgtools\lib 4. Compile C file for debugging errors. 5. Build the project. 6. Load Program (.out file) into DSK from file menu. 7. Run the program from Debug menu. 8. Plot the Graph for input and output from View graph menu. C-SOURCE CODE FOR PSD.C #include <math.h> #define PTS 128 #define PI 3.14159265358979 typedef struct {float real,imag;} COMPLEX; void FFT(COMPLEX *Y, int n); float iobuffer[PTS]; float x1[PTS],x[PTS]; short i; short buffercount = 0; short flag = 0; float y[128]; COMPLEX w[PTS]; COMPLEX samples[PTS]; main() {
67
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

//# 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

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

GRAPH PROPERTY DIALOG SETTINGS:

MODEL GRAPH:

68
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

float j,sum=0.0 ; int n,k,i,a; for (i = 0 ; i<PTS ; i++) { w[i].real = cos(2*PI*i/(PTS*2.0)); w[i].imag =-sin(2*PI*i/(PTS*2.0)); } for(i=0,j=0;i<PTS;i++) { x[i] = sin(2*PI*5*i/PTS); samples[i].real=0.0; samples[i].imag=0.0; } /************Auto Correlation of X(n)=R(t) *****************/ for(n=0;n<PTS;n++) { { sum=0; for(k=0;k<PTS-n;k++) sum=sum+(x[k]*x[n+k]); // Auto Correlation R(t) } iobuffer[n] = sum; } /**************** FFT of R(t) ***********************/ for (i = 0 ; i < PTS ; i++) { samples[i].real=iobuffer[i]; } for (i = 0 ; i < PTS ; i++) samples[i].imag = 0.0; FFT(samples,PTS); for (i = 0 ; i < PTS ; i++) { x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag); } } C-SOURCE CODE FOR FFT.C #define PTS 128 extern COMPLEX w[PTS]; void FFT(COMPLEX *Y, int N) { COMPLEX temp1,temp2; int i,j,k; int upper_leg, lower_leg;
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

// set up twiddle constants in w //Re component of twiddle constants /*Im component of twiddle constants*/ // Signal x(Fs)=sin(2*pi*f*i/Fs);

//swap buffers //buffer with new data //imag components = 0 //call function FFT.c //compute magnitude

//# of points for FFT //twiddle constants stored in w //input sample array, # of points //temporary storage variables //loop counter variables //index of upper/lower butterfly leg
69

typedef struct {float real,imag;} COMPLEX;

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

GRAPH PROPERTY DIALOG SETTINGS:

MODEL GRAPH:

70
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

int leg_diff; int num_stages = 0; int index, step; i = 1; do { num_stages +=1; i = i*2; }while (i!=N); leg_diff = N/2; step = (PTS*2)/N; for (i = 0;i < num_stages; i++) { index = 0; for (j = 0; j < leg_diff; j++) {

//difference between upper/lower leg //number of FFT stages (iterations) //index/step through twiddle constant //log(base2) of N points= # of stages

//difference between upper&lower legs //step between values in twiddle.h // 512 //for N-point FFT

for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff)) { lower_leg = upper_leg+leg_diff; temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real; temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag; temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real; temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg]).real = temp2.real*(w[index]).real -temp2.imag*(w[index]).imag; (Y[lower_leg]).imag = temp2.real*(w[index]).imag +temp2.imag*(w[index]).real; (Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag = temp1.imag; } index += step; } leg_diff = leg_diff/2; } j = 0; for (i = 1; i < (N-1); i++) { k = N/2; while (k <= j) {
71
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

step *= 2; //bit reversal for resequencing data

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

72
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

j = j - k; k = k/2; } j = j + k; if (i<j) { temp1.real = (Y[j]).real; temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real; (Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real; (Y[i]).imag = temp1.imag; } } return; }

RESULT:

73
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT:

74
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

TO FIND THE FFT OF GIVEN 1-D SIGNAL AND PLOT


AIM: To find the FFT of a given 1-D signal and plot the graph. TOOLS REQUIRED: TMS 320 C6713Kit, Code Composer Studio Software, Personal Computer PROCEDURE: 1. Create a Project in Code Composer Studio. 2. Create Source files in C language for Main.C and FFT.C and add them to the project. 3. Add both hello.cmd & rts6700.lib files to the current project folder from the following locations: C:\CCStudio\tutorial\dsk6713\hello1 and C:\CCStudio\c6000\cgtools\lib 4. Compile C file for debugging errors. 5. Build the project. 6. Load Program (.out file) into DSK from file menu. 7. Run the program from Debug menu. 8. Plot the Graph for input and output from View graph menu. C SOURCE CODE FOR MAIN.C #include <math.h> #define PTS 128 #define PI 3.14159265358979 typedef struct {float real,imag;} COMPLEX; void FFT(COMPLEX *Y, int n); float iobuffer[PTS]; float x1[PTS]; short i; short buffercount = 0; short flag = 0; COMPLEX w[PTS]; COMPLEX samples[PTS]; main() { for (i = 0 ; i<PTS ; i++) { w[i].real = cos(2*PI*i/(PTS*2.0));
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

//# 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

// set up twiddle constants in w //Re component of twiddle constants


75

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

76
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

w[i].imag =-sin(2*PI*i/(PTS*2.0)); } for (i = 0 ; i < PTS ; i++) {

//Im component of twiddle constants //swap buffers /*10- > freq,100 -> sampling freq*/

iobuffer[i] =sin(2*pi*5*i/(PTS)); samples[i].real=0.0; samples[i].imag=0.0;

} for (i = 0 ; i < PTS ; i++) { samples[i].real=iobuffer[i]; iobuffer[i] = x1[i]; } for (i = 0 ; i < PTS ; i++) samples[i].imag = 0.0; FFT(samples,PTS); for (i = 0 ; i < PTS ; i++) { x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag); } } C SOURCE CODE FOR FFT.C #define PTS 128 //# of points for FFT typedef struct {float real,imag;} COMPLEX; extern COMPLEX w[PTS]; void FFT(COMPLEX *Y, int N) { COMPLEX temp1,temp2; int i,j,k; int upper_leg, lower_leg; int leg_diff; int num_stages = 0; int index, step; i = 1; do { num_stages +=1; i = i*2;
77
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

//swap buffers //buffer with new data //processed frame to iobuffer

//imag components = 0 //call function FFT.c //compute magnitude

///32;

//twiddle constants stored in w //input sample array, # of points //temporary storage variables //loop counter variables //index of upper/lower butterfly leg //difference between upper/lower leg //number of FFT stages (iterations) //index/step through twiddle constant //log(base2) of N points= # of stages

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

78
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

}while (i!=N); leg_diff = N/2; step = (PTS*2)/N; for (i = 0;i < num_stages; i++) { index = 0; for (j = 0; j < leg_diff; j++) { for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff)) { lower_leg = upper_leg+leg_diff; temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real; temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag; temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real; temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg]).real = temp2.real*(w[index]).real (Y[lower_leg]).imag = temp2.real*(w[index]).imag (Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag = temp1.imag; } index += step; } leg_diff = leg_diff/2; step *= 2; } j = 0; for (i = 1; i < (N-1); i++) { k = N/2; while (k <= j) { j = j - k; k = k/2; } j = j + k; if (i<j) { temp1.real = (Y[j]).real;
79
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

//difference between upper&lower legs //step between values in twiddle.h // 512 //for N-point FFT

-temp2.imag*(w[index]).imag; +temp2.imag*(w[index]).real;

//bit reversal for resequencing data

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

80
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real; (Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real; (Y[i]).imag = temp1.imag; } } return; }

RESULT:

81
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT:
UNIT SAMPLE SEQUENCE 1 amplitud

0.5

0 -5

5 time DELAYED UNIT SAMPLE SEQUENCE

10

15

1 amplitud

0.5

0 -5

0 time

10

15

OUTPUT:
UNIT STEP SEQUENCE 1 amplitud

0.5

0 -5

5 time DELAYED UNIT STEP SEQUENCE

10

15

1 amplitud

0.5

0 -5

0 time

10

15

82
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

BASIC SIGNALS GENERATION USING MATLAB


AIM: Generation of basic signals using MATLAB. TOOLS REQUIRED: MATLAB Software, Personal Computer. MATLAB PROGRAM FOR UNIT SAMPLE SEQUENCE: n = -5:15; g = [zeros(1,5) 1 zeros(1,15)]; h = [zeros(1,10) 1 zeros(1,10)]; subplot(2,1,1); stem(n,g); xlabel('time index'); ylabel('amplitude'); title('UNIT SAMPLE SEQUENCE'); axis([-5 15 0 1.2]); subplot(2,1,2); stem(n,h); xlabel('time index'); ylabel('amplitude'); title(' DELAYED UNIT SAMPLE SEQUENCE'); axis([-5 15 0 1.2]); MATLAB PROGRAM FOR UNIT STEP SEQUENCE: n = -5:15; i = [zeros(1,5) ones(1,6) zeros(1,10)]; j = [zeros(1,10) ones(1,6) zeros(1,5)]; subplot(2,1,1); stem(n,i); xlabel('time index'); ylabel('amplitude'); title(' UNIT STEP SEQUENCE'); axis([-5 15 0 1.2]); subplot(2,1,2); stem(n,j);

83
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Graph:

84
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

xlabel('time index'); ylabel('amplitude'); title(' DELAYED UNIT STEP SEQUENCE'); axis([-5 15 0 1.2]); MATLAB PROGRAM FOR SINE WAVE: clc; clear all; close all; t=0:.2:10; y=sin(2*pi*t/5); subplot(2,1,1); plot(t,y); xlabel('time index'); ylabel('amplitude'); title('SINE WAVE'); subplot(2,1,2); stem(t,y); xlabel('time index'); ylabel('amplitude'); title('SINE WAVE');

85
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT:

OUTPUT:
UNIT RAMP 1 amplitud

0.5

0.1

0.2

0.3

0.4

0.5 time UNIT RAMP

0.6

0.7

0.8

0.9

1 amplitud

0.5

0.1

0.2

0.3

0.4 time

0.5

0.6

0.7

0.8

0.9

86
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

MATLAB PROGRAM FOR RAMP SIGNAL: clc; clear all; close all; m=1; t=0:.1:1; y=m*t; subplot(2,1,1); plot(t,y); xlabel('time index'); ylabel('amplitude'); title('UNIT RAMP'); subplot(2,1,2); stem(t,y); xlabel('time index'); ylabel('amplitude'); title('UNIT RAMP'); MATLAB PROGRAM FOR TRIANGULAR WAVE: clc; clear all; close all; m=-1; t=0:1:10; y=m.^t; subplot(2,1,1); plot(t,y); xlabel('time index'); ylabel('amplitude'); title('TRIANGULAR WAVE'); subplot(2,1,2); stem(t,y); xlabel('time index'); ylabel('amplitude'); title('TRIANGULAR WAVE');

87
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT:

TRIANGULAR WAVE 1 0.5 amplitude 0 -0.5 -1

5 6 time index TRIANGULAR WAVE

10

1 amplitude 0.5 0 -0.5 -1

5 time index

10

Graph:

88
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Result:

89
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

OUTPUT:

10 d[n] s[n] x[n]

amplitude

-5

10

15

20

25 30 time index

35

40

45

50

8 6 y[n] s[n]

amplitude

4 2 0

10

15

20

25 30 time index

35

40

45

50

90
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Expt.No:

Date:

MATLAB PROGRAM FOR SIGNAL SMOOTHING

AIM: Write a program for signal smoothing using MATLAB TOOLS REQUIRED: MATLAB Software, Personal Computer. PROGRAM: clc; clear all; close all; R = 51; d = 0.8*(rand(R,1) - 0.5); m = 0:R-1; s = 2*m.*(0.9.^m); x = s+d'; subplot(2,1,1); plot(m,d','r-',m,s,'g-',m,x,'b-.'); xlabel('time index'); ylabel('amplitude'); legend('d[n]','s[n]','x[n]'); grid; x1 = [0 0 x]; x2 = [0 x 0]; x3 = [x 0 0]; y = (x1 + x2 + x3)/3; subplot(2,1,2); plot(m,y(2:R+1),'r-',m,s,'g-.'); legend('y[n]','s[n]'); xlabel('time index'); ylabel('amplitude'); grid;
Result:

91
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

DIGITAL SIGNAL PROCESSING LAB

Dept. of ECE

Graph:

92
SRI SAI ADITYA INSTITUTE OF SCIENCE & TECHNOLOGY

You might also like