You are on page 1of 65

DSP LAB

EEE

MAHENDRA ENGINEERING COLLEGE MAHENDRAPURI, MALLASAMUDRAM (WEST), NAMAKKAL Dt - 637503

DEPARTMENT OF ECE

DIGITAL SIGNAL PROCESSING LABORATORY

Observation Manual
Name: _________________________ Reg. No.: ______________________

Class: _____________________

DSP LAB

EEE

DIGITAL SIGNAL PROCESSING LABORATORY


EXTRACT OF UNIVERSITY SYLLABUS

LIST OF EXPERIMENTS:
USING MATLAB CODES:

1. Representation of basic signals. 2. Verification of sampling theorem. 3. Computation of Circular Convolution. 4. Checking stability of LTI systems. 5. Finding Fast Fourier Transform. 6. Design Chebyshev analog and Digital filters. 7. Design of Butterworth analog and Digital filters. 8. Design and analysis of FIR filter using windows

USING TMS320C5X/54XX:

1. Generation of Signals 2. Linear Convolution 3. Implementation of a FIR filter 4. Implementation of an IIR filter 5. Calculation of FFT

DSP LAB

EEE

DIGITAL SIGNAL PROCESSING LABORATORY


Exp. No. Experime nt Name CYCLE 1: DSP USING MATLAB 1 2 3 4 5 6 7 8 Marks (15) Staff Sign

Representation of basic signals. Verification of sampling theorem. Computation of Circular Convolution. Checking stability of LTI systems Finding Fast Fourier Transform Design Chebyshev analog and Digital filters Design of Butterworth analog and Digital filters Design and analysis of FIR filter using windows
CYCLE 2: DSP USING TMS320C5X

1 2 3 4 5

GENERATION OF SIGNALS LINEAR CONVOLUTION IMPLEMENTATION OF A FIR FILTER IMPLEMENTATION OF IIR FILTER CALCULATION OF FFT

AVERAGE:

STAFF-IN CHARGE

DSP LAB

EEE

INTRODUCTION
WHAT IS MATLAB? MATLAB is a high-performance language for technical computing. Itintegrates computation, visualization, and programming in an easy-to-useenvironment where problems and solutions are expressed in familiar mathematical notation. Typical ses include: Math and computation Algorithm development Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including graphical user interface building MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar non interactive language such as C or Fortran. The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects, which together represent the state-of-the-art in software for matrix computation. MATLAB has evolved over a period of years with input from many users. In university environments, it is the standard instructional tool for introductory and advanced courses in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for high-productivity research, development, and analysis. MATLAB features a family of application-specific solutions called toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn and apply specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are available include signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many others.

DSP LAB

EEE

Hierarchy of arithmetic operations:


First Second Third Fourth Example:
>> 1/(2+3^2)+4/5*6/7 ans = 0.7766

The contents of all parentheses are evaluated first, starting from the innermost parentheses and working outward All exponentials are evaluated, working from left to right All multiplications and divisions are evaluated, working from left to right All additions and subtractions are evaluated, starting from left to right

Basic Notations in MATLAB


xlabel(time); ylabel(amplitude); title(xxxxx); clear; clear all; clc; plot(x,y) axis tight; zeros(m,n) fliplr abs % label the x-axis with time % label the y-axis with amplitude % put a title on the plot % clears the workspace, all variables are removed. % clears all variables and functions from work space. % clears command window, command history is lost. % plot x Vs y. % set tight scale on axes. % returns an m by n matrix of zeros. % flips a matrix from left to right. % absolute value. Exp: abs(A) produces a matrix of absolute values |Aij| % phase angle % complex conjugate % converts character arrays using automatic padding. % create vector x % create vector b

angle conj abs x=0:.1:20; b=[2;3;5];

DSP LAB

EEE

The graphical interface to the MATLAB workspace

DSP LAB
Ex. No. : 1 Date:

EEE

REPRESENTATION OF BASIC SIGNALS

Aim:
To write a MATLAB program to generate various input Waveforms.

Hardware/software requirement S.NO


1 2

Hardware/software
PC with XP operating system. Matlab 2007b

1. Unit Impulse response Algorithm:


STEP 1: Start the program. STEP 2: Get the range of sequence n1, s1 for various signals STEP 3: Generate the unit impulse response STEP 4: Plot the sequence by taking n1 along x axis and s1alone y axis. STEP 5: Stop the program.

P rogram:
clc; clear all; close all; s1=[zeros(1,20) 1 zeros(1,20)]; n1=-20:20; subplot(2,2,1); stem(n1,s1); grid on; title('Unit Impulse Function'); xlabel('time'); ylabel('amplitude');

DSP LAB 2. Unit step response Algorithm:


STEP 1: STEP 2: STEP 3: STEP 4: Start the program. Get the range of sequence n2, s2 for various signals Generate the unit step response Plot the sequence by taking n2 along x axis and s2 along y axis STEP 5: Stop the program

EEE

P rogram:
clc; clear all; close all; s2=[zeros(1,20) ones(1,21)]; n2=-20:20; subplot(2,2,2); stem(n2,s2); grid on; title('Unit Step Function'); xlabel('time'); ylabel('amplitude');

3. Unit Ramp function Algorithm


STEP 1: STEP 2: STEP 3: STEP 4: Start the program. Get the range of sequence n3, s3 for various signals Generate the unit ramp response Plot the sequence by taking n3 along x axis and s3 along y axis STEP 5: Stop the program

DSP LAB

EEE

Program:
clear all; close all; s3=[zeros(1,20) 0:20]; n3=-20:20; subplot(2,2,3); stem(n3,s3); grid on; title('Unit Ramp Function'); xlabel('time'); ylabel('amplitude');

4. Exponential function Algorithm:


STEP 1: STEP 2: STEP 3: STEP 4: Start the program. Get the range of sequence n4, s4 for various signals Generate the unit impulse response Plot the sequence by taking n4 along x axis and s4 along y axis. STEP 5: Stop the program

P rogram:
clear all; close all; n4=0:0.01:1; s4=exp(n4); subplot(2,2,4); stem(n4,s4); grid on; title('Exponential Function'); xlabel('time'); ylabel('amplitude');

DSP LAB 5. Cosine function Algorithm

EEE

STEP 1 : Start the program. STEP 2 : Get the range of sequence n5, s5 for various signals STEP 3 : Generate the cos wave using function of cos expression

s5=a*cos(2*n5*pi*c);
STEP 4 : Plot the sequence by taking n5 along x axis and s5 . along y axis STEP 5: Stop the program

Program:
clear all; close all; f=input('Enter the frequency of value:'); f1=input ('Enter the sampling freq:'); a=input ('Enter the amplitude of freq:'); c=f/f1; n5=0:0.1:10; s5=a*cos(2*n5*pi*c); plot(n5,s5); title('Cosine wave generation'); xlabel('Time in milliseconds'); ylabel('Amplitude' );

6. Sin Function: Algorithm


STEP 1 : Start the program. STEP 2 : Get the range of sequence n6, s6 for various signals STEP 3 : Generate the cos wave using function of cos expression

s6=sin(2*pi*t6);
STEP 4 : Plot the sequence by taking n6 along x axis and s6 along y axis. STEP 5: Stop the program

DSP LAB Program:


clear all; close all; t6=0:.01:pi; s6=sin(2*pi*t6); plot(t6,s6); title('sine sequence'); ylabel('amplitude'); xlabel('time'); 7. SAWTOOTH FUNCTION:

EEE

Algorithm
STEP 1: STEP 2: STEP 3: STEP 4: Start the program. Get the range of sequence n7, s7 for various signals Generate the saw tooth wave Plot the sequence by taking n7 along x axis and s7 along y axis. STEP 5: Stop the program

Program
clear all; close all; n7=0:0.1:5; s7=sawtooth(2*pi*n7); subplot(2,2,3); stem(n7,s7); grid on; title('sawtooth Function'); xlabel('time'); ylabel('amplitude');

DSP LAB

EEE

8. Square Function
Algorithm:
STEP 1 : STEP 2 : STEP 3 : STEP 4 : . Start the program. Get the range of sequence n8, s8 for various signals Generate the square wave Plot the sequence by taking n8 along x axis and s8 along y axis STEP 5: Stop the program

Program:
clear all; close all; n8=0:0.1:1; s8=square(2*pi*5*n8); subplot(2,2,4); stem(n8,s8); grid on; title('Square Function'); xlabel('time'); ylabel('amplitude');

PROCEDURE:
1. 2. 3. 4. 5. Open the MATLAB. Create a edit window Type the relevant programs. Save the file Run the program by using icon (or) select debug and select Run (or) press F5. 6. If any error present in the program, it will be displayed in the. command prompt >> 7. To check the errors and rectify that errors in the program again run the program. 8. If no error occurs, the output waveform will be obtained. Print the output

DSP LAB
VIVA QUESTION:

EEE

RESULT:

DSP LAB Ex. No. : 2 Date: Aim:

EEE VERIF ICATION OF SAMPLING THEOREM

To write the program for verification of sampling theorem using MATLAB.

Hardware/software requirement
S.NO 1 2 Hardware/software PC with XP operating system. Matlab 2007b

Algorithm:

DSP LAB Program:


clear; close all; clc; T=5; Np=512; t =linspace(0,T,Np+1); f=2; x=sin(2*pi*f*t); N=8; Ts=T/N; fs=1/Ts; ts=Ts*(0:N-1); xs=sin(2*pi*f*ts); h=round(f/fs); fapp=f-h*fs; xa=sin(2*pi*fapp*t); figure; plot(t,x,'r-',ts,xs,'b*',t,xa,'m-'); title('Signal sampling at 1.6 Hz'); axis tight; xlabel('time'); ylabel('signal value'); N=16; Ts=T/N; Fs=1/Ts; ts=Ts*(0:N-1); xs=sin(2*pi*f*ts); h=round(f/fs); fapp=f-h*fs; xa=sin(2*pi*fapp*t); figure; plot(t,x,'r-',ts,xs,'b*',t,xa,'m-'); title('Signal sampling at 3.2 Hz'); axis tight; xlabel('time'); ylabel('signal value');

EEE

DSP LAB
N=32; Ts=T/N; Fs=1/Ts; ts=Ts*(0:N-1); xs=sin(2*pi*f*ts); h=round(f/fs); fapp=f-h*fs; xa=sin(2*pi*fapp*t); figure; plot(t,x,'r-',ts,xs,'b*',t,xa,'m-'); title('Signal sampling at 6.4 Hz'); axis tight; xlabel('time'); ylabel('signal value');

EEE

PROCEDURE:
1. 2. 3. 4. 5. 6. 7. 8. 9. Open the MATLAB. Create a new file from file menu. Click new and select M-file. Type the relevant programs. Save the file. Run the program by using icon (or) select debug and select Run (or) press F5 If any error present in the program, it will be displayed in the command prompt >> . To check the errors and rectify that errors in the program again run the program If no error occurs, the output waveform will be obtained. Print the output.

DSP LAB Viva voice:

EEE

Result:

DSP LAB
Ex. No. : 3 Date:

EEE

CIRCULAR CONVOLUTION

Aim:
To write a program for circular convolution using MATLAB.

Hardware/software requirement:
S.NO 1 2 Hardware/software PC with XP operating system. Matlab 2007b

Algorithm:
1. Enter the value for n and x(n). 2. Make the length of the sequence equal. 3. Compute the convolution using shift value. 4. Plot the result.

Program:
%Program for Circular Convolution

clear all; N=input ('enter the values of n:'); disp('enter the values for x(n):'); for i1=1:N x(i1)=0; x1(i1)=0; h(i1)=0; end; for i1=1:N x(i1)=input ('enter value:'); end; disp('enter the value for h(n):'); for i1=1:N

DSP LAB
h(i1)=input ('enter the value:'); end; k1=0; j1=0; for g1=1:N i1=0; a=0; for m1=1:N; j1=j1+1; i1=i1+1; a=a+(x(i1)*h(j1)); if N==j1 j1=0; end; end; disp(a); k1=k1+1; j1=k1; if N==k1 break; end; end;

EEE

procedure:
1. Open the MATLAB. 2. Create a new file from file menu. Click new and select M-file. 3. Type the relevant programs. 4. Save the file. 5. Run the program by using icon (or) select debug and select 6.Run (or) press F5. 7. If any error present in the program, it will be displayed in the command prompt >> . 8. To check the errors and rectify that errors in the program again run the program. 9. If no error occurs, the output waveform will be obtained. 10. Print the output

DSP LAB

EEE

Viva -voice

Result:

DSP LAB
Ex. No. : 4 Date:

EEE

CHECKING STABILITY OF LTI SYSTEMS.

Aim:
To write a MATLAB program for to check the stability of a system

Hardware/software requirement:
S.NO 1 2 Hardware/software PC with XP operating system. Matlab 2007b

Algorithm:
STEP 1: Start the program STEP 2: Get the Input as Numerator and Denominator Coefficients STEP 3: Convert the transfer function to pole zero plot STEP 4: Find the Absolute values of the poles. STEP 5: Check whether it is greater than unity, if so display Unstable system, or else, display it as stable system STEP 6: If the values lies on the circle, Display as conditionally stable system

Program:
%Program to find a system as stable or unstable system clc; close all; clear all; a=input('enter the numerator of H(z):'); b=input('enter the denominator of H(z):'); zplane(a,b);

DSP LAB
[z,p,u]=tf2zp(a,b); c=length(p); r=abs(p); x=0; if c==0; x=1; else for i=1:c; if r(i)>1; x=x+2; elseif r(i)==1; x=x+1; disp('conditionally stable'); break; end end if x>1; disp('unstable system'); elseif x==0; disp('condition is stable'); end end

EEE

Procedure:
1. Open the MATLAB. 2. Create a new file from file menu. Click new and select M-file. 3. Type the relevant programs. 4. Save the file.

DSP LAB

EEE
5. Run the program by using icon (or) select debug and select 6.Run (or) press F5. 7. If any error present in the program, it will be displayed in the command prompt >> . 8. To check the errors and rectify that errors in the program again run the program. 9. If no error occurs, the output waveform will be obtained. 10. Print the output

Viva voice:

RESULT:

DSP LAB Ex. No. : 5 Date: Aim:

EEE CALCULATION OF FFT OF A SIGNAL

To write a MATLAB program for computing FFT of a signal using DIF.

Hardware/software requirement:
S.NO 1 2 Hardware/software PC with XP operating system. Matlab 2007b

Algorithm:
STEP 1: Start the process STEP 2: Get the Input sequence. STEP 3: Compute the Real and Imaginary parts of the spectrum STEP 4: Calculate the FFT STEP 5: Plot the Amplitude and Frequency in x & y axis respectively STEP 6: Stop the program

Program:
%Program For Computation of FFT Using DIF clear all; close all; disp('Decimation in frequency'); disp(' Input in normal order'); disp(' ************************'); n=input ('Enter n points:'); for i1=1:n x0(i1)=input('Enter a number'); x1(i1)=0; end; m=log2(n);

DSP LAB
for(i1=1:m) p1=n/(2^i1); p=n/(p1*2); q=n/p; for j1=1:q:n r=j1; for k=1:q/2 a=x0(r); b=x0(r+(q/2)); w=cos(2*pi*(k-1)/q)-j*sin(2*pi*(k-1)/q); c=a+b; d=(a-b)*w; x1(r)=c; x1(r+(q/2))=d; r=r+1; end; end; x0=x1; x2=x1; x1=0; end; disp('Output in scrambled order:'); disp( ' n point DIF of radix 2 is:'); disp(x2);

EEE

Procedure:
1. Open the MATLAB. 2. Create a new file from file menu. Click new and select M-file. 3. Type the relevant programs. 4. Save the file. 5. Run the program by using icon (or) select debug and select 6.Run (or) press F5. 7. If any error present in the program, it will be displayed in the command prompt >> . 8. To check the errors and rectify that errors in the program again run the program. 9. If no error occurs, the output waveform will be obtained. 10. Print the output

DSP LAB

EEE

Viva -voice

Result:

DSP LAB

EEE

Ex. No. : 6 Date: Aim:

DESIGN CHEBYSHEV ANALOG AND DIGITAL FILTERS

To write a program to design a chebyshev low pass filter 1. Impulse invariant method 2. Bilinear Transform using MATLAB.

Hardware/software requirement :
S.NO 1 2 Hardware/software PC with XP operating system. Matlab 2007b

Algorithm:
1. Get the all the gain & band frequency 2. Select the method by switch case 3. Plot the magnitude & phase response for Each method

Program:
% Program For Chebyshev Filter wp=input('Enter the passband frequency:'); ws=input('Enter the stopband frequency:'); r1=input('Enter the passband gain in db:'); r2=input('Enter the stopband gain in db:'); disp('1-bilinear;2-impulse invariance method'); choice=input('enter the choice'); switch(choice) case 1, % Bilinear Method

DSP LAB
[n,wn]=cheb1ord(wp,ws,r1,r2,'s'); [z,p,k]=cheb1ap(n,.9976); [num,den]=zp2tf(z,p,k); [numt,dent] = lp2lp(num,den,wn); [bz,az]=bilinear(numt,dent,1) [h,w]=freqz(bz,az,512); plot(w/pi,20*log10(abs(h)));grid; title('Chebyshez lowpass filter(Bilinear)'); xlabel('Normalised frequency'); ylabel('Gain-db'); case 2, % Impulse Invariance Method [n,wn]=cheb1ord(wp,ws,r1,r2,'s'); [z,p,k]=cheb1ap(n,.7648); [num,den]=zp2tf(z,p,k); [numt,dent] = lp2lp(num,den,wn); [bz,az]=impinvar(numt,dent,1) [h,w]=freqz(bz,az,512); plot(w/pi,20*log10(abs(h)));grid; title('Chebyshez lowpass filter(Impluse invariance)'); xlabel('Normalised frequency'); ylabel('Gain-db'); end;

EEE

Procedure:
1. Open the MATLAB. 2. Create a new file from file menu. Click new and select M-file. 3. Type the relevant programs. 4. Save the file. 5. Run the program by using icon (or) select debug and select 6.Run (or) press F5. 7. If any error present in the program, it will be displayed in the command prompt >> . 8. To check the errors and rectify that errors in the program again run the program. 9. If no error occurs, the output waveform will be obtained. 10. Print the output

DSP LAB

EEE

VIVA QUESTION:

RESULT:

DSP LAB Ex. No. : 7 Date: Aim:


To write a program for Butterworth low pass filter by i)
ii)

EEE

DESIGN OF BUTTERWORTH ANALOG AND DIGITAL FILTERS

Impulse invariant method Bilinear Transform using MATLAB

Hardware/software requirement :
S.NO 1 2 Hardware/software PC with XP operating system. Matlab 2007b

Algorithm:
a. Get the all the gain & band frequency b. Select the method by switch case c. Plot the magnitude & phase response for Each method

Program:
%Program For Butterworth low pass Filter

clc; clear all; close all; wp=input('Enter the passband frequency :'); ws=input('Enter the stopband frequency :'); r1=input('Enter the passband gain in db :'); r2=input('Enter the stopband gain in db :'); disp('1-bilinear ; 2-impulse invariance method');

DSP LAB
choice=input('enter the choice'); switch(choice)

EEE

case 1, %Bilinear Method [n,wn]=buttord(wp,ws,r1,r2,'s'); [z,p,k]=buttap(n); [num,den]=zp2tf(z,p,k); [numt,dent] = lp2lp(num,den,wn); [bz,az]=bilinear(numt,dent,1); [h,w]=freqz(bz,az,512); plot(w/pi,20*log10(abs(h))); grid; title('Butterworth lowpass filter(Bilinear)'); xlabel('Normalised frequency'); ylabel('Gain-db'); case 2, % Impulse Invariance Method [n,wn]=buttord(wp,ws,r1,r2,'s'); [z,p,k]=buttap(n); [num,den]=zp2tf(z,p,k); [numt,dent] = lp2lp(num,den,wn); [bz,az]=impinvar(numt,dent,1); [h,w]=freqz(bz,az,512); plot(w/pi,20*log10(abs(h))); grid; title('Butterworth lowpass filter(Impluse invariance)'); xlabel('Normalised frequency'); ylabel('Gain-db'); end;

DSP LAB

EEE

Procedure:
1. Open the MATLAB. 2. Create a new file from file menu. Click new and select M-file. 3. Type the relevant programs. 4. Save the file. 5. Run the program by using icon (or) select debug and select Run (or) press F5. 6. If any error present in the program, it will be displayed in the command prompt >> . 7. To check the errors and rectify that errors in the program again run the program. 8. If no error occurs, the output waveform will be obtained. 9. Print the output

DSP LAB

EEE

Viva -voice

Result:

DSP LAB

EEE

Ex. No. : 8 Date:

DESIGN AND ANALYSIS OF FIR FILTER USING WINDOWS

Aim:
To write a MATLAB program to design a FIR filter by using Windowing techniques.

Hardware/software requirement:
S.NO 1 2 Hardware/software PC with XP operating system. Matlab 2007b

Algorithm:
1. 2. 3. 4. Get the order of the filter Get the coefficients of the filter Calculate frequency response by using window functions Plot the frequency response

Program:
%Program For Designing FIR Filter Using Windowing Techniques N=input('Enter the order of the filter :'); Wc=input ('Enter the coefficients of the filter:'); r=fir1(N,Wc,boxcar(N+1)); figure (1); [h,o]=freqz(r,1,N); subplot(2,2,1); plot(o/pi,abs(h)); grid; title('Rectangular Windowing Technique'); xlabel('Normalised Frequency'); ylabel('Magnitude'); subplot(2,2,2);

DSP LAB
plot(o/pi,20*log(abs(h))); grid; xlabel('Normalised frequency'); ylabel('Magnitude'); x=fir1(N,Wc,hamming(N+1)); figure (2); [h,o]=freqz(x,1,N); subplot(2,2,1); plot(o/pi, 20*log10(abs(h))); grid; title('Hamming windowing technique'); xlabel('Normalised frequency'); ylabel('Magnitude'); subplot(2,2,2); plot(o/pi,20*log(abs(h))); grid; xlabel('Normalised frequency'); ylabel('Magnitude'); y=fir1(N,Wc,hanning(N+1)); figure (3); [h,o]=freqz(y,1,N); subplot(2,2,1); plot(o/pi,abs(h)); grid; title('hanning windowing technique'); xlabel('normalised frequency'); ylabel('magnitude'); subplot(2,2,2); plot(o/pi,20*log(abs(h))); grid; xlabel('normalised frequency'); ylabel('magnitude');

EEE

DSP LAB

EEE

Procedure:
1. Open the MATLAB. 2. Create a new file from file menu. Click new and select M-file. 3. Type the relevant programs. 4. Save the file. 5. Run the program by using icon (or) select debug and select Run (or) press F5. 6. If any error present in the program, it will be displayed in the command prompt >> . 7. To check the errors and rectify that errors in the program again run the program. 8. If no error occurs, the output waveform will be obtained. 9. Print the output

DSP LAB

EEE

Viva voice:

Result:

DSP LAB

EEE

EXPERIMENTS USING DSP PROCESSOR TMS320C5X


Exp No: 1 Date : __/__/__

GENERATION OF SIGNALS Aim:


To write a program for generation of various input signals & verify by using DSP processor kit (TMS320C5X).

Equipments Required:
1. 2. 3. 4. TMS320C5X CRO DAC Function Generator -1 -1 -1 -1

PROGRAM (Sine Waveform Generation)


TXD .SET STS .SET DATA .SET TEMP .SET B3 .SET B2 .SET B1 .SET B0 .SET .mmregs .text START: LDP #100H LACC #TABLE SACL TEMP REP1: LACC #TABLE SACL TEMP LAR AR0,#372 REP: 0H 1H 2H 3H 0F000H 0F00H 00F0H 000FH

DSP LAB
LACC TEMP TBLR DATA OUT DATA,04H LACC TEMP ADD #1H SACL TEMP MAR *,AR0 BANZ REP,*B REP1 HLT: B HLT

EEE

PROGRAM (Cosine Waveform Generation):


.mmregs .text start: ldp lacc loop: sacl rpt out cmpl b .end

#100h #0fffh ;change this value for amplitude. 0 #0ffh ;change this value for frequency. 0,04H ;address for dac. loop

PROGRAM (Triangular Waveform Generation): .mmregs .text START: LDP REP: SPLK #0,DATA LAR AR0,#60 REPH: OUT LACC ADD SACL BANZ DATA,04H DATA #40H DATA REPH,*#100H

DSP LAB
LAR REPL: OUT LACC SUB SACL MAR BANZ B B DATA,04H DATA #40H DATA *,AR0 REPL,*AR0,#60

EEE

HLT:

REP HLT

Procedure:
1. Connect the Interface Card AD12N to TMS320C5X. 2. Enter the Program & Execute. 3. Observe the output at DAC using CRO. 4.Plot the Waveform

DSP LAB Viva voice

EEE

Result:

DSP LAB
Exp No: 2 Date : _ _/_ _/_ _

EEE

LINEAR CONVOLUTION Aim:


To write a program linear convolution and verify by using DSP processor kit (TMS320C5X).

Equipments Required:
1. TMS320C5X 2. DAC -1 -1

Procedure:
1. Connect the Interface Card AD12N to TMS320C5X. 2. Enter the Program & Execute. 3. Observe the output using PC.

DSP LAB
PROGRAM FOR LINEAR CONVOLUTION .mmregs .text START: LDP #02H LAR AR1,#8100H ; x(n) datas lar ar0,#08200H ;h(n) datas LAR AR3,#8300H ;y(n) starting LAR AR4,#0007 ;N1+N2-1 ;to fold the h(n) values ;************************ lar ar0,#8203H ; data mem 8200 to program mem c100(tblw) lacc #0c100h mar *,ar0 rpt #3 tblw *- ;to move 8203- 8200 to c100- c103 ;padding of zerros for x(n) values ;********************************** lar ar6,#8104h mar *,ar6 lacc #0h rpt #3h sacl *+ ;convalution operation starts ;****************************** LOP: MAR *,AR1 LACC *+ SACL 050H ;starting of the scope of multiplication LAR AR2,#0153H ; end of the array, to be multiplied with h(n) {150+N1-1} MAR *,AR2 ZAP RPT #03H ;N1-1 times so that N1 times MACD 0C100H,*APAC ;to accmulate the final product sample MAR *,AR3 SACL *+ MAR *,AR4 BANZ LOP,*H: B H

EEE

DSP LAB
INPUT ( x(n) ) ;8100 - 1 ;8101 - 3 ;8102 - 1 ;8103 - 3 INPUT ( h(n) ) ; 8200 - 0 ; 8201 - 1 ; 8202 - 2 ; 8203 - 1 OUTPUT ( y(n) ) ; 8300 - 1 ; 8301 - 5 ; 8302 - 8 ; 8303 - 8 ; 8304 - 7 ; 8305 - 3 ; 8306 - 0

EEE

Result

DSP LAB

EEE

Exp No: 3 Date : _ _/_ _/_ _

IMPLEMENTATION OF A FIR FILTER Aim:


To write a program implementation of FIR Filter and verify by using DSP processor kit (TMS320C5X). i) FIR Low Pass Filter ii) FIR High Pass Filter iii) FIR Band Pass Filter iv) FIR Band Reject Filter

Equipments Required:
1. 2. 3. 4. TMS320C5X CRO -1 DAC -1 Function Generator -1

-1

Procedure:
1. 2. 3. 4. Connect the Interface Card AD12N to TMS320C5X. Enter the Program & Execute. Observe the output at DAC using CRO. Plot the Waveform.

DSP LAB
i) PROGRAM LOWPASS FILTER
START: MAR *,AR0 LAR AR0,#0200H RPT #33H BLKP CTABLE,*+ SETC CNF * Input data and perform convolution ISR: LDP #0AH LACC #0 SACL 0 OUT 0,05 ;pulse to find sampling frequency IN 0,06H LAR AR7,#0 ;change value to modify sampling freq. MAR *,AR7 BACK: BANZ BACK,*IN 0,4 NOP NOP NOP NOP MAR *,AR1 LAR AR1,#0300H LACC 0 AND #0FFFH SUB #800H SACL * LAR AR1,#333H MPY #0 ZAC RPT #33H MACD 0FF00H,*APAC LAR AR1,#0300H SACH * ;give as sach *,1 incase of overflow LACC * ADD #800h SACL * OUT *,4 LACC #0FFH SACL 0 OUT 0,05 NOP B ISR .end

EEE

DSP LAB
ii) PROGRAM HIGH PASS FILTER
START: MAR *,AR0 LAR AR0,#0200H RPT #33H BLKP CTABLE,*+ SETC CNF * Input data and perform convolution ISR: LDP #0AH LACC #0 SACL 0 OUT 0,05 ;pulse to find sampling frequency IN 0,06H LAR AR7,#0 ;change value to modify sampling freq. MAR *,AR7 BACK: BANZ BACK,*IN 0,4 NOP NOP NOP NOP MAR *,AR1 LAR AR1,#0300H LACC 0 AND #0FFFH SUB #800H SACL * LAR AR1,#333H MPY #0 ZAC RPT #33H MACD 0FF00H,*APAC LAR AR1,#0300H SACH * ;give as sach *,1 incase of overflow LACC * ADD #800H SACL * OUT *,4 LACC #0FFH SACL 0 OUT 0,05 NOP B ISR

EEE

DSP LAB
.end

EEE

iii) PROGRAM BAND PASS FILTER


START: MAR *,AR0 LAR AR0,#0200H RPT #33H BLKP CTABLE,*+ SETC CNF * Input data and perform convolution ISR: LDP #0AH LACC #0 SACL 0 OUT 0,05 ;pulse to find sampling frequency IN 0,06H LAR AR7,#0 ;change value to modify sampling freq. MAR *,AR7 BACK: BANZ BACK,*IN 0,4 NOP NOP NOP NOP MAR *,AR1 LAR AR1,#0300H LACC 0 AND #0FFFH SUB #800H SACL * LAR AR1,#333H MPY #0 ZAC RPT #33H MACD 0FF00H,*APAC LAR AR1,#0300H SACH * ;give as sach *,1 incase of overflow LACC * ADD #800H SACL * OUT *,4 LACC #0FFH SACL 0 OUT 0,05 NOP B ISR

DSP LAB
.end

EEE

IV)PROGRAM BAND REJECT FILTER


START: MAR *,AR0 LAR AR0,#0200H RPT #33H BLKP CTABLE,*+ SETC CNF * Input data and perform convolution ISR: LDP #0AH LACC #0 SACL 0 OUT 0,05 ;pulse to find sampling frequency IN 0,06H LAR AR7,#0 ;change value to modify sampling freq. MAR *,AR7 BACK: BANZ BACK,*IN 0,4 NOP NOP NOP NOP MAR *,AR1 LAR AR1,#0300H LACC 0 AND #0FFFH SUB #800H SACL * LAR AR1,#333H MPY #0 ZAC RPT #33H MACD 0FF00H,*APAC LAR AR1,#0300H SACH * ;give as sach *,1 incase of overflow LACC * ADD #800H SACL * OUT *,4 LACC #0FFH SACL 0 OUT 0,05 NOP B ISR

DSP LAB
.end

EEE

VIVA QUESTION:

RESULT:

DSP LAB

EEE

Exp No: 4 Date : _ _/_ _/_ _

IMPLEMENTATION OF IIR FILTER Aim:


To write a program implementation of IIR Filter and verify by using DSP processor kit. i) IIR Low Pass Filter ii) IIR High Pass Filter iii) IIR Band Pass Filter iv) IIR Band Reject Filter

Equipments Required:
1. 2. 3. 4. TMS320C5X CRO DAC Function Generator -1 -1 -1 -1

Procedure:
1. Connect the Interface Card AD12N to TMS320C5X. 2. Enter the Program & Execute. 3. Observe the output at DAC using CRO. 4. Plot the Waveform.

DSP LAB
i) PROGRAM IIR LOW PASS FILTER
.MMREGS .TEXT .SET 0 .SET 1 .SET 2 .SET 3 .SET 4 .SET 315eh .SET 4e9fh

EEE

TEMP INPUT T1 T2 T3 ; K M

; a = 2 * (355/113) * 1000 = 6283.18/1000 = 6.28 ;; divide by 1000 for secs ; K = aT/(1+aT) = 6.28*0.1 / (6.28*0.1+1) = 0.3857 ; M = 1/(1+aT) = 1 / (6.28*0.1+1) = 0.61425 ;convert to Q15 format ; K = K * 32767 = 12638.23 = 315Eh ; M = M * 32767 = 20127.12 = 4E9Fh ;Sampling Rate is 100 s & Cut off Frequency is 1 Khz LDP #100H LACC #0 SACL T1 SACL T2 SACL TEMP OUT TEMP,4 ;CLEAR DAC BEFORE START TO WORK LOOP: LACC #0 SACL TEMP OUT TEMP,5 ;OUTPUT LOW TO DAC2 TO CALCULATE TIMING ; IN TEMP,06 ;SOC ; LAR AR7,#30h ;CHANGE VALUE TO MODIFY SAMPLING FREQ. ;sampling rate 100 s. MAR *,AR7 BACK: BANZ BACK,*; IN INPUT,4 ;INPUT DATA FROM ADC1 NOP NOP ; LACC INPUT AND #0FFFH

DSP LAB
SUB #800h SACL INPUT ; LT INPUT MPY #K PAC SACH T1,1 LT T2 ;PREVIOUS RESULT IN T2 MPY #M PAC SACH T3 ,1 LACC ADD SACL ADD SACL OUT ; LACC #0FFH SACL TEMP OUT TEMP,5 ; B LOOP T1 T3 T2 #800h TEMP TEMP,4

EEE

;OUTPUT FILTER DATA TO DAC1

;OUTPUT HIGH TO DAC2 TO CALCULATE TIMING

DSP LAB
ii) PROGRAM IIR HIGH PASS FILTER
.MMREGS .TEXT START: LDP #100H LACC #00H SACL 00H SACL 01H SACL 02H SACL 03H SACL 04H SACL 05H LOOP: LACC #00H SACL 00H IN 0,06H LAR AR7,#30H MAR *,AR7 BACK: BANZ BACK,*; LT 01H ; MPY #0FFFFB5DEH ; PAC ; SACH 05H,1

EEE

; ;

IN 0,04H NOPS NOP NOP NOP LT 01H MPY #0FFFFB5DEH MPY #4A22H MPY #315EH PAC SACH 05H,1

LACC 00H AND #0FFFH XOR #800H SUB #800H SACL 00H SACL 01H ZAP

DSP LAB
; ; ; LT 00H DMOV 00H LTD 00H MPY #4A22H MPY #315EH PAC SACH 02H,1 LT 03H MPY #1446H MPY #4E9FH PAC SACH 04H,1 LACC 02H ADD 04H SUB 05H SACL 03H ADD #800H SACL 00H OUT 00H,1AH OUT 0,04H B LOOP NOP NOP BH

EEE

H:

DSP LAB
iii) PROGRAM IIR BAND PASS FILTER
.MMREGS .TEXT START: LDP #100H LACC #00H LAR AR0,#00FFH LAR AR1,#8000H MAR *,AR1 LOOP: SACL *+,AR0 BANZ LOOP,AR1 LOOP1: LACC #00H SACL 00H IN 0,06H LAR AR7,#30H MAR *,AR7 BACK: BANZ BACK,*IN 0,04H NOP NOP NOP NOP LT 04H MPY #003BH PAC SACH 24H,0 RPT #0BH SFR SACH 24H,4

EEE

; ; ;

; ;

LT 03H MPY #0000H PAC RPT #0BH SFR SACH 23H,0 SACH 23H,4 LT 02H MPY #0077H

DSP LAB
; ; ; PAC RPT #0BH SFR SACH 22H,0 SACH 22H,4

EEE

; ; ;

LT 01H MPY #0000H PAC RPT #0BH SFR SACH 21H,0 SACH 21H,4 LACC 03H SACL 04H LACC 02H SACL 03H LACC 01H LACC 02H LACC 00H AND #0FFFH XOR #800H SUB #800H SACL 00H SACL 01H ZAP

; ; ;

LT 00H MPY #003BH PAC RPT #0BH SFR SACH 20H,0 SACH 20H,4 LT 73H MPY #0B04H PAC RPT #0BH SFR SACH 63H,0 SACH 63H,4

; ; ;

DSP LAB
LT 72H MPY #1226H PAC RPT #0BH SFR SACH 62H,0 SACH 62H,4 LT 71H MPY #21A3H PAC RPT #0BH SFR SACH 61H,0 SACH 61H,4 LACC 72H SACL 73H LACC 71H SACL 72H LACC 70H SACL 71H LT 70H MPY #15E9H PAC RPT #0BH SFR SACH 60H,0 SACH 60H,4 LACC 20H ADD 21H SUB 22H ADD 23H ADD 24H ADD 60H SUB 61H ADD 62H SUB 63H SACL 70H ADD #800H SACL 00H OUT 00H,1AH OUT 0,04H B LOOP1 NOP

EEE

; ; ;

; ; ;

; ; ;

DSP LAB
H: NOP B H

EEE

iv) PROGRAM IIR BAND REJECT FILTER


.MMREGS .TEXT START: LDP #100H NOP NOP NOP LACC #00H LAR AR0,#00FFH LAR AR1,#8000H MAR *,AR1 LOOP: SACL *+,AR0 BANZ LOOP,AR1 LOOP1: LACC #00H SACL 00H IN 0,06H LAR AR7,#30H MAR *,AR7 BACK: BANZ BACK,*IN 0,04H NOP NOP NOP NOP LT 04H MPY #2FC4H MPY #05F8H PAC SACH 24H,0 SACH 24H,4 LT 03H MPY #99B2H MPY #1336H PAC

DSP LAB
; SACH 23H,0 SACH 23H,4 LT 02H MPY #0DB29H MPY #1B65H PAC SACH 22H,0 SACH 22H,4 LT 01H MPY #99B2H MPY #1336H PAC SACH 21H,0 SACH 21H,4 LACC 03H SACL 04H LACC 02H SACL 03H LACC 01H LACC 02H LACC 00H AND #0FFFH XOR #800H SUB #800H SACL 00H SACL 01H ZAP DMOV 03H DMOV 02H DMOV 01H LT 00H MPY #2FC4H MPY #05F8H PAC SACH 20H,0 SACH 20H,4 LT 73H MPY #2A22H MPY #0544H PAC SACH 63H,0 SACH 63H,4 LT 72H MPY #6761H

EEE

; ; ;

; ;

DSP LAB
; MPY #0CECH PAC SACH 62H,0 SACH 62H,4

EEE

LT 71H MPY #0B6E8H MPY #16DDH PAC SACH 61H,0 SACH 61H,4 LACC 72H SACL 73H LACC 71H SACL 72H LACC 70H SACL 71H

Result

DSP LAB

EEE

Exp No: 5 Date : _ _/_ _/_ _

CALCULATION OF FFT Aim:


To write a program for calculation of FFT and verify by using DSP processor kit (TMS320C5X).

Equipments Required:
1. TMS320C5X 2. DAC -1 -1

Procedure:
1. Connect the Interface Card AD12N to TMS320C5X. 2. Enter the Program & Execute. 3. Observe the output using PC .

DSP LAB

EEE

PROGRAM CALCULATION OF FFT .mmregs .text START: LDP ; #100H LACC N #8H,N 0B000H ;call the subroutine for bitreversing the input AR0,#BIT_REV ;transfer the bitrevesed data in 8020 to 8030 AR5,#INPLACE ;and include the imaginary part 0B100H ;call the subroutine for this purpose #3H,STG ;for 8 point FFT 3 stages are found #1H,BFLY ;for first stage butterfly=1 #2H,DNS ;dual node spacing=2 #2H,0FH 0FH N 2H STG ;8 real values & 8 imaginary values for each stage

SPLK CALL LAR LAR CALL SPLK SPLK SPLK SPLK ZAP LT MPY SPL 2H LT MPY SPL 2H LAR MAR RPT BLPD

;location 8002 hold the number of table ;values or twidle factor values AR1,#TWIDLE *,AR1 2H #TABLE,*+

;transfer the twidle factor values from program

STGLOP

LAR LACC SUB SACL LACC SACL LAR LACC BSAR SACL SUB SACL LAR LACC SUB

;memory to the data memory(8090) AR1,#TWIDLE STG #1H ;stage value is subtracted by 1 for counter STGC ;purpose 00 GRP ;let group=8 AR7,STGC ;stage loop GRP ;group=group/2 1H GRP #1H ;group value is subtracted by 1 for counter GRPC ;purpose AR6,GRPC ;group loop BFLY #1H

DSP LAB
SACL LACC SUB SACL BFLYC DNS #1H DNSC ;dual node spacing value is subtracted by 1 ;for counter purpose

EEE

;this is the main butterfly loop AR0,#INPLACE ;take the input values from 8030 GRPLOP LAR AR2,BFLYC ;butterfly counter BFLYLOP CALL 0B200H ;call the subroutine for the complex LAR ;multiplication of input values and twidle ;factor values MAR RPT LACC CALL MAR RPT LACC CALL *,AR0 DNSC *+ 0B200H *,AR0 DNSC *0B300H ;incrment the location 8030 for next complex ;multiplication(for example in first stage ;location is incremented from 8030 to 8032) ;gain call the subroutine

;call the subroutine for comlex addition

;and complex subtraction MAR RPT LACC MAR BANZ MAR RPT LACC MAR BANZ LT MPY SPL BFLY LT MPY SPL DNS MAR BANZ B HLT *,AR0 DNSC *+ *,AR2 BFLYLOP,**,AR0 DNSC *+ *,AR6 GRPLOP,*BFLY #2H DNS #2H *,AR7 STGLOP,*;increment the 8030 location for next butterfly

;decrement the butterfly & check

;increment the 8030 location for next ;group ;decrement the group & check ;increase the butterfly for next stage

;increase the dual node spacing for ;next stage

;decrement the stage & check

HLT:

DSP LAB

EEE

INPUT BIT_REV INPLACE TWIDLE N STG STGC GRP GRPC BFLY BFLYC DNS DNSC

.set .set .set .set .set .set .set .set .set .set .set .set .set

8010H 8020H 8030H 8090H 0H 1H 3H 4H 5H 6H 7H 8H 9H

;inputs are given in 8010 ;bitreversed input are found in 8020 ;final outputs are in 8030 ;twidle factor values are in 8090

Result

You might also like