BEC 453_signals & systems lab manual
BEC 453_signals & systems lab manual
LAB MANUAL
LAB MANUAL
KEC 453
1. Introduction to MATLAB
a. To study various MATLAB commands for creating two- and three-dimensional plots.
b. Write a MATLAB program to plot the following continuous time and discrete time signals.
i. Step Function
v. Sine Function
4. Convolution of given signals Write a MATLAB program to obtain linear convolution of the
given sequences.
a. Write a MATLAB program to compute autocorrelation of a sequence x(n) and verify the
property.
iii
b. Write a MATLAB program to compute cross-correlation of sequences x(n) and y(n) and
a. Write a MATLAB program to find the impulse response and step response of a system
a. Write a MATLAB program to find pole-zero diagram, bode diagram of a given system
b. Write a MATLAB program to find, bode diagram of a given system from the given
system function.
9. Frequency response of a system Write a MATLAB program to plot magnitude and phase
Additional Experiments:
iv
Course Outcomes as per the AKTU Syllabus
CO1 3 3 2 3 3 3 3 2
CO2 3 3 2 3 3 3 3 2
CO3 3 3 2 3 3 3 3 2
CO4 3 3 2 3 3 3 3 2
CO5 3 3 3 3 3 3 3 3
CO6 3 3 2 3 3 3 3 2
CO7 3 3 3 3 3 3 3 3
v
Index
S.No Experiment Page. No
1 Introduction to MATLAB 1
vi
EXPERIMENT NO - 1
OBJECTIVE: Introduction to MATLAB
a. To define and use variables and functions in MATLAB.
b. To define and use Vectors and Matrices in MATLAB.
c. To study various MATLAB arithmetic operators and mathematical functions.
d. To create and use m-files.
THEORY: The name MATLAB stands for MATrix LABoratory. MATLAB is a high-
performance language for technical computing.
The variables are created with an assignment statement. The syntax of variable assignment is
Variable name = a value (or an expression).
Matrices are the basic elements of the MATLAB environment. A matrix is a two-dimensional
array consisting of m rows and n columns. Special cases are column vectors (n = 1) and row
vectors (m = 1). All of the data that we enter into MATLAB is stored in the form of a matrix.
Various mathematical functions defined in MATLAB are
1
% is used for comment line in MATLAB.
MATLAB CODE:
clc;
close all;
clear all;
Variable assignment:
a=5; % Scalar
a= [1 2 3] or [1,2,3] or a= 1:3 ; % Row vector
a= [1;2;3] ; % Column vector
a=[1 2 3; 4 5 6; 7 8 9] ; % Matrix
Arithmatic operation:
a=5 ; b=4;
c=a+b ;
c=a-b ;
c=a*b ;
c=a^b ;
c=a/b ;
Mathematical function
t = 0:pi/100:2*pi ;
y = sin(t) ;
plot(t,y) % plot the y versus t
2
EXPERIMENT NO - 2
THEORY:
Discrete – Time signals
• Unit impulse sequence.
1, for n = 0
x ( n) = ( n) =
0, otherwise
• Unit step sequence.
1, for n 0
x ( n ) = u( n ) =
• Unit ramp sequence. 0, otherwise
n, for n 0
x ( n) = r ( n) =
• Sinusoidal sequence 0, otherwise
x(n) = A sin(n + )
• Exponential sequence x(n) = A an, where A and a are constant.
1, for t = 0
• Unit impulse signal x (t ) =. (t ) =
(Ar
0, otherwise
1, for t 0
• Unit step signal. x (t ) = u(t ) =
0, otherwise
6. zeros:
zeros (N) is an N-by-N matrix of Zeros.
zeros (M,N) or zeros ([M,N]) is an M-by-N matrix of zeros
MATLAB CODE:
clc;
clear all;
close all;
t1=-3:1:3;
x1=[0,0,0,1,0,0,0];
subplot(3,3,1);
stem(t1,x1);
xlabel('time');
ylabel('Amplitude');
title('Unit impulse signal');
%UNIT STEP SIGNAL
t2=-5:1:25;
x2=[zeros(1,5),ones(1,26)];
subplot(3,3,2);
plot(t2,x2);
4
xlabel('time');
ylabel('Amplitude');
title('CT Unit step signal');
subplot(3,3,3);
stem(t2,x2);
xlabel('time');
ylabel('Amplitude');
title('DT Unit step signal');
%UNIT RAMP SIGNAL
t4=-10:1:20;
x4= [zeros(1,10),0:20];
subplot(3,3,4);
plot(t4,x4);
xlabel('time');
ylabel('Amplitude');
title('CT Unit ramp signal');
subplot(3,3,5)
stem(t4,x4);
xlabel('time');
ylabel('Amplitude');
title('DT Unit ramp signal');
%EXPONENTIAL SIGNAL
a= 4;
t3=-1:0.1:2;
x3=exp(-1*a*t3);
subplot(3,3,6);
plot(t3,x3);
xlabel('time');
ylabel('Amplitude');
title('CT Exponential signal');
subplot(3,3,7);
plot(t3,x3);
xlabel('time');
ylabel('Amplitude');
title('DT Exponential signal');
%SINUSOIDAL SIGNAL
A=4;
f=5;
t5=-1:0.01:1;
x5=A*sin(2*pi*f*t5);
5
subplot(3,3,8);
plot(t5,x5)
xlabel('time');
ylabel('Amplitude');
title('CT Sinusoidal signal');
subplot(3,3,9);
stem(t5,x5)
xlabel('time');
ylabel('Amplitude');
title('DT Sinusoidal signal');
RESULT: 2-D and 3-D plotting are performed. Continuous time domain and Discrete time
signals are plotted.
OUTPUT:
6
EXPERIMENT NO - 3
OBJECTIVE: Time and Amplitude transformations
a. Write a MATLAB program to perform amplitude-scaling, time-scaling and time-shifting
on a given signal.
THEORY: Amplitude-Scaling of Signal: There are some important properties of signal such as
amplitude-scaling, time-scaling and time-shifting. Consider a signal x(t) which is multiplying by
a constant 'A' and this can be indicated by a notation x(t) → Ax(t). This is called amplitude-
scaling. If the amplitude-scaling factor is negative then it flips the signal with the t-axis as the
rotation axis of the flip. If the scaling factor is -1 then only the signal will be flip. This is shown
in the figures given below:
Time-Scaling of Signal: Time scaling compresses or expand a signal by multiplying the time
variable by some quantity. If that quantity is greater than one, the signal becomes narrower and
the operation is called compression. If that quantity is less than one, the signal becomes wider
and the operation is called expansion. Below figure shows the signal x(t), compression of signal
and expansion of signal respectively.
Time-Shifting of Signal: If a continuous time signal is defined as x(t) = s(t - t1). Then we can say
that x(t) is the time shifted version of s(t). Consider a simple signal s(t) for 0 < t < 1
7
Signal within 0< t < 1 Signal shifted by 2 sec. Signal shifted by -1 sec.
MATLAB CODE:
1. Amplitude Scaling
clc
clear all
close all
t = [-4:5];
y = [0, 2,3,1,4,1,2,2,3,0];
plot(t,y);
y1 = y * -1;
y2 = y * 0.5;
y3 = y * 3;
subplot(2,2,1);
plot(t,y);
xlabel('Time');
ylabel('y(t)');
grid on
subplot(2,2,2);
plot(t,y1);
xlabel('Time');
ylabel('{y_1}(t)');
grid on
subplot(2,2,3);
plot(t,y2);
xlabel('Time');
ylabel('{y_2}(t)');
grid on
subplot(2,2,4);
plot(t,y3);
xlabel('Time');
ylabel('{y_3}(t)');
8
grid on
sgtitle('Amplitude Scaling')
2. Time Scaling
clc
clear all
close all
t = -1:0.01:1;
y = sin(2*pi*1*t);
subplot(2,2,1);
plot(t,y);
xlabel('Time');
ylabel('y(t)');
grid on
subplot(2,2,2);
plot(t/2,y);
xlabel('Time');
ylabel('y(t/2)');
grid on
subplot(2,2,3);
plot(t*2,y);
xlabel('Time');
ylabel('y(2t)');
grid on
subplot(2,2,4);
plot(t*10,y);
xlabel('Time');
ylabel('y(10t)');
grid on
sgtitle('Time Scaling')
3. Time Shifting
RESULT: Effects of amplitude scaling, time scaling and time shifting has been observed. This
helps to understand how signal can be modify using mathematical operations.
OUTPUT:
9
10
EXPERIMENT NO - 4
OBJECTIVE: Convolution of given signals
Write a MATLAB program to obtain linear convolution of the given sequences.
THEORY: Linear convolution is the basic operation to calculate the output for any linear time
invariant system given its input and its impulse response. If the response of the system to the
impulse signal is known,then the response to any other input to the system can be found out by
convolving the input signal with impulse response.
MATLAB CODE:
clc;
clear all;
close all;
n=0:8;
x1=1;
x2=0;
y1=x1.*(n>=0 & n<=2)+x2.*(n>=2 & n<=8);
subplot(2,2,1);
stem(n,y1);
axis([0 8 0 1.5]);
xlabel('Time n ---->');
ylabel('Amplitude---->');
title('Sequence {y_1}[n]')
y2=x1.*(n>=0 & n<=4)+x2.*(n>=4 & n<=8);
subplot(2,2,2);
11
stem(n,y2);
axis([0 8 0 1.5]);
xlabel('Time n ---->');
ylabel('Amplitude---->');
title('Sequence {y_2}[n]')
y=conv(y1,y2);
L=length(y);
n=0:L-1;
subplot(2,2,[3,4]);
stem(n,y);
axis([0 10 0 4]);
xlabel('Time n ---->');
ylabel('Amplitude---->');
title('Convolved sequence of {y_1}[n] & {y_2}[n]');
RESULT: Convolution of two discrete sequence has been performed using MATLAB and it can
be observed that length of output sequence is addition of two input sequence minus one.
OUTPUT:
12
EXPERIMENT NO - 5
OBJECTIVE: Autocorrelation and Cross-correlation
a. Write a MATLAB program to compute autocorrelation of a sequence x(n) and
verify the property.
b. Write a MATLAB program to compute cross-correlation of sequences x(n) and
y(n) and verify the property.
THEORY: Correlation is a measure of similarity between two signals. For given discrete-time
real sequence x[k]. The autocorrelation function is defined by following equation:
Using the definition for the total discrete-time signal energy, we see that for k=0, the
autocorrelation function represents the total signal energy that is:
Naturally, the autocorrelation sum is convergent under assumptions that the signal x[k] have
finite total energy. In addition, it is easy to show that the autocorrelation function is an even
function, that is
Hence, the autocorrelation function is symmetric with respect to the vertical axis.
MATLAB CODE:
% Autocorrelation
fs = 2000;
t1 = 0 : 1/fs : 0.2; % for 200 milliseconds
x = sin(2*pi*100*t1) + sin(2*pi*200*t1);
subplot(2,1,1);
plot(t1*1000,x);
xlabel('Time(milliseconds)');
13
ylabel('Amplitude');
title('Input Signal');
[acf lag] = xcorr(x); % k=lag = 2*N-1 (length)
subplot(2,1,2);
plot(lag/(fs/1000),acf);
xlabel('Lag in milliseconds');
ylabel('Amplitude');
title('Autocorrelation of above signal');
RESULT: It can be easily deduced that autocorrelation of given function is even function and
symmetry about y axis. It can also be observe that at k=0 (lag =0) value of autocorrelation
function is maximum and proportional to energy of given sequence x[n].
OUTPUT:
14
EXPERIMENT NO - 6
OBJECTIVE: Calculating transforms using MATLAB
a. Calculate and plot Fourier Transform of a given signal.
b. Calculate and plot Z-transform of a given signal.
THEORY: A fast Fourier transform (FFT) algorithm computes the discrete Fourier transform
(DFT) of a sequence, or its inverse (IFFT). Fourier analysis converts a signal from its original
domain (often time or space) to a representation in the frequency domain and vice versa. An FFT
rapidly computes such transformations by factorizing the DFT matrix into a product of sparse
(mostly zero) factors. As a result, it manages to reduce the complexity of computing the DFT
from O(n2), which arises if one simply applies the definition of DFT, to O(n log(n)), where n is
the data size.
Z transform enables analysis of the signal in the frequency domain. It takes the form of a
polynomial and interpretation of the signal in terms of the roots of the polynomial. z-1
corresponds to a delay of one unit in the signal.
where z = r ejw
MATLAB CODE:
subplot(2,1,1);
15
plot(t*1000,x);
xlabel('t (milliseconds)');
ylabel('x(t)');
title('Signal in Time Domain');
y=fft(x,500);
mag1 = abs(y);
mag1 = mag1(1:250);
k=[0:length(mag1)-1];
k=k*(sampling_freq/length(y));
subplot(2,1,2);
plot(k,mag1);
xlabel('Frequency(Hz)');
ylabel('Power');
title('FFT of x(t)');
RESULT: Given signal was analyzed using FFT algorithm and observed that frequency
components of can be analyzed efficiently. Z-transform of finite sequence is calculated.
OUTPUT:
1. Fourier Transform
16
2. Z-Transform
17
EXPERIMENT NO - 7
OBJECTIVE: Impulse response and Step response of a given system
a. Write a MATLAB program to find the impulse response and step response
of a system form its difference equation.
b. Compute and plot the response of a given system to a given input.
THEORY: The response of a discrete-time system to a unit sample sequence {δ[n]} is called the
unit sample response or simply, the impulse response, and is denoted by {h[n]}
The response of a discrete-time system to a unit step sequence {u[n]} is called the unit step
response or simply, the step response, and is denoted by {s[n]}
MATLAB CODE:
18
t=0:0.1:20;
h1=subs(h,t);
figure(1)
subplot(2,1,1);
plot(t,h1);
xlabel('Time');
ylabel('h(t)');
title('Impulse response of the system');
y1=subs(y,t);
subplot(2,1,2);
plot(t,y1);
xlabel('Time');
ylabel('x(t)');
title('Step response of the system');
% The response of a given system to a given input
n=[1 5 ];
d= [1 2 3 5];
t=0:0.15:9;
r=exp(-0.2*t);
y=lsim(n,d,r,t);
figure(2)
plot(t,r,t,y);
title ('System response of given transfer function for ramp input');
xlabel('Time(secs)');
ylabel('Amplitude');
19
OUTPUT:
20
EXPERIMENT NO - 8
OBJECTIVE: Pole-zero diagram and bode diagram
a. Write a MATLAB program to find pole-zero diagram of a given system from
the given system function.
b. Write a MATLAB program to find bode diagram of a given system from the
given system function.
THEORY: A system is often defined in terms of the poles and zeros of its transfer function.
A system can be defined by its transfer function, which is a ratio of polynomials in the Laplace
variable "s." For example consider the transfer function:
In this equation the constant k=b0/a0. The zi terms are the zeros of the transfer function; as
s→zi the numerator polynomial goes to zero, so the transfer function also goes to zero. The
pi terms are the poles of the transfer function; as s→pi the denominator polynomial is zero, so the
transfer function goes to infinity.
MATLAB CODE:
% pole-zero diagram
clc;
clear all;
close all;
num=input('enter the numerator polynomial vector\n'); % [1 -2 1]
den=input('enter the denominator polynomial vector\n'); % [1 6 11 6]
H=tf(num,den)
[p z]=pzmap(H);
disp('zeros are at ');
disp(z);
disp('poles are at ');
disp(p);
pzmap(H);
if max(real(p))>=0
disp(' All the poles do not lie in the left half of S-plane ');
disp(' Given LTI systen is not a stable system ');
21
else
disp('All the poles lie in the left half of S-plane ');
disp(' Given LTI systen is a stable system ');
end;
% Bode diagram of s + 12 /2 s2 + s + 4
clc
clear all
num=[1, 12];
den=[2, 1, 4];
system=tf(num,den)
bode(system)
RESULT: Pole-Zero plot and bode plot of given system function is drawn.
OUTPUT:
Transfer function:
s^2 - 2 s + 1
----------------------
s^3 + 6 s^2 + 11 s + 6
Zeros are at
1
1
Poles are at
-3.0000
-2.0000
-1.0000
All the poles lie in the left half of S-plane. The given LTI system is a stable system
22
23
EXPERIMENT NO - 9
OBJECTIVE: Frequency response of a system
a. Write a MATLAB program to plot magnitude and phase response of a given
system.
THEORY: Frequency response is the quantitative measure of the output spectrum of a system or
device in response to a stimulus, and is used to characterize the dynamics of the system. It is a
measure of magnitude and phase of the output as a function of frequency, in comparison to the
input. In simplest terms, if a sine wave is injected into a system at a given frequency, a linear
system will respond at that same frequency with a certain magnitude and a certain phase angle
relative to the input. Also for a linear system, doubling the amplitude of the input will double the
amplitude of the output.
MATLAB CODE:
( s − 1) s −1
% for example H ( s ) = = 2
( s + 4) 2
s + 8s + 8
clc;
clear all;
close all;
syms t s ;
syms w float;
num=[0 1 -1]; % defining numerator
den=[1 8 8]; % defining denominator
w=-2*pi:pi/50:2*pi; % defining frequency
[H,w]= freqs(num,den,w); % determining frequency response of system
24
RESULT: The plot of magnitude and phase response of a given system has been done.
OUTPUT:
25
EXPERIMENT NO - 10
OBJECTIVE: Checking Linearity/Non-Linearity of a system using SIMULINK
a. Build a system that amplifies a sine wave by a factor of two.
b. Test the linearity of this system using SIMULINK.
THEORY:
Linearity: Suppose that when one inputs is x1 to a system, the output of the system is y1, and
when other input is x2 to a system, the output of the system is y2. A system is said to be linear if
the input to the system is α1x1+ α 2x2, then the output of the system will be α1y1 + α2y2. Linear
systems are said to satisfy the principle of superposition.
Simulink: To see when a system is linear and when it is not, we make use of Simulink a
MATLAB “add-on." Simulink is, essentially, a graphical user interface (GUI) to MATLAB. It
allows to drag-and-drop blocks to build up a system.
SIMULINK OPERATION:
1. To open Simulink, type “simulink" at the MATLAB command prompt. Alternatively click on
the Simulink icon on the toolbar in the main MATLAB window.
2. After performing either of these actions, the Simulink Library Browser will open. After it has
opened, click on the blank page in this window's toolbar to open a new Simulink page.
3. To start working, drag and drop items from the library browser into the worksheet, connects
the items and run the simulation.
26
6. In order to improve the quality of the sine wave, click on the sine wave block again and
change the sample time from zero to 0.001s.
1. To copy a block, hold down the control key, left-click on the block and drag the copy to
wherever it is needed.
2. The summing block (the circle with the pluses inside) is located in the “Math Operations"
library.
3. Double clicking on the summing block opens up a dialog box that allows change from sums to
differences.
4. In order to open a scope window, double click on the scope of interest. If one does not see the
whole signal on a scope, go to the scope window. Go to the “parameters" tab (the second tab
from the left) and click on it. A dialog box will open. Click on the “data history" tab, and unclick
the “limit data points to last" box.
OUTPUT:
27
EXPERIMENT NO - 11
OBJECTIVE: Verification of sampling theorem using MATLAB..
THEORY: The sampling theorem specifies the minimum-sampling rate at which a continuous-
time signal needs to be uniformly sampled so that the original signal can be completely
recovered or reconstructed by these samples alone. This is usually referred to as Shannon's
sampling theorem in the literature.
A band-limited signal can be reconstructed exactly if it is sampled at a rate at least twice the
maximum frequency component in it.
Aliasing:
In reconstructing a signal from its samples, there is another practical difficulty. The sampling
theorem was proved on the assumption that the signal x(t) is bandlimited. All practical signals
are time limited, i.e., they are of finite duration. As a signal cannot be time limited and
bandlimited simultaneously
MATLAB CODE:
t=-10:.01:10;
T=4;
fm=1/T;
x=cos(2*pi*fm*t);
subplot(2,2,1);
plot(t,x);
xlabel('Time');
ylabel('x(t)')
title('Continous time signal')
grid;
n1=-4:1:4
fs1=1.6*fm;
fs2=2*fm;
fs3=8*fm;
x1=cos(2*pi*fm/fs1*n1);
subplot(2,2,2);
stem(n1,x1);
xlabel('Time');
ylabel('x(n)')
title('Discrete time signal with fs<2fm')
hold on
subplot(2,2,2);
plot(n1,x1)
28
grid;
n2=-5:1:5;
x2=cos(2*pi*fm/fs2*n2);
subplot(2,2,3);
stem(n2,x2);
xlabel('Time');
ylabel('x(n)')
title('Discrete time signal with fs=2fm')
hold on
subplot(2,2,3);
plot(n2,x2)
grid;
n3=-20:1:20;
x3=cos(2*pi*fm/fs3*n3);
subplot(2,2,4);
stem(n3,x3);
xlabel('Time');
ylabel('x(n)')
title('Discrete time signal with fs>2fm')
hold on
subplot(2,2,4);
plot(n3,x3)
grid;
RESULT: In this experiment the sampling theorem have been verified using MATLAB.
29
OUTPUT:
30
EXPERIMENT NO - 12
OBJECTIVE: Implementation of decimation and interpolation processes using MATLAB
THEORY:
Interpolation is the process of increasing the sampling frequency of a signal to a higher sampling
frequency that differs from the original frequency by an integer value. Interpolation also is
known as up-sampling. The spectrum of the output signal ideally is the same as the input signal
spectrum, except the output signal spectrum contains an additional high-frequency region with
zero-power density.
Down sampling, compression, and decimation are terms associated with the process of
resampling in a multi-rate digital signal processing system. Both down sampling and decimation
can be synonymous with compression, or they can describe an entire process of bandwidth
reduction (filtering) and sample-rate reduction. When the process is performed on a sequence of
samples of a signal or a continuous function, it produces an approximation of the sequence that
would have been obtained by sampling the signal at a lower rate (or density, as in the case of a
photograph).
MATLAB CODE:
clear all;
close all;
fs=1000; %Sampling frequency
a=1.5; %relative amplitudes
b=1;
f1=100; %Values of f1 and f2
f2=200;
t=0:1/fs:1; %time vector
x=a*cos(2*pi*f1*t)+b*cos(2*pi*f2*t); %generation of x(t);
y=interp(x,3); %interpolate signal by 3
subplot(3,1,1)
stem(x(1:25)); %plot original signal
xlabel('Discrete time,nT')
ylabel('Amplitude');
title('Input signal')
subplot(3,1,2)
31
stem(y(1:100)); %plot interpolated signal
xlabel('Discrete time,3*nT')
ylabel('Amplitude');
title('Interplolated output signal')
y1=decimate(t,3);
subplot(3,1,3)
stem(y1(1:25)); %plot decimated signal
xlabel('Discrete time,nT')
ylabel('Amplitude');
title('Decimated output signal')
RESULT: Decimation and interpolation processes using MATLAB has been performed.
OUTPUT:
32