DSP Lab Manual
DSP Lab Manual
DSP Lab Manual
ECE: V SEMESTER
LIST OF EXPERIMENTS MATLAB: INTRODUCTION TO MATLAB. GENERATION OF SIGNALS. LINEAR AND CIRCULAR CONVOLUTION OF TWO SEQUENCES. SAMPLING AND EFFECT OF ALIASING. DESIGN OF FIR FILTERS. CALCULATION OF FFT OF A SIGNAL. DESIGN OF IIR FILTERS.
PROCESSOR:-
STUDY OF TMS320C50 PROCESSOR. 16 BIT ARITHMETIC OPERATION USING TMS320C50. STUDY OF VARIOUS ADDRESSING MODES OF DSP USING SIMPLE PROGRAMMING EXAMPLES. SAMPLING OF INPUT SIGNAL AND DISPLAY. IMPLEMENTATION OF FIR FILTER. CALCULATION OF FFT.
1. STUDY OF MATLAB
AIM: To study the MATLAB and its operations. APPARATUS REQUIRED: PC with software MATLAB THEORY: MATLAB is a high performance language for technical computing. It integrates computing, visualization and programming in an easy way to be used by the environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include 1. Math and Computation 2. Algorithm development 3. Data acquisition 4. Modeling, simulation and proto-typing 5. Scientific and engineering graphics 6. Application development including graphical user interface building 7. Data analysis, exploration, visualization. MATLAB SYSTEM: The MATLAB consists of three main parts 1. Desktop and Development Environment This is the set of tools and facilities that help you use MATLAB function and files. Many of these tools are graphical user interfaces. It includes the MATLAB desktop and command window, command history and editor and debugger, a code analyzer and other reports, and browser for viewing help, the workspace, files and the search path. 2. The MATLAB Mathematical Function Library This is a vast collection of computational algorithm ranging from elementary function like sum, sine, cosine and complex arithmetic to more sophisticated functions like matrix inverse, matrix Eigen values, Bessel functions and fast Fourier transform.
3. The MATLAB Language This is a high level matrix/array language with control flow statements, functions, data structures, input and output and object oriented programming features. It allows both programming in the small to rapidly create quick and dirty throw away program and programming in the large to create large and complex application programmer. 4. Graphics MATLB has extensive facilities for displaying vectors and matrices as graphs as well as annotating and printing these graphs. It includes high-level functions for two and three dimensional data visualization, image processing animation and presentation graphics. 5. MATLAB External Interfaces This is a library that allows you to write a C program and function FORTRAN programmer that interacts with MATLAB. It includes facilities for calling routines from MATLAB (dynamic range), calling MATLAB as a computational engine, and for reading and writing MATLAB files. EXAMPLES: 1. Mathematics-Mathematical operation functions and data analysis. 2. Programming-Programming features and techniques.
2.GENERATION OF SIGNALS
AIM: To draw the waveform for unit step, unit ramp, unit impulse, exponential, sine and cosine wave using MATLAB program. APPARATUS REQUIRED: PC with MATLAB ALGORITHM: STEP1: Clear output screen by using clc command in editor window. STEP2: Divide output screen into number of portions by using sub-plot command. STEP3: Then the function for unit step, ramp, impulse and exponential, sine and cosine waves are declared. STEP4: Give the title for each output. STEP5: End the program. PROCEDURE: 1. Click MATLAB icon and open a new file. 2. Type the program and save the project. 3. Run the program by clicking on debug. 4. Note the output and plot the graph for the output.
PROGRAM: clc; clear all; figure(1); subplot(3,2,1); a=5; t=-a ; a; i =[zeros(1,a),1,ones(1,a)]; stem (t, i); x label (time); y label (amplitude); title (unit step); subplot (3,2,2); figure (1); a=5; t=-a;a; x=t.i; stem(t,x); x label (time); y label (amplitude); title (unit ramp); subplot (3,2,3); figure (1); a=5; t=-a:a; j=[zeros(1,a),1,zeros(1,a)]; stem (t,j); x label (time);
y label (amplitude); title (unit impulse); subplot (3,2,4); figure (1); a=5; t=-a:a; x=exp(t); stem (t,x); x label (time); y label (amplitude); title (unit exponential); subplot (3,2,5); t=0:.01:2; x=sin(2*pi*t); plot (t,x); line ([0,2],[0,0]); x label (time); y label (amplitude); title (sine wave); subplot (3,2,6); t=0:.01:2; x=cos(2*pi*t); plot(t,x); line([0,2],[0,0]); x label (time); y label (amplitude); title(cosine wave);
RESULT: Thus the waveform for unit step, unit ramp, unit impulse, unit exponential, and sine and cosine wave obtained using MATLAB program.
CIRCULAR CONVOLUTION: We know that linear convolution of two finite length data sequence is done by assuming that the data is zero outside the length in which it is defined[recall that linear convolution runs from to ].this need not be the only valid assumption. For e.g. one can assume that the data is periodic outside the sequence length in which it is defined. This is consistent with the definition of DFT.DFT is equivalent to discrete time Fourier series and that all Fourier series assume periodicity. So this definition of convolution would be more practical use since it implies with DFT definition. Therefore circular Convolution is defined n-1 X (n) +y (n) = x (m) y [(n-m) mod n)] m=0
PROCEDURE: 1. Click on MATLAB icon and open new file. 2. Type program and save it. 3. Run program by clicking on debug. 4. Note output and plots the graph.
PROGRAM: %linear convolution clear all; clc; close all; a=input(enter the value of a); b= input(enter the value of b); subplot (3,1,1); stem (a); subplot (3,1,2); stem(b); c=conv(a,b); subplot (3,1,3); stem (c);
%circular convolution clear all; clc; close all; x= input(enter the value of x); y= input(enter the value of y); a=length(x); b=length(y);
n=a+b/2 %zero padding if a~=b if a<b n=b; x=[x,zeros(1,b-1)]; else n=a; y=[y,zeros(1,a-1)]; end else n=a; end %circular convolution for i=1:n z(i)=0; for j=1:n k=mod(i-j(n))+1; z(i)=z(i)+[x(j)*y(k)]; end end subplot (3,1,1); stem (x); x label (n); y label (x(n)); title (sequence 1); disp(sequence 1 :);x subplot (3,1,2);
stem (y); x label (n); ylabel (y(n)); title(sequence 2); disp(sequence 2 :);y subplot(3,1,3); stem (z); x label (n); y label (z(n)); title (output); disp(output :);z g.text(circular convolution);
RESULT: Thus program to perform linear and circular convolution in MATLAB has been verified and processed.
PROGRAM: %SAMPLING AND EFFECT OF ALIASING clc; clear all; close all; disp(aliasing); fc1=50; fc2=10; t=0:(1/10)e2:0.1; x1=sin(2*pi*fc1*t); x2= sin(2*pi*fc2*t); subplot (2,3,1); plot(x1); line ([0,200],[0,0]); x label (time); y label (amplitude); title (sinusoidal signal f=50 hz); subplot (2,3,4); plot (x2); line([0,100],[0,0]); x label (time); y label (amplitude); title (sinusoidal signal f=50 hz); fs=40; n=0:1:15; x3=sin(2*pi*fc1*n/fs); x4=sin(2*pi*fc2*n/fs); subplot (2,3,2);
stem(x3); line ([0,15],[0,0]); x label (time); y label (amplitude); title (sampled signal (alias fs=40hz)); subplot (2,3,5); stem (x4); line ([0,15],[0,0]); x label (time); y label (amplitude); title(sampled signal fs=40 hz); fs1=150 n=0:1:10 x5=sin (2*pi*fc1*n/fs1); x6=sin(2*pi*fc2*n/fs1); subplot (2,3,3); stem (x5); line([0,10],[0,0]); x label (time); y label (amplitude); title(sampled signal fs1=150hz); subplot(2,3,6); stem (x6); line ([0,10],[0,0]); x label (time); y label (amplitude); title(sampled signal fs1=150hz); g text(sampling and aliasing);
RESULT: Thus a sine wave is sampled and the effects of aliasing are studied.
PROGRAM: % KAISER WINDOW clc; clear all; close all; n=input (enter the order of the filter); %order of the filter
wc=input (enter cut off frequency); % cut off frequency beta=input(enter the beta value); % kaiser window parameter w=kaiser(n+1,beta); %fir filter using Kaiser window fn b=fir1(n,wc,w); % fir filter coefficient [h,omega]=freqz(b,1,256); %frequency response m=20*log(abs(h)); %magnitude response ph=angle(h*(180/pi)); %phase response subplot (2,2,1); plot (b); title (filter response); subplot (2,2,2); plot (omega/pi,h); title (frequency response); subplot (2,2,3); plot(m); title(magnitude response); subplot(2,2,4); plot(ph); title(phase response); %RECTANGULAR WINDOW
clc; clear all; close all; n=input(enter the value) wc=input(enter the cut-off frequency) w=boxcar(n+1); b=fir1(n,wc,w); [h,omega]=freqz(b,1,256); m=20*log(abs(h)); ph=angle(h*180/pi)); subplot(2,2,1); plot(b); title(filter response); subplot(2,2,2); plot(omega/pi,h); title(frequency response); subplot(2,2,3); plot(m); title(magnitude response); subplot(2,2,4); plot(ph); title(phase response); %BARLETT WINDOW clc; clear all; close all; n=input(enter the value); wc=input(enter cut off frequency);
w=barlett(n+1); b=fir1(n,wc,w); [h,omega]=freqz(b,1,256); m=20*log(abs(h)); ph=angle(h*(180/pi)); subplot(2,2,1); plot(b); title(h(n)); subplot(2,2,2); plot(omega/pi,h); title(frequency response); subplot(2,2,3); plot(m); title(magnitude response); subplot(2,2,4); plot(ph); title(phase response); %BLACKMAN WINDOW clc; clear all; close all; n=input(enter the value); wc=input(enter the cut off frequency); w=blackman(n+1); b=fir1(n,wc,w); [h,omega]=freqz(b,1,256); m=20*log(abs(n)); ph=angle(h*(180/pi));
subplot(2,2,1); plot(b); title(h(n)); subplot(2,2,2); plot(omega/pi,h); title(frequency response); subplot(2,2,3); plot(m); title(magnitude response); subplot(2,2,4); plot(ph); title(phase response);
RESULT: Thus the FIR filter was designed using window technique using MATLAB program for the given order and cut off frequency.
PROCEDURE: 1. Click on MATLAB icon and open a new file 2. Type the program and save the project 3. Run the program by clicking debug. 4. Note the output and plot the graph.
PROGRAM: %N POINT FFT USING DFT: clc; clear all; close all; x=input(enter the sequence); N=length(x); z= fft(x,n); display(input);x display(output);z n=1:N; subplot(3,2,1); stem(n,x); xlabel(sequence number); ylabel(amplitude); title(input sequence); subplot(3,2,2); stem(n,abs(z)); xlabel(sequence number); ylabel(amplitude); title(output amplitude); subplot(3,2,3); stem(b,real(z)); xlabel(sequence number); ylabel(real); title(output real part); subplot(3,2,4); stem(n,imag(z));
xlabel(sequence number); ylabel(imaginary); title(output imaginary part); subplot(3,2,5); stem(n,(z)); xlabel(sequence number); ylabel(phase); title(output phase);
%N-POINT INVERSE FFT USING IDFT: clc; clear all; close all; x=input(enter the number); N=length(x); z= ifft(x,n); display(input);x display(output);z n=1:N; subplot(2,2,1); stem(n,x); xlabel(sequence number); ylabel(amplitude); title(input sequence); subplot(2,2,2); stem(n,z); xlabel(sequence number); ylabel(amplitude);
title(output sequence); subplot(2,2,3); stem(n,floor(real(acos(z)))); xlabel(sequence number); ylabel(amp); title(output sequence); gtext(mnmjec);
RESULT: Thus the program to perform linear combination and circular convolution using FFT has been processed and verified successfully.
Concentrates over range 0<w<1 rather than w=0.the same characteristics of Butterworth filter can be achieved using a filter of lesser order. It has ripples in pass band and stop band.
Tn (w) =cos (n cos-1w), |w|<1 =cosh (ncosh-1w), |w|1 Tn+1(w)=2w Tn(w)-Tn-1(w) PROCEDURE: 1. Click on MATLAB icon and open a new file. 2. Type the program and save the project. 3. Run the program by clicking on debug. 4. Note the output and plot the graph for the output.
PROGRAM: %CHEBYSHEV 1 FILTER clc; close all; clear all; n=input(enter the order value); wc=input(enter the cut off frequency); r=input(enter stop band ripple); [b, a]=cheby1(n,r,wc,s); [h,omega]=freqz(b,a,256); m=20&log(abs(h)); subplot(2,2,2); plot(m);grid title(magnitude response); subplot(2,2,1); plot(omega/pi,h);grid title(frequency response); ph=angle(h*(180/pi)); subplot(2,2,3); plot(ph);grid title(phase response); gtext(chebychev1=IIR filter); %phase response %order of the filter %cut off frequency %stop band frequency %chebyshev function %frequency response %magnitude response
%CHEBYSHEV 2 FILTER clc; close all; n=input(enter the order value); wc=input(enter the cut off frequency); r=input(enter passband ripple); [b, a]=cheby2(n,r,wc,s); [h,omega]=freqz(b,a,256); m=20*log(abs(h)); ph=angle(h*(180/pi)); subplot(2,2,1); plot(omega/pi,h);grid title(frequency response); subplot(2,2,2); plot(m);grid title(magnitude response); subplot(2,2,3); plot(ph);grid title(phase response); %order of the filter %cut off frequency %pass band frequency %chebyshev function %frequency response %magnitude response %phase response %plot response
%BUTTERWORTH FILTER clc; close all; clear all; n=input(enter the value); wc=input(enter the cut off frequency); [b,a]=butter(n,wc); [h.omega]=freqz(b,a,256); %clear the screen %order of the filter %cut off frequency %butterworth function %frequency response
m=20*log((abs(h)); ph=angle(h*(180/pi)) subplot(2,2,1); plot(omega/pi,h);grid title(frequency response); subplot(2,2,2); plot(m);grid title(magnitude response); subplot(2,2,3); plot(ph);grid title(phase response); gtext(BUTTERWORTH IIR FILTER);
RESULT: Thus the programs for IIR filter are designed successfully using MATLAB programs for the given order, cut off frequency and stop band frequency.
time .TMS320C50 has 1056 words of dual access on chip data memory is divided as three blocks B0, B1,& B2 of which B0 can be configured as program or data RAM. INTERRUPTS AND SUBROUNTINE: The TMS320C50 has three external makeable user interrupts available for external devices that interrupt the processor .the TMS320C50 contains an eight-level hardware stack for saving the contents of the program counter during interrupts and subroutine calls.
SERIAL PORT: A full-duplex on-chip serial port provides direct communication with serial devices such as codecs, serial A/D converters and other serial systems. The interface signals are compatible with codecs and many others serial devices with a minimum of external hardware. INPUT AND OUTPUT: The 16-bit parallel data bus can be utilized to perform I/O functions in two cycles. The I/O ports are addressed by four LSBs on the address lines, allowing 16 input and 16 output ports. In addition, a polling input for bit test and jump operation (BIO) and three interrupt pins (INT0-INT2) have been incorporated for multitasking.
EXAMPLES OF ARITHMETIC OPERATIONS USING TMS320C50 PROGRAM: ADDITION: .MMREGS .TEXT START: LDP #1004 LACC #1111H ADD #2222H SACL 0H HLT: B HLT
SUBTRACTION: .MMREGS .TEXT START: LDP #100H LACC #2222H SUB #1111H SACL 0H HLT: B HLT
MULTIPLICATION: .MMREGS .TEXT START: LDP #100H LACC #037AH,0 SACL 0000,0 LACC # 012EH,0 SACL 0001,0 LT 0000 MPY 0001
RESULT: Thus the architecture of TMS320C50 was studied with the simple programming examples
9. STUDY OF VARIOUS ADDRESSING MODES OF DSP USING SIMPLE PROGRAMMING EXAMPLES AIM: To study the various addressing modes of DSP processor using simple programming examples. APPARATUS REQUIRED: 1. TMS320C5X 2. PC 3. RS232 CABLE TYPES OF ADDRESSING MODES: 1. Direct addressing 2. Memory map register addressing 3. Indirect addressing 4. Immediate addressing 5. Dedicated register addressing 6. Circular addressing PROCEDURE: 1. Click on C50 debugger icon and start a new project. 2. Type the program and save it as an assembly file. 3. Program is executed by giving G0C000 in communication window. 4. The output is obtained. 5. Values are obtained by giving various input values.
PROGRAM: IMMEDIATE ADDRESSING MODE: .MMREGS ENTRY .LACC #1000H .LACC #1111H,3
LAR AR0,#1000H LAR AR1,#1100H ADD #00FFH ADD #0011H,2 SPLK #10H,0 MPY #0010H SUB #0022H SUB #0011H,3 .END
DIRECT ADDRESSING MODE: .MMREGS .ENTRY LDP #20H LACC 10H LACC 5H,2 LDP #22H LAR AR0,15H SACL 15H SACL 20H,3 SAMM AR7 LDP # 12H ADD 25H ADD 7H,2 SUB 10H SUB 12H,2 SPLK #10H,0 MPY 15H
.END INDIRECT ADDRESSING MODE: .MMREGS .PS0A00H .ENTRY LAR AR0,#1000H LACC* LACC*,4,AR1 LAR AR1,#1010H SACL*, SACL*+,2,AR0 LACC*-,2,AR1 LACC*0+ LACC*BR0+ ADD*+,0,AR0 SUB*-,2 SPLK #10H,0 MPY* .END CIRCULAR ADDRESSING MODE: .MMREGS .PS0A00H .ENTRY SPLK #1000H,0 SPLK #1003H,1 SPLK #08H,2 LACC*+ LACC*+
RESULT: Thus the various addressing modes of DSP processor using simple programming examples are studied and verified.
PROGRAM: DATA .SET 2H DELAY .SET3H .MMREGS .TEXT START: LDP#100H LAR AR0,#9000H LAR AR1,#719H REP: IN 0,06 RPT #OFH NOP IN 0,04 SPLK #00FFH,DELAY RPT DELAY
NOP LACC 0 AND #0FFFH MAR*,AR0 SACL*+,0,AR1 BANZ REP,*CONT1: LAR AR0,#9000H LAR AR1,#719H LOOP:MAR*,AR0 RPT #1FFH NOP OUT*+,04,AR1 BANZ LOOP,*B CONT1
PROGRAM: .MMREGS .TEXT B START CTABLE: .WORD 0FFF4H .WORD 0FFE3H .WORD 0FFCFH . WORD 0FEBBH . WORD 0FFA7H . WORD 0FF97H .WORD 0FF8EH
. WORD 0FF8FH . WORD 0FF9BH . WORD 0FFB7H . WORD 0FFE3H . WORD 022H . WORD 075H . WORD 0DCH . WORD 0157H . WORD 01E5H . WORD 0283H . WORD 032FH . WORD 03E5H . WORD 04A0H . WORD 055CH . WORD 0614H . WORD 06C2H .WORD 0761H . WORD 076BH .WORD 085BH .WORD 085BH . WORD 07EBH . WORD 07E1H . WORD 06C2H . WORD 0614H . WORD 055CH . WORD 04A0H . WORD 03E5H . WORD 032FH
. WORD 0283H . WORD 01E5H . WORD 0157H . WORD 0DCH . WORD 075H . WORD 022H . WORD 0FFE3H . WORD 0FFB7H . WORD 0FF9BH . WORD 0FF8FH . WORD 0FF8EH . WORD 0FF97H . WORD 0FFA7H . WORD 0FFBBH . WORD 0FFCFH . WORD 0FFE3H . WORD 0FFF4H START: MAR*,AR0 LAR AR0,#0200H RPT #33H BLKP CTABLE,*+ SETC CNF ISR: LDP #0AH LACC #0 SACL 0 OUT 0,05 IN 0,06H LAR AR7,#0
MAR*,AR7 BACK: BANZ BACK,*IN 0,4 NOP NOP NOP NOP MAR*,AR1 LAR AR1,#0300H LACC0 AND #0FFFH SUB #800H SACL* LAR AR1,#333H MPY #0 ZAC RPT #33H MACD 0FF00H,*APAC LAR AR1,#0300H SACH* LACC* ADD #800H SFR SACL* OUT*,4 LACC #0FFH
RESULT : Thus the FIR filter was designed using TMS320C50 DSP Kit.
IMG: SET 8050H .MMREGS .TEXT START: LDP # 100H LAR AR1 ,#IN LAR AR2,#BITREV SPLR #2H,05H LMMR INDX,#8005H MAR*,AR2 RPT #3H BLDD #IN,*BR0+ LAR AR2 ,#BITREV LAR AR3 ,#8030H LAR AR0 ,#1H FFT1: MAR*,AR2 LACC*+ SACB LT*+ MPY #1H APAC MAR*,AR3 SACL*+ LACB SPAC SACL*+,AR0 BANZ FFT1,*LAR AR3,#8030H LAR AR4,#REAL
LAR AR5,#IMG MAR*,AR3 LACC* SACB ADRK#2H LT*MPY #1H APAC MAR*,AR4 SACL* ADRK #2H LACC #0H MAR*,AR5 SACL* ADRK #2H LACB SPAC MAR*,AR4 SACL*LACC #0H MAR*,AR5 SACL*-,AR3 LACL*,AR4 SACL*,AR3 ADRK #2H LT* MPY #0FFFFH MAR*,AR5
SPL8,AR3 LT* MPY #1H MAR*,AR5 ADRK #2H SPL* HLT: B HLT
INPUTS:
(REAL PART) 8040 :0006 8041 :FFFE 8042 :FFFE 8043 :FFFE
(IMAGINARY PART) 8050 :0000 8051 :0002 8052 :0000 8053 :FFFE
RESULT: Thus the FFT of the inputs were performed successfully using DSP processor.