DSP Lab Manual EC8562 (R 2017)
DSP Lab Manual EC8562 (R 2017)
DSP Lab Manual EC8562 (R 2017)
Aim:
To familiarize with MATLAB software, general functions and signal processing toolbox
functions.
The name MATLAB stands for MATrix LABoratory produced by Mathworks Inc., USA.
It is a matrix-based powerful software package for scientific and engineering computation
and visualization. Complex numerical problems can be solved in a fraction of the time that
required with other high level languages. It provides an interactive environment with
hundreds of built -in –functions for technical computation, graphics and animation. In
addition to built-in-functions, user can create his own functions.
MATLAB offers several optional toolboxes, such as signal processing, control systems,
neural networks etc. It is command driven software and has online help facility.
MATLAB has three basic windows normally; command window, graphics window and edit
window.
Command window is characterized by the prompt ‘>>’.
All commands and the ready to run program filename can be typed here. Graphic window
gives the display of the figures as the result of the program. Edit window is to create
program files with an extension .m.
Some important commands in MATLAB
Help - List topics on which help is available
Help command name Provides - help on the topic selected
Demo - Runs the demo program
Who - Lists variables currently in the workspace
Whos - Lists variables currently in the workspace with their size
Clear - Clears the workspace, all the variables are removed
Clear x,y,z - Clears only variables x,y,z
Quit - Quits MATLAB
Some of the frequently used built-in-functions in Signal Processing Toolbox
filter(b.a.x) - Syntax of this function is Y = filter(b.a.x)
It filters the data in vector x with the filter described by vectors
a and b to create the filtered data y.
fft (x) It is the DFT of vector x
ifft (x) It is the DFT of vector x
conv (a,b) Syntax of this function is C = conv (a,b)
It convolves vectors a and b. The resulting vector is of
Length, Length (a) + Length (b)-1
deconv(b,a) Syntax of this function is [q,r] = deconv(b,a)
It deconvolves vector q and the remainder in vector r such that
b = conv(a,q)+r
butter(N,Wn) designs an Nth order lowpass digital
Butterworth filter and returns the filter coefficients in length
N+1 vectors B (numerator) and A (denominator). The coefficients
1
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
are listed in descending powers of z. The cutoff frequency Wn must be 0.0 <
Wn < 1.0, with 1.0 corresponding to half the sample rate.
buttord(Wp, Ws, Rp, Rs) returns the order N of the lowest order digita Butterworth filter
that loses no more than Rp dB in the passband and has at least Rs dB of
attenuation in the stopband. Wp and Ws are the passband and stopband
edge frequencies, Normalized from 0 to 1 ,(where 1 corresponds to pi
rad/sec)
Cheby1(N,R,Wn) designs an Nth order lowpass digital Chebyshev filter with R decibels of
peak-to-peak ripple in the passband. CHEBY1 returns the filter
coefficients in length N+1 vectors B (numerator) and A (denominator).
The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0
corresponding to half the
sample rate.
Cheby1(N,R,Wn,'high') designs a highpass filter.
Cheb1ord(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Chebyshev Type
I filter that loses no more than Rp dB in the passband and has at
least Rs dB of attenuation in the stopband. Wp and Ws are the
passband and stopband edge frequencies, normalized from 0 to 1
(where 1 corresponds to pi radians/sample)
cheby2(N,R,Wn) designs an Nth order lowpass digital Chebyshev filter with the
stopband ripple R decibels down and stopband edge frequency Wn.
CHEBY2 returns the filter coefficients in length N+1 vectors B
(numerator) and A . The cutoff frequency Wn must be 0.0 < Wn < 1.0,
with 1.0 corresponding to half the sample rate.
cheb2ord(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Chebyshev Type II
filter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation
in the stopband. Wp and Ws are the passband and stopband edge frequencies,
abs(x) - It gives the absolute value of the elements of x. When x is complex abs(x) is the
complex modulus (magnitude) of the elements of x.
angle(H) - It returns the phase angles of a matrix with complex elements in radians.
freqz(b,a,N) -Syntax of this function is [h,w] = freqz(b,a,N) returns the N-
point frequency vector w in radians and the N-point complex
frequency response vector h of the filter b/a.
stem(y) It plots the data sequence y aa stems from the x axis terminated
with circles for the data value.
stem(x,y) It plots the data sequence y at the values specified in x.
ploy(x,y) It plots vector y versus vector x. If x or y is a matrix, then the
vector is plotted versus the rows or columns of the matrix,
whichever line up.
title(‘text’) It adds text at the top of the current axis.
xlabel(‘text’) It adds text beside the x-axis on the current axis.
2
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Expt. No: 1
AIM:
To generate the following signals using MATLAB 9.0
1. Unit impulse signal
2. Unit step signal
3. Unit ramp signal
4. Exponential growing signal
5. Exponential decaying signal
6. Sine signal
7. Cosine signal
APPARATUS REQUIRED:
System with MATLAB 9.0.
ALGORITHM:
1. Get the number of samples.
2. Generate the unit impulse, unit step using ‘ones’, ‘zeros’ matrix
command.
3. Generate ramp, sine, cosine and exponential signals using corresponding
general formula.
4. Plot the graph.
3
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
UNIT IMPULSE
clc;
clear all;
close all;
t=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(2,2,1);
stem(t,y);
xlabel('time-->.');
ylabel('amplitude-->');
OUTPUT:
4
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Date:
clc;
close all;
clear all;
n=input ('Enter the length of ramp sequence:');
t=0:1:n;
subplot(2,2,3);
stem(t,t);
xlabel('time-->.');
ylabel('amplitude-->');
OUTPUT:
5
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Date:
clc;
clear all;
t=0:.05:pi;
y=sin(2*pi*t);
figure(2);
subplot(2,1,2);
plot(t,y);
xlabel('time-->.');
ylabel('amplitude-->');
OUTPUT:
6
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Date:
clc;
clear all;
t=0:0.05:pi;
y=cos(2*pi*t);
subplot(2,2,2);
plot(t,y);
xlabel('time-->.');
ylabel('amplitude-->');
OUTPUT:
7
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Date:
clear all;
close all;
n=input('Enter the length of the exponential sequence');
t=0:1:n;
a=input('Enter value');
y=exp(a*t);
subplot(2,2,4);
stem(t,y);
ylabel('amplitude-->');
xlabel('time-->.');
Enter value 1
OUTPUT:
RESULTS:-
Thus the generation of continues time signals using matlab was verified
8
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM:
To write the program for finding the linear convolution of two signals using
MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0.
LINEAR CONVOLUTION:
ALGORITHM:
1. Get the number of samples.
2. Generate the output sequence of the given two input signals using
‘conv’ command.
3. Plot the graph.
9
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clc;
clear all;
close all;
y=conv(x,h);
subplot(3,1,1);
stem(x);
ylabel('amplitude x(n)-->');
xlabel('n-->');
subplot(3,1,2);
stem(h);
ylabel('amplitude h(n)-->');
xlabel('n-->');
subplot(3,1,3);
stem(y);
ylabel('amplitude y(n)-->');
xlabel('n-->');
10
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
INPUT:
the resultant b
y = 4 11 20 30 20 11 4
OUTPUT:
RESULTS :-
Thus the program for linear convolution is written using MATLAB and
verified.
11
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM:
To write the program for finding the circular convolution of two signals using
MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0.
CIRCULAR CONVOLUTION:
ALGORITHM:
1. Get the number of samples.
2. Generate the sequence for the given two input signals using ‘zeros’ and
‘ones’ matrix command.
3. Generate the convoluted output sequence of the given two input signals
using ‘conv’ command.
4. Plot the graph.
12
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clc;
clear all;
close all;
a=input('x1(n)');
b=input('x2(n)');
N=length(b);
M=length(a);
c=fft(a,N);
d=fft(b);
e=c.*d;
f=ifft(e);
disp(f);
subplot(1,3,1);
stem(a);
xlabel('time-->');
ylabel('amplitude');
title('x1(n)');
subplot(1,3,2);
stem(b);
xlabel('time');
ylabel('amplitude');
title('x2(n)');
subplot(1,3,3);
stem(f);
xlabel('time');
13
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
ylabel('amplitude');
title('output');
INPUT:
x1(n) [1 2 3 4]
x2(n) [4 3 2 1]
24 22 24 30
RESULTS:-
Thus the program for circular convolution is written using MATLAB and
verified.
14
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Expt. No: 3
Date: CORRELATION
%Cross-CorrelationandAuto-Correlationoffinitesequences
AIM:
To write the program for finding the correlation of two signals using MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0.
CIRCULAR CONVOLUTION:
ALGORITHM:
1. Get the number of samples.
2. Generate the sequence for the given two input signals using ‘zeros’ and
‘ones’ matrix command.
3. Generate the convoluted output sequence of the given two input signals
using ‘conv’ command.
4. Plot the graph.
15
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clc;clearall;closeall;
x=input('EntertheSignalx=');
y=input('EntertheSignaly=');
rxy=xcorr(x,y);%cross-correlation of x and y
rxx=xcorr(x);%Auto-Correlation of x
subplot(221);
stem(x);
xlabel(Time');
ylabel('Amplitude');
title('x(n)');
subplot(222);
stem(y);
xlabel('Time');
ylabel('Amplitude');
title('y(n)');
subplot(223);
stem(rxy);
xlabel('Lag');
ylabel('Amplitude');
title('rxy(k)');
subplot(224);
stem(rxx);
xlabel('Lag');
ylabel('Amplitude'); title('rxx(k)');
16
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
RESULTS:-
Thus the program for correlation of two signals is written using MATLAB and
verified.
Expt. No: 4
17
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM:
To write the program for calculating the N-point FFT and IFFT of given input
sequence using MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0.
ALGORITHM:
1. Get the input sequence and its length.
2. Calculate the Fast Fourier Transform and Inverse Fast Fourier Transform
of given sequence using user defined function.
3. Plot the magnitude and phase response of FFT sequence.
4. Plot the IFFT response.
clc;
18
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clear all;
close all;
b=fft(a);
disp('fft of a sequence');
disp(b);
c=abs(b);
disp('magnitude plot');
disp(c);
d=angle(b);
disp('phase plot');
disp(d);
subplot(3,3,1);
stem(a);
xlabel('time');
ylabel('amplitude');
title('input');
subplot(3,3,2);
stem(b);
xlabel('time');
ylabel('amplitude');
title('fft');
subplot(3,3,3);
stem(c);
xlabel('time');
ylabel('amplitude');
title('magnitude plot');
19
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
subplot(3,3,4);
stem(d);
xlabel('time');
ylabel('amplitude');
title('phaseplot');
Enter the sequence [2 2 2 2 1 1 1 1]
OUTPUT:
fft of a sequence
Columns 1 through 8
12.0000, 1.0000 - 2.4142i , 0 ,1.0000 - 0.4142i ,0 , 1.0000 + 0.4142i , 0 , 1.0000 + 2.4142i
Magnitude plot
12.0000 2.6131 0 1.0824 0 1.0824 0 2.6131
Phase plot
0 -1.1781 0 -0.3927 0 0.3927 0 1.1781
RESULTS:-
Thus the program for fft is written using MATLAB and verified.
Expt. No: 5
20
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM:
To write the program for calculating the N-point DFT and IDFT of given input
sequence using MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0.
ALGORITHM:
1. Get the input sequence and its length.
2. Calculate the DFT and Inverse DFT
of given sequence using user defined function.
3. Plot the magnitude and phase response of DFT sequence.
4. Plot the IDFT response.
clear all;
21
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clc;
n=8;
x=[1,1,1,1,1,1,0,0];
subplot(3,1,1);
stem(x);
xlabel('n-->');
ylabel('amp-->');
title('input');
A=dftmtx(n);
y=A*x';
subplot(3,1,2);
stem(y);
xlabel('n-->');
ylabel('amp-->');
title('dft');
disp(y);
c=abs(y);
disp('magnitude plot');
disp(c);
d=angle(y);
disp('phase plot');
disp(d);
subplot(3,3,1);
stem(x);
xlabel('time');
ylabel('amp');
22
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
title('input');
subplot(3,3,2);
stem(y);
xlabel('time');
ylabel('amp');
title('dft');
subplot(3,3,3);
stem(c);
xlabel('time');
ylabel('amplitude');
title('magnitude plot');
subplot(3,3,4);
stem(d);
xlabel('time');
ylabel('amplitude');
title('phaseplot');
OUTPUT:
23
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
6.0000
-0.7071 - 1.7071i
1.0000 - 1.0000i
0.7071 + 0.2929i
0
0.7071 - 0.2929i
1.0000 + 1.0000i
-0.7071 + 1.7071i
magnitude plot:
6.0000, 1.8478 , 1.4142, 0.7654, 0, 0.7654, 1.4142, 1.8478
phase plot:
0, -1.9635, -0.7854, 0.3927, 0, -0.3927, 0.7854, 1.9635
RESULTS:-
Thus the program for dft is written using MATLAB and verified.
Expt. No: 6
24
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM
To sample the signal and observe the aliasing effect of that signal using
MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0.
ALGORITHM:
1. Get the input frequency and number of samples.
2. The input signal is sampled at the frequencies fs1=2fm, fs2>2fm and
fs3<2fm.
3. Plot the input and sampled signal at various frequencies.
clear all;
25
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clc;
close all;
t=-5:0.1:5;
T=1;
fm=1/T;
x=cos(2*pi*fm*t);
n=-5:0.1:5;
y1=cos(2*pi*fm*n/fs1);
y2=cos(2*pi*fm*n/fs2);
y3=cos(2*pi*fm*n/fs3);
subplot(4,1,1);
plot(t,x);
xlabel('times-->');
ylabel('x(t)-->');
title('input');
subplot(4,1,2);
stem(n,y1);
xlabel('n-->');
ylabel('x(n)==>');
if fs1<2*fm
26
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
else
end
subplot(4,1,3);
stem(n,y2);
xlabel('n-->');
ylabel('x(n)-->');
if fs2<2*fm
else
end
subplot(4,1,4);
stem(n,y3);
xlabel('n-->');
ylabel('x(n)-->');
if fs3<2*fm
else
end
INPUT:
27
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
RESULTS:-
Thus the sample the signal and observe the aliasing effect of that signal using matlab
was verified
Date:
AIM:
To design a Butterworth low pass digital IIR filter using MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter using
5.Find the filter co-efficient.
6.Draw the magnitude and phase response.
clc;
29
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clear all;
clf;
sip=2*fp/f;
sis=2*fs/f;
[n,sic]=buttord(sip,sis,alphap,alphas,'s');
[b a]=butter(n,sic,'low','s');
t=0:0.01:pi;
[h,p]=freqs(b,a,t);
magnitude=20*log(abs(h));
subplot(2,2,1);
plot(p/pi,magnitude);
xlabel('Normailsed frequency-->');
ylabel('Gain in db-->');
ang=angle(h);
subplot(2,2,2);
plot(p/pi,ang);
xlabel('Normalised frequency-->');
ylabel('Phase in radian-->');
30
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
disp('Order of filter:');
disp(n);
disp('cut of frequency:');
disp(sic);
disp('coefficient of numerator');
disp(b);
disp('coefficient of denominator');
disp(a);
[bz,az]=bilinear(b,a,f);
w=0:0.01:pi;
[hz,pz]=freqz(bz,az,w);
magnitude=20*log(abs(hz));
subplot(2,2,3);
plot(pz/pi,magnitude);
xlabel('Normalised frequency-->');
ylabel('Gain in db-->');
ang=angle(hz);
subplot(2,2,4);
plot(pz/pi,ang);
xlabel('Normalised frequency-->');
ylabel('phase in radian-->');
31
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
disp('coefficient of numerator');
disp(bz);
disp('coefficient of denominator');
disp(az);
INPUT:
OUTPUT:
Order of filter:
cut of frequency:
2.5251
coefficient of numerator
0 0 6.3761
coefficient of denominator
32
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
coefficient of numerator
coefficient of denominator
RESULTS:-
33
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM:
To design a Butterworth high pass digital IIR filter using MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter using
5.Find the filter co-efficient.
6.Draw the magnitude and phase response.
clc;
34
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clear all;
clf;
sip=2*fp/f;
sis=2*fs/f;
[n,sic]=buttord(sip,sis,alphap,alphas,'s');
[b a]=butter(n,sic,'high','s');
t=0:0.01:pi;
[h,p]=freqs(b,a,t);
magnitude=20*log(abs(h));
subplot(2,2,1);
plot(p/pi,magnitude);
xlabel('Normailsed frequency-->');
ylabel('Gain in db-->');
ang=angle(h);
subplot(2,2,2);
plot(p/pi,ang);
xlabel('Normalised frequency-->');
ylabel('Phase in radian-->');
35
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
disp('Order of filter:');
disp(n);
disp('cut of frequency:');
disp(sic);
disp('coefficient of numerator');
disp(b);
disp('coefficient of denominator');
disp(a);
[bz,az]=bilinear(b,a,f);
w=0:0.01:pi/10;
[hz,pz]=freqz(bz,az,w);
magnitude=20*log(abs(hz));
subplot(2,2,3);
plot(pz/pi,magnitude);
xlabel('Normalised frequency-->');
ylabel('Gain in db-->');
ang=angle(hz);
subplot(2,2,4);
plot(pz/pi,ang);
xlabel('Normalised frequency-->');
ylabel('phase in radian-->');
36
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
disp('coefficient of numerator');
disp(bz);
disp('coefficient of denominator');
disp(az);
INPUT:
OUTPUT:
Order of filter:
cut of frequency:
2.2177
coefficient of numerator
1 0 0
37
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
coefficient of numerator
coefficient of denominator
RESULTS:-
Expt. No: 8
38
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM: -
ALGORITHM:-
39
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clear all;
alphap=2;
alphas=20;
wp=[0.2*pi,0.4*pi];
ws=[0.1*pi,0.5*pi];
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
[b,a]=cheby1(n,alphap,wn);
w=0.1:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot((ph/pi),m);
grid;
ylabel('gain in db');
xlabel('Normalised Frequency');
subplot(2,1,2);
plot((ph/pi),an);
grid;
xlabel('Normalised Frequency');
ylabel('Phase in radians');
40
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
RESULTS:-
Thus the Amplitude response and phase response of chebyshev type 1 Low
pass filter was verified
41
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM:
To design a FIR filter using Hanning window with MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0
ALGORITHM:
1. Get the pass band and stop band ripple and frequency.
2. Get the sampling frequency.
3. Find the order of filter N.
4. Design the lowpass,High pass,Band pass and Band stop filter.
5. Plot the magnitude response of all the filters.
clc;
clf;
42
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clear all;
wp=input('enter the passband frequency:');
ws=input('enter the stopband frequency:');
n=input('enter the samples:');
m=max(wp,ws);
fs=3*m;
fp=2*wp/fs;
fstop=2*ws/fs;
w=0:.01:pi;
%LPF:
b=fir1(n,fp,'low',hanning(n+1));
h=freqz(b,1,w);
subplot(2,2,1);
plot(w/pi,abs(h));
xlabel('normalised frequency');
ylabel('magnitude');
title('low pass filter');
%HPF:
b=fir1(n,fp,'high',hanning(n+1));
h=freqz(b,1,w);
subplot(2,2,2);
plot(w/pi,abs(h));
xlabel('normalised frequency');
ylabel('magnitude');
title('high pass filter');
%BPF:
b=fir1(n,[fp fstop],'bandpass',hanning(n+1));
h=freqz(b,1,w);
subplot(2,2,3);
plot(w/pi,abs(h));
xlabel('normalised frequency');
ylabel('magnitude');
title('band pass filter');
%BSF:
b=fir1(n,[fp fstop],'stop',hanning(n+1));
h=freqz(b,1,w);
subplot(2,2,4);
plot(w/pi,abs(h));
xlabel('normalised frequency');
43
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
ylabel('magnitude');
title('band stop filter');
OUTPUT:
RESULTS:-
Thus the magnitude response and phase response of fir LPF, HPF,BPF, BSF
using hanning window was verified.
Date:
AIM:
To design a FIR filter using Hamming window with MATLAB 9.0.
APPARATUS REQUIRED:
System with MATLAB 9.0
ALGORITHM:
1. Get the pass band and stop band ripple and frequency.
2. Get the sampling frequency.
3. Find the order of filter N.
4. Design the lowpass,High pass,Band pass and Band stop filter.
5. Plot the magnitude response of all the filters.
45
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clc;
clf;
clear all;
wp=input('enter the passband frequency:');
ws=input('enter the stopband frequency:');
n=input('enter the samples:');
m=max(wp,ws);
fs=3*m;
fp=2*wp/fs;
fe=2*ws/fs;
w=0:.01:pi;
%LPF:
b=fir1(n,fp,'low',hamming(n+1));
h=freqz(b,1,w);
subplot(2,2,1);
plot(w/pi,abs(h));
xlabel('normalised frequency');
ylabel('magnitude');
title('low pass filter');
%HPF:
b=fir1(n,fp,'high',hamming(n+1));
h=freqz(b,1,w);
subplot(2,2,2);
plot(w/pi,abs(h));
xlabel('normalised frequency');
ylabel('magnitude');
title('high pass filter');
%BPF:
b=fir1(n,[fp fe],'bandpass',hamming(n+1));
h=freqz(b,1,w);
subplot(2,2,3);
plot(w/pi,abs(h));
xlabel('normalised frequency');
ylabel('magnitude');
title('band pass filter');
%BSF:
b=fir1(n,[fp fe],'stop',hamming(n+1));
h=freqz(b,1,w);
subplot(2,2,4);
46
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
plot(w/pi,abs(h));
xlabel('normalised frequency');
ylabel('magnitude');
title('band stop filter');
INPUT:
OUTPUT:
RESULTS:-
Thus the magnitude response and phase response of fir LPF, HPF,BPF, BSF
using hamming window was verified.
47
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
(a) UP SAMPLING
AIM:
To write a program to compute Convolution and m-fold interpolation by
polyphase decomposition.
APPARATUS REQUIRED:
System with MATLAB 9.0.
ALGORITHM:
1. Get the input sequence.
2. Get the filter coefficients and also the interpolation factor.
3. Find the response by using convolution.
4. Plot the graph.
clc;
48
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
N=10;
n=0:1:N-1;
x=sin(2*pi*n/10)+sin(2*pi*n/5);
L=3;
x1=[zeros(1,L*N)];
n1=1:1:L*N;
j=1:L:L*N;
x1(j)=x;
subplot(2,1,1);
stem(n,x);
xlabel('n');
ylabel('x');
title('input sequence');
subplot(2,1,2);
stem(n1,x1);
xlabel('n');
ylabel('x1');
title('upsampled sequence');
OUTPUT :
RESULT:
49
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Date:
(b)DOWN SAMPLING
AIM:
To write a program to compute Convolution and m-fold decimation by
polyphase decomposition.
APPARATUS REQUIRED:
System with MATLAB 9.0.
ALGORITHM:
1. Get the input sequence.
2. Get the filter coefficients and also the decimation factor.
3. Find the response by using convolution.
4. Plot the graph.
50
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
clc;
N=50;
n=0:1:N-1;
x=sin(2*pi*n/20)+sin(2*pi*n/15);
M=2;
x1=x(1:M:N);
n1=1:1:N/M;
subplot(2,1,1);
stem(n,x);
xlabel('n');
ylabel('x');
title('input sequence');
subplot(2,1,2);
stem(n1-1,x1);
xlabel('n');
ylabel('x1');
title('downsampled sequence');
OUTPUT:
RESULT:
TMS320C5XProcessor Based
Experiments
4. SQUAREWAVE GENERRATION
52
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Expt. No: 1
AIM:
he hardware experiments in the DSP lab are carried out on the Texas
Instruments TMS320C6713 DSP Starter Kit (DSK), based on the TMS320C6713
floating point DSP running at 225MHz. The basic clock cycle instruction time is
1/(225 MHz)= 4.44 nanoseconds. During each clock cycle, up to eight instructions
can be carried out in parallel, achieving up to 8×225 = 1800 million instructions per
second (MIPS). The DSK board includes a 16MB SDRAM memory and a 512KB
Flash ROM. It has an on-board 16-bit audio stereo codec (the Texas Instruments
AIC23B) that serves both as an A/D and a D/A converter. There are four 3.5 mm
audio jacks for microphone and stereo line input, and speaker and headphone
outputs. The AIC23 codec can be programmed to sample audio inputs at the
following sampling rates: fs = 8, 16, 24, 32, 44.1, 48, 96 kHz The ADC part of the
codec is implemented as a multi-bit third-order noise-shaping delta-sigma
converter) that allows a variety of oversampling ratios that can realize the above
choices of fs. The corresponding oversampling decimation filters act as anti-
aliasing pre-filters that limit the spectrum of the input analog signals effectively to
the Nyquist interval [−fs/2,fs/2]. The DAC part is similarly implemented as a multi-
53
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Schéma de la carte
La carte starter kit TMS320C50 que vous avez à disposition contient (Cf. Figure 1)
- Un DSP TMS320C50 (16 bits, virgule fixe, cycle 50ns)
- Une mémoire PROM de 32 ko
- Un circuit analogique d'interface (AIC) TLC32040
54
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Organisation de la mémoire
La carte starter kit TMS320C50 comprend une mémoire PROM-8bits de 32 K
réservée pour le noyau (kernel) qui est parcourue au démarrage du DSP et une
mémoire RAM de 10 K pour les programmes application. Au niveau CPU (Voir
Figure 3) du TMS320C50, on trouve une Single-Access RAM (SARAM) et trois
(B0,B1,B2) Dual-Access RAM (DARAM). La DARAM B2 est une mémoire tampon
des registres de status.La plan général d'adressage mémoire de la carte TMS320C50
est donnée Figure 2.
55
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
56
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
57
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM:
To study about direct, indirect and immediate addressing modes in
TMS320C50 debugger.
APPARATUS REQUIRED:
1.System with TMS 320C50 debugger software
2.TMS 320C50 Kit.
ALGORITHM:
IMMEDIATE ADDRESSING MODE:
1. Initialize data pointer with 100H data.
2. Load the accumulator with first data.
3. Add the second data with accumulator content.
4. Store the accumulator content in specified address location.
DIRECT ADDRESSING MODE:
1. Initialize data pointer with 100H data.
2. Load the accumulator with first data, whose address is specified in the
instruction.
3. Add the accumulator content with second data, whose address is specified
in the instruction.
4. Store the accumulator content in specified address location.
IN-DIRECT ADDRESSING MODE:
1. Load the auxiliary register with address location of first data.
2. The auxiliary register (AR0) is modified indirectly as # symbol.
3. Load the second data into accumulator and perform addition operation.
4. Store the result.
58
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
PROGRAM:
;program for immediate addressing mode
.mmregs
.text
START:
LDP #100H
LACC #1241H
ADD #1200H
SACL 2H
H: B H
;program for direct addressing mode
.mmregs
.text
START:
LDP #100H
LACC 0H
ADD 1H
SACL 2H
H: B H
;program for adding two numbers with indirect addressing mode.
.mmregs
.text
START:
LAR AR0,#8000H
MAR *,AR0
LACC *+,0 ;WITH ZERO SHIFT
ADD *+
SACL *+
H: B H
RESULT:
Thus, the arithmetic operations using TMS320 kit was performed
successfully.
59
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM:
APPARATUS REQUIRED:
3. RS232 cable
PROGRAM LOGIC:
3. Load the contents of the address data memory location into auxiliary register.
6. Store the 16 LSBs of the accumulator into the address data memory location.
.mmregs
.text
60
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
START:
LDP #100H
LACC 0H ;length of the input is given in 8000
SUB #1H
SACL 1H
LAR AR0,1H
LAR AR1,#8060H;
LAR AR2,#8100H
COPYX2:
MAR *,AR1
LACC *+
MAR *,AR2
SACL *+
MAR *,AR0
BANZ COPYX2,*-
LAR AR0,1H
LAR AR2,#8010H
LOOP3:
LAR AR1,#8060H ;give the inputs x1[n] & h2[n] in AR1 & AR3
LAR AR3,#8050H
LAR AR4,1H
ZAP
LOOP:
MAR *,AR3 ;multiply x1[n] & X2[n] and add the
;multiplication
LT *+
MAR *,AR1 ;output
MPY *+
SPL 5H ;store the partial result at location 8005
ADD 5H ; add the partial result with accumulator
MAR *,AR4
BANZ LOOP,*-,
MAR *,AR2
;outputs of correlation are stored in AR2
SACL *+
CALL ROTATE
LOOP2:
MAR *,AR0
BANZ LOOP3,*-
61
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
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
62
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
INPUT:
; 8000-0004
; 8051 - 0001
; 8052 - 0002
; 8053 - 0001
; 8061 - 0002
; 8062 - 0003
; 8063 - 0004
;OUTPUT:
; 8010-000E
; 8011-0010
; 8012-000E
; 8013-0010
RESULT:
63
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AIM:
APPARATUS REQUIRED:
3. RS232 cable
LINEAR CONVOLUTION
2. LPD will load the 9LSB’s of address data memory. Location or immediate value
into the data pointer (DP) registers.
3. Load auxiliary register (LAR) loads the content of the address data
6. The RPT load the 8 bit LSBs of the addressed value of the RPT.
7. The SACL store the 16 LSBs of the accumulator into the addressed data
memory.
9. The LTP would load the contents of the addressed data memory location into T
register.
11. LACC is used to load the content of the addressed data memory into acc.
64
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.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
INPUT ( x(n) )
65
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
;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
RESULT:
66
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Expt. No: 3
AIM:
APPARATUS REQUIRED:
3.CR0
4.Function Generator.
ALGORITHM:
1. Start the program
subroutine.
7. Store the 16 LSBs of the accumulator into the address data memory
location.
67
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
68
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.word 103
.word 105
.word 106
.word 108
.word 110
.word 112
.word 113
.word 115
.word 117
.word 119
.word 120
.word 122
.word 124
.word 125
.word 127
.word 129
.word 130
.word 132
.word 134
.word 135
.word 137
.word 139
.word 140
.word 142
.word 143
.word 145
.word 146
.word 148
.word 150
.word 151
.word 152
.word 154
.word 155
.word 157
.word 158
.word 160
.word 161
.word 162
.word 164
.word 165
.word 166
.word 168
.word 169
.word 170
.word 171
.word 173
.word 174
.word 175
.word 176
.word 177
.word 178
.word 179
.word 180
.word 181
.word 182
.word 183
.word 184
.word 185
69
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.word 186
.word 187
.word 188
.word 189
.word 189
.word 190
.word 191
.word 192
.word 192
.word 193
.word 193
.word 194
.word 195
.word 195
.word 196
.word 196
.word 197
.word 197
.word 197
.word 198
.word 198
.word 198
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 200
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 198
.word 198
.word 198
.word 197
.word 197
.word 197
.word 196
.word 196
.word 195
.word 195
.word 194
.word 193
.word 193
.word 192
.word 192
.word 191
.word 190
.word 189
.word 189
70
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.word 188
.word 187
.word 186
.word 185
.word 184
.word 183
.word 182
.word 181
.word 180
.word 179
.word 178
.word 177
.word 176
.word 175
.word 174
.word 173
.word 171
.word 170
.word 169
.word 168
.word 166
.word 165
.word 164
.word 162
.word 161
.word 160
.word 158
.word 157
.word 155
.word 154
.word 152
.word 151
.word 149
.word 148
.word 146
.word 145
.word 143
.word 142
.word 140
.word 139
.word 137
.word 135
.word 134
.word 132
.word 130
.word 129
.word 127
.word 125
.word 124
.word 122
.word 120
.word 119
.word 117
.word 115
.word 113
.word 112
.word 110
.word 108
71
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.word 106
.word 105
.word 103
.word 101
.word 99
.word 98
.word 96
.word 94
.word 93
.word 91
.word 89
.word 87
.word 86
.word 84
.word 82
.word 80
.word 79
.word 77
.word 75
.word 74
.word 72
.word 70
.word 69
.word 67
.word 65
.word 64
.word 62
.word 60
.word 59
.word 57
.word 56
.word 54
.word 53
.word 51
.word 49
.word 48
.word 47
.word 45
.word 44
.word 42
.word 41
.word 39
.word 38
.word 37
.word 35
.word 34
.word 33
.word 31
.word 30
.word 29
.word 28
.word 26
.word 25
.word 24
.word 23
.word 22
.word 21
.word 20
72
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.word 19
.word 18
.word 17
.word 16
.word 15
.word 14
.word 13
.word 12
.word 11
.word 10
.word 10
.word 9
.word 8
.word 7
.word 7
.word 6
.word 6
.word 5
.word 4
.word 4
.word 3
.word 3
.word 2
.word 2
.word 2
.word 1
.word 1
.word 1
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 1
.word 1
.word 1
.word 2
.word 2
.word 2
.word 3
.word 3
.word 4
.word 4
.word 5
.word 6
.word 6
73
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.word 7
.word 7
.word 8
.word 9
.word 10
.word 10
.word 11
.word 12
.word 13
.word 14
.word 15
.word 16
.word 17
.word 18
.word 19
.word 20
.word 21
.word 22
.word 23
.word 24
.word 25
.word 26
.word 28
.word 29
.word 30
.word 31
.word 33
.word 34
.word 35
.word 37
.word 38
.word 39
.word 41
.word 42
.word 44
.word 45
.word 47
.word 48
.word 50
.word 51
.word 53
.word 54
.word 56
.word 57
.word 59
.word 60
.word 62
.word 64
.word 65
.word 67
.word 69
.word 70
.word 72
.word 74
.word 75
.word 77
.word 79
.word 80
74
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.word 82
.word 84
.word 86
.word 87
.word 89
.word 91
.word 93
.word 94
.word 96
.word 98
.word 100
.end
RESULT:
75
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
EX.NO:4
Date:
SQUAREWAVE GENERATION
AIM:
APPARATUS REQUIRED:
2. TMS320C50 Kit.
3. CR0
4. Function Generator.
ALGORITHM:
3. Store the 16 LSBs of the accumulator into the address data memory
location.
76
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.mmregs
.text
start:
ldp #100h
loop: sacl 0
cmpl
b loop
.end
RESULT:
77
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Expt. No: 5
AIM:
APPARATUS REQUIRED:
2. TMS320C50 Kit.
3. CR0
4. Function Generator.
ALGORITHM:
accumulator.
memory location
8. Branch the program memory address if the specified conditions are met.
78
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
.MMREGS
.TEXT
START:
LDP #120H
SACL 0
LOOP: LACC 0
OUT 0,04H
SACL 0
BCND LOOP,LEQ
B START
.END
RESULT:
Thus the saw tooth waveform was generated and executed using
TMS320C5X.
79
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
Expt. No: 6
AIM:
APPARATUS REQUIRED:
2. TMS320C50 Kit.
3. CR0
4. Function Generator.
80
SEC - ECE EC8562 – DIGITAL SIGNAL PROCESSING
AMPLITUDE .SET 15
FREQ .SET 43
TEMP .SET 0;
.mmregs
.text
START:
LDP #100H
splk #0,TEMP
CONT1:
lar AR2,#FREQ
CONT:
out TEMP,4
LACC TEMP
ADD #AMPLITUDE
SACL TEMP
MAR *,AR2
BANZ CONT,*-
LAR AR2,#FREQ
CONTx:
OUT TEMP,4
LACC TEMP
SUB #AMPLITUDE
SACL TEMP
MAR *,AR2
BANZ CONTx
B CONT1
.end
RESULT:
Expt. No: 7
AIM:
82