Lab Manual
Lab Manual
Lab Manual
G.PANNEERSELVAM (MTS883)
R.KALPANA (MTS 1079)
1
Department of ECE Digital Signal Processing Lab
(R 2008)
15 Units
PCs with Fixed / Floating point DSP
1. (2 students
Processors (Kit / Add-on Cards)
per system)
4. CRO (20MHz) 15
AIM
2
Department of ECE Digital Signal Processing Lab
To introduce the student to various digital Signal Processing techniques using TMS 320c5x family
processors and MATLAB.
OBJECTIVES
● To implement the processing techniques using the instructions of TMS320C5X/TMS320C
67XX/ADSP 218X/219X/BS531/532/561
● To implement the IIR and FIR filter using MATLAB.
LIST OF EXPERIMENTS
USING
3
Department of ECE Digital Signal Processing Lab
MATL
AB
1. Generation of Signals. 5
4. Design of Linear Phase Low Pass and High Pass FIR filters. 20
Design of Linear Phase Band Pass and Band Stop FIR filters. 20
4
Department of ECE Digital Signal Processing Lab
ylabel('Amplitude');
title('Unit Ramp Signal');
5
Department of ECE Digital Signal Processing Lab
xlabel('Time');
ylabel('Amplitude');
title('Cosine wave');
OUTPUT RESPONSE
6
Department of ECE Digital Signal Processing Lab
7
Department of ECE Digital Signal Processing Lab
INPUT DATA
Enter the lenght of unit step sequence(N)= 10
Enter the length of unit ramp sequence(N1)= 10
Enter the length of sinusoidal sequence(N2)= 2
Enter the length of the cosine sequence(N3)= 2
Enter the length of the exponential sequence(N4)= 10
Enter the value of the exponential sequence(a)= 0.5
8
Department of ECE Digital Signal Processing Lab
OUTPUT RESPONSE
RESULT
Thus the continuous time signal and discrete time signal using MATLAB program was generated.
9
Department of ECE Digital Signal Processing Lab
AIM
To perform Linear and Circular convolution of the two sequences using MATLAB function.
ALGORITHM
1. Get the two sequence x(n) and h(n) in matrix form.
2. The convolution of the two sequences is given by
PROGRAM
A) TO PERFORM THE LINEAR CONVOLUTION OF TWO SEQUENCES
%input sequence
clc;
x=input('enter the input sequence x(n)=');
N1=length(x);
n=0:1:(N1-1);
subplot(3,1,1);
stem(n,x,'k');
xlabel('n-------->');
ylabel('amplitude');
title('input sequence x(n)');
%impulse sequence
h=input('enter the impulse sequence h(n)=');
N2=length(h);
n1=0:1:(N2-1);
subplot(3,1,2);
stem(n1,h,'k');
xlabel('n--------->');
ylabel('amplitude');
title('impulse response h(n)');
%output convolution
y=conv(x,h)
n2=0:1:(N1+N2-2);
subplot(3,1,3);
stem(n2,y,'k');
10
Department of ECE Digital Signal Processing Lab
xlabel('n--------->');
ylabel('amplitude');
title('linear convolution of two sequences');
y=
2 5 10 16 12 11 4
>>
OUPUT RESPONSE
N2=length(x2);
N=max(N1,N2);
N3=N1-N2;
%CIRCULAR CONVOLUTION
disp('The output of circular convolution is')
for m=1:N %This 'for' loop is for circular shifting
sum=0;
for k=1:N %This 'for' loop is for summation
if((m-k)>=0) %This 'if' loop is for circular folding
n=m-k+1;
else
n=m-k+N+1;
end
sum=sum+x1(k)*x2(n);
end
disp(sum) %display the result of circular convolution
end
x2 =
4 3 0 0
11
18
12
Department of ECE Digital Signal Processing Lab
25
RESULT
Thus the Linear and Circular convolution of the two sequences using MATLAB program was
performed.
PROGRAM
SAMPLING AND EFFECT OF ALIASING
clc;
%Analog signal
t=-0.005:0.00005:0.005;
xa=exp(-1000*abs(t));
subplot(2,1,1);
plot(t*1000,xa,'k');
grid;
hold on;
stem(n*Ts*1000,xn,'k');
xlabel('time in sec');
ylabel('x(n)');
title('discrete time signal');
gtext('Ts=1msec');
hold off;
subplot(2,1,2);
plot(W/pi,X,'k');
grid;
xlabel('normalised frequency in rad/sec');
ylabel('|X(W)|');
title('discrete time fourier transform');
OUTPUT RESPONSE
(a) Enter the sampling frequency (Fs) =5000
The maximum frequecy of analog signal (Wm) =1000rad/sec. i.e. sampling frequency is greater than
twice the maximum frequecy.
i.e.Ws >2Wm
i.e.5000>2000
Therefore it satisfies the above condition hence there is no aliasing effect.
14
Department of ECE Digital Signal Processing Lab
15
Department of ECE Digital Signal Processing Lab
RESULT
Thus the effect of sampling on the frequency domain quantities at different sampling frequencies
was studied MATLAB program.
DESIGN OF LINEAR PHASE LOW PASS AND HIGH PASS FIR DIGITAL
FILTERS
AIM
To design a linear phase Low Pass and High Pass FIR Digital Filter using different windows in
MATLAB Function.
16
Department of ECE Digital Signal Processing Lab
ALGORITHM
1. Get the number of samples of impulse response.
2. Get the cut off frequency.
3. Determine the value of infinite impulse response.
4. Choose the window sequence.
5. Determine the filter co-efficient of finite impulse response.
6. Draw the magnitude and phase response.
17
Department of ECE Digital Signal Processing Lab
hnr = -0.0757 0.0858 -0.0935 0.0984 0.9000 0.0984 -0.0935 0.0858 -0.0757
hnm = -0.0061 0.0184 -0.0505 0.0851 0.9000 0.0851 -0.0505 0.0184 -0.0061
hnn = -0.0072 0.0297 -0.0612 0.0890 0.9000 0.0890 -0.0612 0.0297 -0.0072
hnb = 0.0000 0.0057 -0.0318 0.0761 0.9000 0.0761 -0.0318 0.0057 0.0000
>>
18
Department of ECE Digital Signal Processing Lab
wham=hamming(N);
%To determine the finite impulse response
hnm=hd.*wham'
w=0:0.001:pi;
h=freqz(hnm,1,w);
plot(w/pi,20*log10(abs(h)),'k.');
hold on
hnr = 0.0046 -0.0717 -0.1591 -0.2283 0.7454 -0.2283 -0.1591 -0.0717 0.0046
hnm = 0.0004 -0.0154 -0.0859 -0.1976 0.7454 -0.1976 -0.0859 -0.0154 0.0004
hnn = 0.0004 -0.0248 -0.1041 -0.2065 0.7454 -0.2065 -0.1041 -0.0248 0.0004
hnb = -0.0000 -0.0048 -0.0541 -0.1766 0.7454 -0.1766 -0.0541 -0.0048 -0.0000
>>
20
Department of ECE Digital Signal Processing Lab
RESULT
Thus the linear phase Low Pass and High Pass FIR Digital Filter using different window was
designed in MATLAB program.
21
Department of ECE Digital Signal Processing Lab
DESIGN OF LINEAR PHASE BAND PASS AND BAND STOP FIR DIGITAL
FILTERS
AIM
To design a linear phase Band Pass and Band Stop FIR Digital Filter using different windows in
MATLAB Function.
ALGORITHM
1. Get the number of samples of impulse response.
2. Get the cut off frequencies (wc1 & wc2).
3. Determine the value of infinite impulse response.
4. Choose the window sequence.
5. Determine the filter co-efficient of finite impulse response.
6. Draw the magnitude and phase response.
A) PROGRAM FOR DESIGN OF LINEAR PHASE BAND PASS FILTER USING
DIFFERENT WINDOWS
clc;
N=input('Enter the number of samples (N)=');
wc1=input('Enter the lower cut off frequency (wc1)=');
wc2=input('Enter the upper cut off frequency (wc2)=');
alpha=(N-1)/2;
22
Department of ECE Digital Signal Processing Lab
w=0:0.001:pi;
h=freqz(hnm,1,w);
plot(w/pi,20*log10(abs(h)),'k.');
hold on
hnr = 0.0000 -0.0000 -0.3183 0.0000 0.5000 -0.0000 -0.3183 0.0000 -0.0000
hnm = 0.0000 -0.0000 -0.1719 0.0000 0.5000 -0.0000 -0.1719 0.0000 -0.0000
hnn = 0.0000 -0.0000 -0.2083 0.0000 0.5000 -0.0000 -0.2083 0.0000 -0.0000
hnb = -0.0000 -0.0000 -0.1082 0.0000 0.5000 -0.0000 -0.1082 0.0000 0.0000
>>
23
Department of ECE Digital Signal Processing Lab
w=0:0.001:pi;
h=freqz(hnr,1,w);
plot(w/pi,20*log10(abs(h)),'r.');
hold on
hnr = -0.0000 0.0000 0.3183 0.0000 0.5000 -0.0000 0.3183 -0.0000 0.0000
hnm = -0.0000 0.0000 0.1719 0.0000 0.5000 -0.0000 0.1719 -0.0000 0.0000
hnn = -0.0000 0.0000 0.2083 0.0000 0.5000 -0.0000 0.2083 -0.0000 0.0000
25
Department of ECE Digital Signal Processing Lab
hnb = 0.0000 0.0000 0.1082 0.0000 0.5000 -0.0000 0.1082 -0.0000 -0.0000
RESULT
Thus the linear phase Band Pass and Band Stop FIR Digital Filter using different window was
designed in MATLAB program.
26
Department of ECE Digital Signal Processing Lab
title('Phase response');
N=
1
omc =
0.5043
Transfer function:
0.5033 s + 0.5033
-----------------
s + 0.006691
Transfer function:
0.7525 z - 0.2508
-----------------
z - 0.9933
Sampling time: 1
OUTPUT RESPONSE
28
Department of ECE Digital Signal Processing Lab
subplot(2,1,1);
plot(w/pi,20*log10(abs(h)),'k');
grid;
xlabel('Normalised frequency');
ylabel('Gain in dB');
title('Magnitude response');
subplot(2,1,2);
plot(w/pi,angle(h),'k');
grid;
xlabel('Normalised frequency');
ylabel('Angle in radians');
title('Phase response');
N=
1
omc =
0.5043
Transfer function:
0.08254 s + 0.08254
-------------------
s - 0.8349
Transfer function:
0.2125 z - 0.07085
------------------
z - 2.433
Sampling time: 1
OUTPUT RESPONSE
30
Department of ECE Digital Signal Processing Lab
RESULT
Thus the digital Butterworth and chebyshev Low Pass IIR Filter from the given specification was
designed using MATLAB program.
Where
3. Stop the program.
xlabel('n---->');
ylabel('Amplitude');
title('Magnitude plot (IDFT)');
Columns 1 through 6
Columns 7 through 8
0 -5.8284 + 2.4142i
x=
32
Department of ECE Digital Signal Processing Lab
1 2 3 4 4 3 2 1
OUTPUT RESPONSE
RESULT
Thus the DFT and IDFT of the given sequence using FFT Algorithm in MATLAB program were
performed.
.
ALGORITHM
1. Start the program.
2. Get the input sequence value and time period of the sequence is obtained as input for decimation and
interpolation.
3. Get the down sampling and up sampling of values is obtained as input.
4. Plot the output response for Decimation and Interpolation
33
Department of ECE Digital Signal Processing Lab
subplot(2,1,1);
stem(n,X(1:N),'k');
grid;
xlabel('samples(n)');
ylabel('Amplitude');
title('Sampled signal');
subplot(2,1,2);
d=0:1:(N/D-1);
stem(d,Y(1:N/D),'k');
grid;
xlabel('Samples(n)');
ylabel('Amplitude');
title('Down sampled signal');
OUTPUT RESPONSE
34
Department of ECE Digital Signal Processing Lab
subplot(2,1,1);
stem(n,X(1:N),'k');
grid;
xlabel('samples(n)');
ylabel('Amplitude');
title('sampled signal');
subplot(2,1,2);
i=0:1:(N/I-1);
stem(i,Y(1:N/I),'k');
35
Department of ECE Digital Signal Processing Lab
grid;
xlabel('samples(n)');
ylabel('Amplitude');
title('up sampled signal');
OUTPUT RESPONSE
RESULT
Thus the decimation and interpolation of the given input signal had been done and the output was
verified using MATLAB program.
36
Department of ECE Digital Signal Processing Lab
.MMREGS
.TEXT
START: LDP #100H
LACC 00H
ADD 01H
SACL 02H
H: B H
OUTPUT:
;input: 8000-0002
; 8001-0002
;output: 8002-0004
.MMREGS
.TEXT
START: LDP #100H
LACC 00H
SUB 01H
SACL 02H
H: B H
OUTPUT:
;input: 8000-0003
; 8001-0002
;output: 8002-0001
37
Department of ECE Digital Signal Processing Lab
.MMREGS
.TEXT
START: LDP #100H
LT 00H
MPY 01H
PAC
SACL 02H
H: B H
OUTPUT:
;input: 8000-0002
; 8001-0002
;output: 8002-0004
OUTPUT:
;input: 8000-0001
.MMREGS
.TEXT
START: LDP #100H
LACC 00H
CMPL
ADD #1
SACL 01H
H: B H
OUTPUT:
;input: 8000-0001
38
Department of ECE Digital Signal Processing Lab
.MMREGS
.TEXT
START: LDP #100H
LACC 00H
AND 01H
SACL 02H
H: B H
OUTPUT:
;input: 8000-0001
; 8001-1011
;output: 8002-0001
.MMREGS
.TEXT
START: LDP #100H
LACC 00H
OR 01H
SACL 02H
H: B H
OUTPUT:
;input: 8000-0001
; 8001-1011
;output: 8002-1011
RESULT
Thus the Addition, Subtraction, Multiplication, 1’s and 2’s Complements, AND and OR
operations of the given numbers was performed using TMS320C50 DSP Processor.
39
Department of ECE Digital Signal Processing Lab
OBSERVATION
NAME OF TIME PERIOD
S.No AMPLITUDE (volts)
WAVEFORMS (msec)
RESULT
41
Department of ECE Digital Signal Processing Lab
Thus the Square, Saw tooth and Triangular Wave was generated using TMS320C50 DSP
Processor.
AIM
To perform the linear and circular convolution of the two sequences using TMS320C50 DSP Processor.
ALGORITHM
1. Get the two sequence x(n) and h(n) in matrix form.
2. The convolution of the two sequences is given by
42
Department of ECE Digital Signal Processing Lab
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
;8100 - 1
;8101 - 3
;8102 - 1
;8103 - 3
;INPUT ( h(n) )
; 8200 - 0
; 8201 - 1
; 8202 - 2
; 8203 - 1
;OUTPUT ( y(n) )
; 8300 - 0
; 8301 - 1
; 8302 - 5
; 8303 - 8
; 8304 - 8
; 8305 - 7
; 8306 - 3
43
Department of ECE Digital Signal Processing Lab
MAR *,AR0
BANZ LOOP3,*-
H: B H
ROTATE:
LDP #100H ;rotate the values of X1[n]
LACC 1H
SUB #1H
SACL 2H
LACC 0050H
SACB ; 8050 DATA MOVED TO THE ACCUMULATOR TO THE ACCUMULATOR
BUFFER
LAR AR3,#8051H
LAR AR5,#8070H
LAR AR6,2H
LOOP1:
MAR *,AR3
LACC *+
MAR *,AR5
SACL *+
MAR *,AR6
BANZ LOOP1,*-; DATA FROM 8051-8053 TO 8070-8072
LACB ;MOVE THE DATA ACCUMULATOR BUFFER TO ACCUMULATOR AS LAST
DATA
MAR *,AR5
SACL *+
LACC #8070H
SAMM BMAR
LAR AR3,#8050H
MAR *,AR3
RPT #3H ;ROTATE 4 TIMES
BLDD BMAR,*+ ;BMAR AUTOMATICALLY INCREMENTED ,TO COPY SHIFTED DATA
TO 8050
RET
45
Department of ECE Digital Signal Processing Lab
;OUTPUT:
; 8010-000E
; 8011-0010
; 8012-000E
; 8013-0010
;
RESULT
Thus the linear convolution of the two sequences was performed using TMS320C50 DSP Processor.
46
Department of ECE Digital Signal Processing Lab
PROGRAM DESCRIPTION:
In this program the samples are taken from the ADC with the desired sampling rate and the sample values
are stored in the memory locations from the data memory 9000H. After taking 720 samples from the
ADC the samples are sent through the serial port which is received by the basic program named
"sample50.bas",and plots the samples in the pc screening this program the sampling rate is varied by
varying the number in the address named DELAY. The delay value is also sent to the basic programas a
first data. The distance between the samples in the basic program varies according
to the delay value which it receives as a first data.
;Note:
;1. Swith off the trainer kit.
;2. Connect the function generator in the corresponding terminals.
;3. Download the program to the trainer kit using Xtalk.exe
;4. Quit from the Xtalk.
;5. Enter into the basic TB.exe
;6. Load and run the program "sample50.bas" which executes the asm program
; and plots the samples on the screen.
47
Department of ECE Digital Signal Processing Lab
.MMREGS
.TEXT
START: LDP #140H
LOOP: IN 0,06
NOP
NOP
IN 0,04
LACC 0
AND #0FFFH
ADD #0800H
SACL 0
OUT 0,04
B LOOP
OUTPUT RESPONSE
RESULT
Thus the sampling of the given input signal was performed using TMS320C50 DSP Processor.
48
Department of ECE Digital Signal Processing Lab
ALGORITHM
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band frequency.
3 Get the sampling frequency
4. Calculate the order the filter by using the formula,
5. Find the filter co-efficient.
6. Draw the magnitude and phase response.
.MMREGS
.TEXT
B START
CTABLE:
.word 0FFE7H ; Filter coefficients n=0
.word 0FFD3H
.word 0FFC6H
.word 0FFC4H
.word 0FFD0H
.word 0FFECH
.word 018H
.word 051H
.word 08CH
.word 0B9H
.word 0C2H
.word 092H
.word 01AH
.word 0FF5FH
.word 0FE78H
.word 0FD9AH
.word 0FD10H
.word 0FD30H
.word 0FE42H
.word 071H
.word 03B5H
49
Department of ECE Digital Signal Processing Lab
.word 07CAH
.word 0C34H
.word 01054H
.word 01387H
.word 01547H
.word 01547H
.word 01387H
.word 01054H
.word 0C34H
.word 07CAH
.word 03B5H
.word 071H
.word 0FE42H
.word 0FD30H
.word 0FD10H
.word 0FD9AH
.word 0FE78H
.word 0FF5FH
.word 01AH
.word 092H
.word 0C2H
.word 0B9H
.word 08CH
.word 051H
.word 018H
.word 0FFECH
.word 0FFD0H
.word 0FFC4H
.word 0FFC6H
.word 0FFD3H
.word 0FFE7H ; Filter coefficients n=52
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
LACC 0
AND #0FFFH
SUB #800H
SACL *
LAR AR1, #333H
MPY #0
ZAC
RPT #33H
MACD 0FF00H,*- ; CONVOLUTION OPERATION
APAC
LAR AR1, #0300H
SACH *
LACC *
ADD #800h
SACL *
OUT *, 4
LACC #0FFH
SACL 0
OUT 0, 05
NOP
B ISR
.END
51
Department of ECE Digital Signal Processing Lab
RESULT
Thus the digital FIR Filter (LPF and HPF) was implemented using TMS320C50 DSP Processor.
52
Department of ECE Digital Signal Processing Lab
AIM
To perform auto and Cross correlation of the two sequences using MATLAB function.
ALGORITHM
1. Get the input sequences in matrix form.
2. The correlation of the two sequences is given by
switch(choice)
case{1} % Autocorrelation of the sequence
x = input('Enter the sequence x = ');
y = fliplr(x); % flip the sequence in left/right direction
r = conv(x,y) % Compute the correlation sequence
stem(r); % display the correlation sequence
xlabel('n'); ylabel('Amplitude'); grid;
title('Autocorrelation');
53
Department of ECE Digital Signal Processing Lab
Case 1:
Autocorrelation and cross correlation of sequences
1 autocorrelation 2 cross correlation
Enter the choice of correlation = 1
Enter the sequence x = [1 2 3 4]
r=
4 11 20 30 20 11 4
>>
Case 2:
Autocorrelation and cross correlation of sequences
1 autocorrelation 2 cross correlation
Enter the choice of correlation = 2
Enter the sequence x = [1 2 3 4]
Enter the sequence y = [4 3 2 1]
r=
1 4 10 20 25 24 16
>>
RESULT
Thus the auto and Cross correlation of the two sequences using MATLAB program was
performed.
54
Department of ECE Digital Signal Processing Lab
AIM
To compute the Power Spectrum Estimation using Periodogram in MATLAB function.
ALGORITHM
1. Get the length input sequences.
2. Get the input sequences in matrix form.
3. Find the signal sum of two sinusoids and random noise.
4. Stop the program.
PROGRAM
%Power Spectrum Estimation using Periodogram
clc;
N=input('Enter the length of the sequence (N)=');
window=hamming(N);
nfft=input('Enter the length of the FFT=');
Fs=input('Enter the sampling frequency (Fs)=');
n=0:1:N-1;
% signal sum of two sinusoids and random noise
x=cos(2*pi*n/Fs)+sin(2*pi*n/Fs)+0.01*randn(size(n));
subplot(2,1,1);
plot(n,x,'k');
xlabel('n');
ylabel('x(n)');
[pxx,f]=periodogram(x,window,nfft,Fs);
subplot(2,1,2)
plot(f/Fs,10*log10(pxx),'k');
grid;
xlabel('\omega/\pi');
ylabel('Power Spectrum');
OUTPUT RESPONSE
55
Department of ECE Digital Signal Processing Lab
RESULT
Thus the power spectrum estimation using periodogram in MATLAB function was performed.
56