Professional Documents
Culture Documents
Lab Manual Signal and System - DSP SRGI1 Print
Lab Manual Signal and System - DSP SRGI1 Print
(DSP LAB)
Department of
ELECTRONICS & COMMUNICATION ENGINEERING
List of Experiments:
Introduction to MATLAB
2. To explore the commutation of even and odd symmetries in a signal with algebraic
operations.
4. To explore the time variance and time invariance property of a given system.
a. Kaiser (β = 3.5)
b. Hanning
c. Blackman
d. Hamming
e. Triangular
f. Bartlett
The filter’s specs are N = 64 and Rp = 1.4 db
x=-2*pi:.01:2*pi;
y=sinc(x); %sin(pi*x)/pi*x
subplot(232);
plot(x,y);
title('sinc(x)');
t = 0:0.01:3;
y = t; % ramp
subplot(235);
plot(t,y);
title('ramp');
t = 0:0.01:20*pi;
y = sin(t);
subplot(236);
plot(t,y);
title('sin wave');
exponential sinc(x) impulse
30 1 1
20 0.5
0.5
10 0
0 -0.5 0
-5 0 5 -10 0 10 0 50 100
1.5 0.5
2
1 0
1
0.5 -0.5
0 0 -1
0 50 100 0 2 4 0 50 100
Amplitude [f2(t)]
15
10
10
5
5
0 0
-2 0 2 -2 0 2
t (time) t (time)
f3(t) =4*exp(-t/2)*u(t) vs. t f4(t) = -4*exp(-t/2)*u(t) vs. t
5 0
4
Amplitude[f3(t)]
Amplitude[f4(t)]
-5
3
2 -10
1 -15
0
-20
-2 0 2 -2 0 2
t (time) t (time)
AIM2: To explore the commutation of even and odd symmetries in a signal with
algebraic operations.
% Script file: even _ odd
t = -10:0.1:10; % 201points
yzero = zeros(1,201);
y1 = [zeros(1,50) 10*ones(1,50)];
y2 = [10:-.1:0];
y = [y1 y2];
figure(1)
subplot(3,1,1)
plot(t,y);axis([-10 10 -5 13]);
title('f(t) vs. t')
ylabel('Amplitude [f(t)]');xlabel('time');
flipft = fliplr(y);
feven =.5*(y+flipft);
fodd =.5*(y-flipft);
subplot(3,1,2);
plot(t,feven); axis([-10 10 -5 13]);
ylabel('Amplitude [feven(t)]');xlabel('time')
title('feven(t) vs.t')
subplot(3,1,3)
plot(t,fodd,t,yzero);
ylabel('Amplitude [fodd(t)]'); xlabel('time')
title('fodd(t) vs.t')
figure(2)
check = feven+fodd;
ysquare = y.^2;
energyft = trapz(t,ysquare);
poweraveft = (1/200)*energyft;
fevensq = feven.^2;
energyfeven = trapz(t,fevensq);
foddsq = fodd.^2;
energyfodd = trapz(t,foddsq);
disp('*********************************************')
disp('************ ENERGY ANALYSIS **************')
disp('*********************************************')
disp('The energy of f(t) =')
disp(energyft)
disp('The energy of feven(t) =')
disp(energyfeven)
disp('The energy of fodd(t) =')
disp(energyfodd)
disp(' (in joules)')
disp('*********************************************')
disp('*********************************************')
plot(t,check);
title('[feven(t) + fodd(t)] vs. t )');
axis([-10 10 -5 15]);xlabel('time');
ylabel('Amplitude [feven(t) + fodd(t)]')
[feven(t) + fodd(t)] vs. t )
15
10
-5
-10 -8 -6 -4 -2 0 2 4 6 8 10
time
f(t) vs. t
Amplitude [f(t)]
10
5
0
-5
-10 -8 -6 -4 -2 0 2 4 6 8 10
time
feven(t) vs.t
Amplitude [feven(t)]
10
5
0
-5
-10 -8 -6 -4 -2 0 2 4 6 8 10
time
fodd(t) vs.t
Amplitude [fodd(t)]
-5
-10 -8 -6 -4 -2 0 2 4 6 8 10
time
AIM3: To explore the effect of transformation of signal parameters
(amplitude - scaling, timescaling and time-shifting).
A. Time shifting
x = -10:0.1:10;
stepfun = heaviside(x);
subplot(3, 1, 1);
plot(x, stepfun)
xlabel('t (time)')
title('u(t) vs. t')
ylabel('Amplitude.')
axis([-10 10 ,0.5 1.5])
subplot(3, 1, 2);
stepfun = heaviside(x-4);
plot(x, stepfun)
axis([-10 10 ,0.5 1.5])
title('u(t-4) vs. t')
ylabel('Amplitude.');
xlabel('t (time)');
subplot(3, 1, 3);
stepfun = heaviside(x+4);
plot(x, stepfun)
axis([-10 10 ,0.5 1.5])
title('u(t+4) vs. t')
ylabel('Amplitude.');
xlabel('t (time)');
u(t) vs. t
1.5
Amplitude.
0.5
-10 -8 -6 -4 -2 0 2 4 6 8 10
t (time)
u(t-4) vs. t
1.5
Amplitude.
0.5
-10 -8 -6 -4 -2 0 2 4 6 8 10
t (time)
u(t+4) vs. t
1.5
Amplitude.
0.5
-10 -8 -6 -4 -2 0 2 4 6 8 10
t (time)
B. Time scalling
% Script file: rect_ pulses
t = -10:.1:10;
f1 = rectpuls(t);
f2 = rectpuls(2*t);
f3 = rectpuls(t/2);
f4 = rectpuls(t/4);
subplot(2,2,1)
plot (t,f1)
grid on
ylabel (' Amplitude [f1(t)]');xlabel('t (time)');
axis ([-10 10 -0.5 2])
title('Rectpuls f1')
subplot(2,2,2)
plot(t,f2)
grid on
ylabel( 'Amplitude [f2(t)=f1(2*t)]'); xlabel('t (time)');
axis([-10 10 -0.5 2])
title('Rectpuls f2')
subplot(2,2,3)
plot(t,f3)
grid on
axis([-10 10 -0.5 2])
ylabel(' Amplitude [f3(t)]');xlabel(' t (time)')
title('Rectpuls f3')
subplot(2,2,4)
plot(t,f4)
grid on
axis([-10 10 -0.5 2])
title('Rectpuls f4')
ylabel(' Amplitude [f4(t)] '); xlabel(' t (time) ')
Rectpuls f1 Rectpuls f2
2 2
Amplitude [f2(t)=f1(2*t)]
1.5 1.5
Amplitude [f1(t)]
1 1
0.5 0.5
0 0
-0.5 -0.5
-10 -5 0 5 10 -10 -5 0 5 10
t (time) t (time)
Rectpuls f3 Rectpuls f4
2 2
1.5 1.5
Amplitude [f3(t)]
Amplitude [f4(t)]
1 1
0.5 0.5
0 0
-0.5 -0.5
-10 -5 0 5 10 -10 -5 0 5 10
t (time) t (time)
AMPLITUDE SCALLING
t = -10:.1:10;
f1 = rectpuls(t);
f2 = 2*rectpuls(t);
f3 = 4*rectpuls(t);
f4 = -3*rectpuls(t);
subplot(2,2,1)
plot (t,f1)
grid on
ylabel (' Amplitude [f1(t)]');xlabel('t (time)');
axis ([-10 10 -0.5 5])
title('Rectpuls f1=rectpuls(t)')
subplot(2,2,2)
plot(t,f2)
grid on
ylabel( 'Amplitude [f2(t)=f1(2*t)]'); xlabel('t (time)');
axis([-10 10 -0.5 5])
title('Rectpuls f2=2*rectpuls(t)')
subplot(2,2,3)
plot(t,f3)
grid on
axis([-10 10 -0.5 5])
ylabel(' Amplitude [f3(t)]');xlabel(' t (time)')
title('Rectpuls f3=4*rectpuls(t)')
subplot(2,2,4)
plot(t,f4)
grid on
axis([-10 10 -5 5])
title('Rectpuls f4=-3*rectpuls(t)')
ylabel(' Amplitude [f4(t)] '); xlabel(' t (time) ')
Rectpuls f1=rectpuls(t) Rectpuls f2=2*rectpuls(t)
5 5
Amplitude [f2(t)=f1(2*t)]
4 4
Amplitude [f1(t)]
3 3
2 2
1 1
0 0
-10 -5 0 5 10 -10 -5 0 5 10
t (time) t (time)
Rectpuls f3=4*rectpuls(t) Rectpuls f4=-3*rectpuls(t)
5 5
4
Amplitude [f3(t)]
Amplitude [f4(t)]
3
2 0
1
0
-5
-10 -5 0 5 10 -10 -5 0 5 10
t (time) t (time)
AIM4: To explore the time variance and time invariance property of a given
system.
Software Required:
Mat lab software 7.0 and above
Theory:
TIME INVARIENT SYSTEMS(TI):
A system is called time invariant if its input – output characteristics do not change with time
X(t)---- input : Y(t) ---output
X(t-T) -----delay input by T seconds : Y(t-T) ------ Delayed output by T seconds
Program:
clc;
clear all;
close all;
% entering two input sequences
x = input( ' Type the samples of signal x(n) ' );
h = input( ' Type the samples of signal h(n) ' );
% original response
y = conv(x,h);
disp( ' Enter a POSITIVE number for delay ' );
d = input( ' Desired delay of the signal is ' );
% delayed input
xd = [zeros(1,d), x];
nxd = 0 : length(xd)-1;
%delayed output
yd = conv(xd,h);
nyd = 0:length(yd)-1;
disp(' Original Input Signal x(n) is ');
disp(x);
disp(' Delayed Input Signal xd(n) is ');
disp(xd);
disp(' Original Output Signal y(n) is ');
disp(y);
disp(' Delayed Output Signal yd(n) is ');
disp(yd);
xp = [x , zeros(1,d)];
subplot(2,1,1);
stem(nxd,xp);
grid;
xlabel( ' Time Index n ' );
ylabel( ' x(n) ' );
title( ' Original Input Signal x(n) ' );
subplot(2,1,2);
stem(nxd,xd);
grid;
xlabel( ' Time Index n ' );
ylabel( ' xd(n) ' );
title( ' Delayed Input Signal xd(n) ' );
yp = [y zeros(1,d)];
figure;
subplot(2,1,1);
stem(nyd,yp);
grid;
xlabel( ' Time Index n ' );
ylabel( ' y(n) ' );
title( ' Original Output Signal y(n) ' );
subplot(2,1,2);
stem(nyd,yd);
grid;
xlabel( ' Time Index n ' );
ylabel( ' yd(n) ' );
title( ' Delayed Output Signal yd(n) ' );
Result: The Time Invariance of a given Discrete System is verified.
Output:
Type the samples of signal x(n) [2 3 4 6]
Type the samples of signal h(n) [1 2 3 8]
Enter a POSITIVE number for delay
Desired delay of the signal is 5
Original Input Signal x(n) is
2346
Delayed Input Signal xd(n) is
000002346
Original Output Signal y(n) is
2 7 16 39 48 50 48
Delayed Output Signal yd(n) is
0 0 0 0 0 2 7 16 39 48 50 48
Original Input Signal x(n) Original Output Signal y(n)
6 40
30
4
x(n)
y(n)
20
2
10
0 0
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 10
Time Index n Time Index n
Delayed Input Signal xd(n) Delayed Output Signal yd(n)
6 40
4 30
xd(n)
yd(n)
20
2
10
0
0 1 2 3 4 5 6 7 0
0 1 2 3 4 5 6 7 8 9 10
Time Index n
Time Index n
input signal
10
x(n)
0
1 1.5 2 2.5 3 3.5 4
n
impulse response
10
h(n)
0
1 1.5 2 2.5 3 3.5 4
n
linear convolution
200
y(n)
100
0
1 2 3 4 5 6 7
n
AIM 6[ B]: Write the program to compute Auto correlation and Cross correlation
between signals and sequences.
Software Required:
Mat lab software 7.0 and above
Theory:
Correlations of sequences:
It is a measure of the degree to which two sequences are similar. Given two real-valued
sequences x(n) and y(n) of finite energy,
Convolution involves the following operations.
1. Shifting
2. Multiplication
3. Addition
These operations can be represented by a Mathematical Expression as follows:
Program:
clc;
close all;
clear all;
% two input sequences
x=input('enter input sequence');
h=input('enter the impulse suquence');
subplot(2,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
subplot(2,2,2);
stem(h);
xlabel('n');
ylabel('h(n)');
title('impulse signal');
% cross correlation between two sequences
y=xcorr(x,h);
subplot(2,2,3);
stem(y);
xlabel('n');
ylabel('y(n)');
title(' cross correlation between two sequences ');
% auto correlation of input sequence
z=xcorr(x,x);
subplot(2,2,4);
stem(z);
xlabel('n');
ylabel('z(n)');
title('auto correlation of input sequence');
% cross correlation between two signals
% generating two input signals
t=0:0.2:10;
x1=3*exp(-2*t);
h1=exp(t);
figure;
subplot(2,2,1);
plot(t,x1);
xlabel('t');
ylabel('x1(t)');
title('input signal');
subplot(2,2,2);
plot(t,h1);
xlabel('t');
ylabel('h1(t)');
title('impulse signal');
% cross correlation
subplot(2,2,3);
z1=xcorr(x1,h1);
plot(z1);
xlabel('t');
ylabel('z1(t)');
title('cross correlation ');
% auto correlation
subplot(2,2,4);
z2=xcorr(x1,x1);
plot(z2);
xlabel('t');
ylabel('z2(t)');
title('auto correlation ');
Result: Auto correlation and Cross correlation between signals and sequences is computed.
Output: enter input sequence [1 2 5 7]
Enter the impulse sequence [2 6 0 5 3]
input signal
1
x(t)
0
-1
0 1 2 3 4 5 6 7 8 9 10
t
impulse response
1
h(t)
-1
0 1 2 3 4 5 6 7 8 9 10
t
linear convolution
50
y(n)
-50
0 50 100 150 200 250
n
6
4
x(n)
h(n)
4
2
2
0 0
1 2 3 4 1 2 3 4 5
n n
cross correlation between two sequences auto correlation of input sequence
60 80
40 60
y(n)
z(n)
20 40
0 20
-20 0
0 5 10 0 2 4 6 8
n n
AIM 7: To determine Magnitude and Phase Response of Fourier Transform of
given signals.
AIM: To find the Fourier Transform of a given signal and plotting its magnitude and phase
spectrum.
Software Required:
Matlab software 7.0 and above.
clc;
clear all;
close all;
fs=1000;
N=1024; % length of fft sequence
t=[0:N-1]*(1/fs);
% input signal
x=0.8*cos(2*pi*100*t);
subplot(3,1,1);
plot(t,x);
axis([0 0.05 -1 1]);
grid;
xlabel('t');
ylabel('amplitude');
title('input signal');
% magnitude spectrum
x1=fft(x);
k=0:N-1;
Xmag=abs(x1);
subplot(3,1,2);
plot(k,Xmag);
grid;
xlabel('t');
ylabel('amplitude');
title('magnitude of fft signal')
%phase spectrum
Xphase=angle(x1)*(180/pi);
subplot(3,1,3);
plot(k,Xphase);
grid;
xlabel('t');
ylabel('angle in degrees');
title('phase of fft signal');
input signal
1
amplitude
0
-1
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
t
magnitude of fft signal
400
amplitude
200
0
0 200 400 600 800 1000 1200
t
phase of fft signal
angle in degrees
200
-200
0 200 400 600 800 1000 1200
t
Experiment No.9
plot its magnitude and phase plot for 128 discrete frequency points.
PROGRAM:
AIM: Plot frequency response for the normalized LP-FIR filters using the command fir1 in
conjunction with the following windows:
a. Kaiser (β = 3.5)
b. Hanning
c. Blackman
d. Hamming
e. Triangular
f. Bartlett
The filter’s specs are N = 64 and Rp = 1.4 dB
PROGRAM:
format long
hnk = fir1(64,.4,kaiser(65,3.5));
[h1,w1] = freqz(hnk,1,256);
magk = 20*log10(abs(h1));
subplot(3,2,1)
plot(w1,magk)
title('Filter using kaiser win.')
ylabel('gain in db')
subplot(3,2,2)
hnhan = fir1(64,.4,hanning(65));
[h2,w2] = freqz(hnhan,1,256);
maghan = 20*log10(abs(h2));
plot(w2,maghan)
title('Filter using hanning win.')
ylabel('gain in db')
subplot(3,2,3)
hnbla = fir1(64,.4,blackman(65));
[h3,w3] = freqz(hnbla,1,256);
magblac=20*log10(abs(h3));
plot(w3,magblac)
title('Filter using blackman win.')
ylabel('gain in db')
subplot(3,2,4)
subplot(3,2,5)
hntri = fir1(64,.4,triang(65));
[h5,w5] = freqz(hntri,1,256);
magtri = 20*log10(abs(h5));
plot(w5,magtri)
title('Filter using triang. win.')
xlabel('frequency in rad.')
ylabel('gain in db')
axis([0 3 -60 10]);
subplot(3,2,6)
hnbar = fir1(64,.4,bartlett(65));
[h6,w6] = freqz(hnbar,1,256);
magbar = 20*log10(abs(h6));
plot(w6,magbar)
title('Filter using bartlett win.')
xlabel('frequency in rad.')
ylabel('gain in db')
axis([0 3 -60 10])
OUTPUT:
Experiment No.11
AIM: Consider the following continuous signal
x(t) 2 +cos(10t)
Design a low-pass digital filter to filter out the sinusoidal term. Use different windows in the design.
PROGRAM:
clc;
N=11; %using N=11( filter order)
m=(N-1)/2;
thetac=.5;
n=0:N-1;
h=sin(thetac*(n-m+eps))./(pi*(n-m+eps)); %eps is used to avoid dividing by zero
h1=h.*(ones(1,N)); %we window the filter coefficients
h2=h.*(hanning(N))';
n=0:100;
Ts=.1;
xn1=2; %This signal should pass through the filter
xn2=cos(10*n*Ts); %This signal should not pass
xn=xn1+xn2;
t=0:.1:10;
xt=cos(10*t)+2;
y1=filter(h1,1,xn);
y2=filter(h2,1, xn);
subplot(3,1,1);
plot(t,xt);
title('cos(10*t)+2 before filtering');
[H1 f1]=freqz(h1,1,100);
subplot(3,1,2);
plot(f1/pi,abs(H1));
hold on;
[H2 f2]=freqz(h2,1,100);
plot(f2/pi,abs(H2),'*');
legend('Rectangular','Hanning',0);
ylabel('Filter: Order 11');
subplot(3,1,3); plot(n*Ts,y1);
title('The signal after cos(10*t) term is removed: Filter order is 11');
xlabel('Time(sec)'); hold on; plot(n*Ts, y2, '*');
legend('Rectangular','Hanning',0);
OUTPUT:
Experiment No. 12
AIM: Design Butterworth LPF and plot response.
PROGRAM:
clc;
clear;
fp=500; %LPF of cut off 500Hz
fs=600;
samp=2000;
ap=.5;
as=40;
wp=fp/(samp/2);
ws=fs/(samp/2);
[N,wn]=buttord(wp,ws,ap,as);
[b,a]=butter(N,wn);
[H,W]=freqz(b,a,256);
plot(W/(2*pi),20*log10(abs(H)));
n=0:1/samp:1;
x=cos(2*pi*200*n)+cos(2*pi*700*n);
figure(2);
subplot 211, plot(n,abs(fft(x)));
y=filter(b,a,x);
subplot 212, plot(n,abs(fft(y)));
OUTPUT: