Signals Lab Manual
Signals Lab Manual
LIST OF EXPERIMENTS:
2 Correlation of Sequences
It also allows you to put a list of your processing requests together in a file and save
that combined list with a name so that you can run all of those commands in the same
order at some later time. Furthermore, it allows you to run such lists of commands such
that you pass in data. and/or get data back out (i.e. the list of commands is like a
function in most programming languages). Once you save a function, it becomes part of
your toolbox. For those with computer programming backgrounds: Note that MATLAB
runs as an interpretive language (like the old BASIC). That is, it does not need to be
compiled. It simply reads through each line of the function, executes it, and then goes
on to the next line.
Ex. No: 1
Date :
GENERATION OF DISCRETE TIME SIGNALS
AIM:
To generate a discrete time signal sequence (Unit step, Unit ramp, Sine, Cosine,
Exponential, Unit impulse) using MATLAB function.
APPARATUS REQUIRED:
HARDWARE : Personal
amplitude
0.5 0.5
0 0
-4 -2 0 2 4 0 2 4 6 8
time period sequence
unit ramp 17
x 10 exponential sequence
6 3
4 2
amplitude
amplitude
2 1
0 0
0 2 4 6 0 2 4 6 8
sequence time period
OUTPUT: (CONTINUOUS SIGNALS)
17
x 10 continuous exponential sequence
3
amplitude
0
0 1 2 3 4 5 6 7 8
time period
sine wave
1
amplitude
-1
0 0.5 1 1.5 2 2.5 3 3.5
time period
cosine wave
1
amplitude
-1
0 0.5 1 1.5 2 2.5 3 3.5
time period
RESULT:
Thus the MATLAB programs for discrete time signal sequence (Unit step,
Unit ramp, Sine, Cosine, Exponential, Unit impulse) using MATLAB function written
and the results were plotted.
Ex. No: 2
Date:
CORRELATION OF SEQUENCES
AIM:
APPARATUS REQUIRED:
PROCEDURE:
6. If any error occurs in the program correct the error and run it again
RESULT:
Thus the MATLAB programs for auto correlation and cross correlation
written and the results were plotted.
Ex. No: 3
Date:
To write MATLAB programs to find out the linear convolution and Circular
convolution of two sequences.
APPARATUS REQUIRED:
PROCEDURE:
6. If any error occurs in the program correct the error and run it again
%convolution operation
y=conv(x,h);
%to plot the signal
subplot(3,1,1);
stem(x);
ylabel('amplitude');
xlabel('n1....>');
title('input sequence')
subplot(3,1,2);
stem(h);
ylabel('amplitude');
xlabel('n2....>');
title('impulse signal')
subplot(3,1,3);
stem(y);
ylabel('amplitude');
xlabel('n3');
disp('the resultant signal is');y
%circular convolution
clc;
clear all;
close all;
%to get the input sequence
g=input('enter the input sequence');
h=input('enter the impulse sequence');
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2
%loop for getting equal length sequence
if(N3>=0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
%computation of circular convoluted sequence
for n=1:N;
y(n)=0;
for i=1:N;
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+g(i)*h(j);
end
end
figure;
subplot(3,1,1);
stem(g);
ylabel('amplitude');
xlabel('n1..>');
title('input sequence')
subplot(3,1,2);
stem(h);
ylabel('amplitude');
xlabel('n2');
title('impulse sequence')
subplot(3,1,3);
stem(y);
ylabel('amplitude');
xlabel('n3');
disp('the resultant signal is');
OUTPUT : LINEAR CONVOLUTION
Enter the length of input sequence 4
Enter the length of impulse sequence 4
Enter the input sequence [1 2 3 4]
Enter the impulse sequence [4 3 2 1]
input sequence
4
amlitude
0
1 1.5 2 2.5 3 3.5 4
n1....>
impulse signal
4
amlitude
0
1 1.5 2 2.5 3 3.5 4
n2....>
40
amlitude
20
0
1 2 3 4 5 6 7
n3
OUTPUT : CIRCULAR CONVOLUTION
Enter the input sequence [1 2 2 1]
Enter the impulse sequence [4 3 2 1]
input sequence
2
amplitude
0
1 1.5 2 2.5 3 3.5 4
n1..>
impulse sequence
4
amplitude
0
1 1.5 2 2.5 3 3.5 4
n2
20
amplitude
10
0
1 1.5 2 2.5 3 3.5 4
n3
RESULT:
Thus the MATLAB programs for linear convolution and circular convolution
written and the results were plotted.
Ex. No: 4
Date:
FREQUENCY ANALYSIS USING DFT
AIM:
To write MATLAB program for Frequency analyzing signal using DFT.
APPARATUS REQUIRED:
SOFTWARE : MATLAB
PROCEDURE:
14. If any error occurs in the program correct the error and run it again
fft
12
10
8
imaginary axis
0
1 2 3 4 5 6 7 8
real axis
PROGRAM: (Spectrum Analysis Using DFT)
N=input('type length of DFT= ');
T=input('type sampling period= ');
freq=input('type the sinusoidal freq= ');
k=0:N-1;
f=sin(2*pi*freq*1/T*k);
F=fft(f); stem(k,abs(F));
grid on; xlabel('k');
ylabel('X(k)');
INPUT:
type length of DFT=32 type
sampling period=64
type the sinusoidal freq=11
RESULT:
Thus the Spectrum Analysis of the signal using DFT is obtained using MATLAB.
Ex. No: 5a
Date:
To write a program to design the FIR low pass, High pass, Band pass and Band
stop filters using RECTANGULAR window and find out the response of the filter by
using MATLAB.
APPARATUS REQUIRED:
PROCEDURE:
1. Start the MATLAB program.
6. If any error occurs in the program correct the error and run it again
%highpass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
ylabel('gain in db......>');
xlabel('(b)normalized frequency......>');
%bandpass filter
wn=[wp ws];0
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
ylabel('gain in db....>');
xlabel('(c)normalized frequency....>');
%bandstop filter
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
ylabel('gain in db....>');
xlabel('(d)normalized frequency.....>');
G a in in d
b--------.
b--------.
LPF 50 50
0 0
-50 -50
-100 -100
0 0.5 1 0 0.5 1
Normalized freqency------> Normalized freqency------>
MAGNITUDE RESPONSE OF MAGNITUDE RESPONSE OF BSF
G a in in d
G a in in d
BPF 50
b--------.
b--------.
20
0
0
-20
-50
-40
-100 -60
0 0.5 1 0 0.5 1
Normalized freqency------> Normalized freqency------>
RESULT:
Thus the program to design FIR low pass, high pass, band pass and band stop
Filters using RECTANGULAR Window was written and response of the filter using
MATLAB was executed.
Ex. No: 5b
Date:
DESIGN OF FIR FILTERS
(HANNING WINDOW DESIGN)
AIM:
To write a program to design the FIR low pass, High pass, Band pass and
Band stop filters using HANNING window and find out the response of the filter by
using MATLAB.
APPARATUS REQUIRED:
PROCEDURE:
1. Start the MATLAB program.
6. If any error occurs in the program correct the error and run it again
%lowpass filter
b=fir1(n,wp,Y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
ylabel('gain in db....>');
xlabel('(a)normalized frequency');
%highpass filter
b=fir1(n,wp,'high',Y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
ylabel('gain in db...>');
xlabel('(b)normalized frequency...>');
%bandpass filter
wn=[wp ws];
b=fir1(n,wn,Y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
ylabel('gain in db.....>');
xlabel('(c)normalized frequency....>');
%bandstop filter
b=fir1(n,wn,'stop',Y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
ylabel('gain in db...>');
xlabel('(d)normalized frequency....>')
Gain in db--------.
MAGNITUDE RESPONSE OF LPF MAGNITUDE RESPONSE OF HPF
50 50
0
0
-50
-100 -50
-150 -100
0 0.5 1 0 0.5 1
Gain in db--------.
Gain in db--------.
0
-50
-5
-100 -10
0 0.5 1 0 0.5 1
Normalized freqency------> Normalized freqency------>
RESULT:
Thus the program to design FIR low pass, high pass, band pass and
band stop Filters using HANNING Window was written and response of the
filter using MATLAB was executed.
Ex. No: 6
Date:
DESIGN OF IIR FILTERS
AIM:
To write a program to design the IIR Butterworth & Chebyshew Filter (LPF/HPF/BPF/BSF) by
using MATLAB.
APPARATUS REQUIRED:
PROCEDURE:
1. Start the MATLAB program.
6. If any error occurs in the program correct the error and run it again
lpf hpf
1 1
abs(h)
abs(h)
0.5 0.5
0 0
0 1 2 3 4 0 1 2 3 4
normalized frequency normalised frquency
bpf bsf
1 1
abs(h)
abs(h)
0.5 0.5
0 0
0 1 2 3 4 0 1 2 3 4
normalised frequency normalised frequency
PROGRAMS: IIR (CHEBYSHEW FILTER)
% chebyshew filter
% get the input values
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband frequency');
ws=input('enter the stopband frequency');
fs=input('enter the sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
%filter order
[n,wn]=cheb1ord(w1,w2,rp,rs);
%lowpass filter
%either coefficient
[b,a]=cheby1(n,rp,wn);
%frequency response
[H,w]=freqz(b,a,512);
subplot(2,2,1);
plot(w,abs(H));
xlabel('normalised frequency');
ylabel('abs(H)');
title('LPF')
%high pass filter
%filter coefficient
[b,a]=cheby1(n,rp,wn,'High');
%frequency response
[H,w]=freqz(b,a,512);
subplot(2,2,2);
plot(w,abs(H));
xlabel('normalised frequency');
ylabel('abs(H)');
title('HPF')
%band pass filter
%filter coefficient
wn1=[w1,w2];
[b,a]=cheby1(n,rp,wn1);
%frequency response
[H,w]=freqz(b,a,512);
subplot(2,2,3);
plot(w,abs(H));
xlabel('normalised frequency');
ylabel('abs(H)');
title('BPF')
%band stop filter
%filter coefficient
wn2= [w1, w2];
%frequency response
[b,a]=cheby1(n,rp,wn2,'stop');
[H,w]=freqz(b,a,512);
subplot(2,2,4);
plot(w,abs(H));
xlabel('normalised frequency');
ylabel('abs(H)');
title('BSF')
LPF HPF
1 1
abs(H)
abs(H)
0.5 0.5
0 0
0 1 2 3 4 0 1 2 3 4
normalised frequency normalised frequency
BPF BSF
1 1
abs(H)
abs(H)
0.5 0.5
0 0
0 1 2 3 4 0 1 2 3 4
normalised frequency normalised frequency
RESULT:
Thus the program to design IIR Butterworth & Chebyshew Filter (LPF/HPF/BPF/BSF) by
using MATLAB was executed.