DOC-20220606-WA0006.
DOC-20220606-WA0006.
LAB MANUAL
SIGNALS & SYSTEMS LAB (C-13)
SIXTH SEMESTER
DEPT. OF INFORMATION SC. & TELECOMMUNICATION
(I.S.T.)
RAVENSHAW UNIVERSITY, CUTTACK
Lab. In-charge:
Mr. Shakti Prasad Dash
1
SIGNALS & SYSTEMS LAB (C-13)
MATLAB:
The course aims at practical experience with the generation and simulation of basic
signals, using standardized environments such as MATLAB.
The objective of this laboratory is to enable the students to acknowledge with basic
signals, and system responses.
OBJECTIVE
COURSE OUTCOMES
dimension
2. Generate the various signals and sequences and perform operations on signals.
noise.
2
SIGNALS & SYSTEMS LAB (C-13)
INTRODUCTION TO MATLAB
The name MATLAB stands for Matrix Laboratory. MATLAB was written originally to provide
easy access to matrix software developed by the LINPACK (linear system package) and
EISPACK (Eigen system package) projects.
THEORY:
3
SIGNALS & SYSTEMS LAB (C-13)
MATLAB ENVIRONMENT:
Command Window:
Whenever MATLAB is invoked, the main window called command window is activated. The
command window displays the command prompt’>>’ and a cursor where commands are entered and
are executed instantaneously.
Workspace:
A workspace is a collection of all the variables that have been generated so far in the current
MATLAB session and shows their data type and size. All the commands executed from Command
Window and all the script files executed from the Command Window share common workspace, so
they can share all the variables.
Current Directory:
The Current Directory window contains all the files and folders present in the Current Directory. To
run any file, it must either be in the Current Directory or on the search path.
Edit Window:
An Edit Window is used to create a new program file, or to modify existing files. In this window,
programs can be written, edited and saved. The programs written using the MATLAB editor are
automatically assigned an extension (.m) by the editor and are known as M- files.
Figure Window:
A Figure Window is a separate window with default white background and is used to display
MATLAB graphics. The results of all the graphic commands executed are displayed in the figure
window
4
SIGNALS & SYSTEMS LAB (C-13)
The clear command deletes all (or the specified) variable(s) from the memory.
Row vectors are created by enclosing the set of elements in square brackets, using space or
comma to delimit the elements.
For example:- r = [7 8 9 10 11]
Column vectors are created by enclosing the set of elements in square brackets, using
semicolon(;) to delimit the elements. c = [7; 8; 9; 10; 11]
Creating Matrices
A matrix is a two-dimensional array of numbers.
Instructions/Functions:
stem (t,x) :- This instruction will display a figure window as shown.
stem(): Used for discrete time plotting of signals.
5
SIGNALS & SYSTEMS LAB (C-13)
11. Subplot: This function divides the figure window into rows and columns.
Subplot (2 2 1) divides the figure window into 2 rows and 2 columns 1 represent
number of the Subplot (3 1 2) divides the figure window into 3 rows and 1 column
2 represent the figure number.
Description: title('string') OUTPUTs the string at the top and in the center of the
current axes.
17. min() and max() : used to find minimum and maximum value.
Syntax:
min()
6
SIGNALS & SYSTEMS LAB (C-13)
max()
19. The inbuilt function fliplr() function can be used to perform reversing or folding a signal.
Syntax:
fliplr(a) : if a is row vector it returns a vector with the same size of a but with reversed
order. if a is column vector it flips the elements one column to the other.
Basic idea :
Starting MATLAB
One can enter MATLAB by double-clicking on the MATLAB shortcut icon on Windows
desktop.
Upon starting of MATLAB, a special window called the MATLAB desktop appears. The
desktop is a window that contains other windows. The major tools within or accessible from the
desktop are:
7
SIGNALS & SYSTEMS LAB (C-13)
Quitting MATLAB: To end your MATLAB session, type quit in the Command Window, or
select File Exit MATLAB in the desktop main menu.
Programming in MATLAB:
So far in these lab sessions, all the commands were executed in the Command Window. The
problem is that the commands entered in the Command Window cannot be saved and executed
again for several times. Therefore, a different way of executing repeatedly commands with
MATLAB is:
1. to create a file with a list of commands,
2. save the file, and
3. run the file. If needed, corrections or changes can be made to the commands in the file. The
files that are used for this purpose are called script files or scripts for short. This section covers
the following topics:
8
SIGNALS & SYSTEMS LAB (C-13)
-File Scripts: A script file is an external file that contains a sequence of MATLAB
statements.
Script files have a filename extension .m and are often called M-files. M-files can be scripts that
simply execute a series of MATLAB statements, or they can be functions that can accept
arguments and can produce one or more outputs.
The M Files
MATLAB allows writing two kinds of program files –
Scripts − script files are program files with .m extension. In these files, you write series of
commands, which you want to execute together. Scripts do not accept inputs and do not return
any outputs. They operate on data in the workspace.
Functions − functions files are also program files with .m extension. Functions can accept
inputs and return outputs. Internal variables are local to the function.
You can use the MATLAB editor or any other text editor to create your .m files.
Built in Functions:
1. Scalar Functions: Certain MATLAB functions are essentially used on scalars, but operate
element-wise when applied to a matrix (or vector).
They are summarized below.
1. sin - trigonometric sine
2. cos - trigonometric cosine
3. tan - trigonometric tangent
4. asin - trigonometric inverse sine (arcsine)
5. sqrt - square root 6. rem - remainder
2. Vector Functions: Other MATLAB functions operate essentially on vectors returning a
scalar value. Some of these functions are given below.
1. max- largest component: get the row in which the maximum element lies
2. min- smallest component
3. length- length of a vector
4. sort- sort in ascending order
5. sum- sum of elements
9
SIGNALS & SYSTEMS LAB (C-13)
3. Matrix Functions: Much of MATLAB‟s power comes from its matrix functions. These
can be further separated into two sub-categories. The first one consists of convenient matrix
building functions, some of which are given below.
1. eye - identity matrix
2. zeros - matrix of zeros
3. ones - matrix of ones
4. diag - extract diagonal of a matrix or create diagonal matrices
Apparatus Required:
OS- Windows 7
Matlab R2010A
MATLAB Procedure
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
MATLAB PROGRAMS
AIM of the Experiment 1 & 2 :
(1) Generation of Signals: continuous time
(2) Generation of Signals: discrete time
(a)%unit step function%
clc;
clear all;
close all;
N=100; t=1:100;
x=ones(1,N);
10
SIGNALS & SYSTEMS LAB (C-13)
subplot(2,1,1); plot(t,x,'g');
xlabel('time'); ylabel('amplitude'); title('unit step function');
subplot(2,1,2); stem(t,x,'r');
xlabel('time'); ylabel('amplitude'); title('unit step discrete function');
1.5
amplitude
0.5
0
0 5 10 15 20 25 30
time
unit step discrete function
1
amplitude
0.5
0
0 5 10 15 20 25 30
time
11
SIGNALS & SYSTEMS LAB (C-13)
amplitude
0.5
0
-10 -8 -6 -4 -2 0 2 4 6 8 10
time
unit impulse discrete function
1
amplitude
0.5
0
-10 -8 -6 -4 -2 0 2 4 6 8 10
time
12
SIGNALS & SYSTEMS LAB (C-13)
15
amplitude
10
0
0 2 4 6 8 10 12 14 16 18 20
time
unit ramp discrete function
20
15
amplitude
10
0
0 2 4 6 8 10 12 14 16 18 20
time
(d)%sinusoidal function%
clc;
clear all;
close all;
t=0:0.05:1.4;
x=sin(2*pi*t);
subplot(2,1,1); plot(t,x,'g');
xlabel('time'); ylabel('amplitude'); title('sinusoidal signal');
subplot(2,1,2); stem(t,x,'r');
xlabel('time'); ylabel('amplitude'); title('sinusoidal sequence');
13
SIGNALS & SYSTEMS LAB (C-13)
(e)%sinc function%
clc;
clear all;
close all;
t=linspace(-5,5);
x=sinc(t);
subplot(2,1,1); plot(t,x,'g');
xlabel('time'); ylabel('amplitude'); title('sinc signal');
subplot(2,1,2); stem(t,x,'r');
xlabel('time'); ylabel('amplitude'); title('sinc sequence');
14
SIGNALS & SYSTEMS LAB (C-13)
sinc signal
1
0.5
amplitude
-0.5
-5 -4 -3 -2 -1 0 1 2 3 4 5
time
sinc sequence
1
0.5
amplitude
-0.5
-5 -4 -3 -2 -1 0 1 2 3 4 5
time
clc;
clear all;
close all;
t=0:0.01:1;
(f-1) % generating two input signals
x1=sin(2*pi*4*t);
x2=sin(2*pi*8*t);
subplot(2,2,1); plot(t,x1);
xlabel('time'); ylabel('amplitude'); title('signal1:sine wave of frequency 4Hz');
subplot(2,2,2); plot(t,x2);
xlabel('time'); ylabel('amplitude'); title('signal2:sine wave of frequency 8Hz');
(f-2) % addition of signals
y1=x1+x2;
subplot(2,2,3); plot(t,y1);
xlabel('time'); ylabel('amplitude'); title('resultant signal:signal1+signal2');
15
SIGNALS & SYSTEMS LAB (C-13)
0.5 0.5
amplitude
amplitude
0 0
-0.5 -0.5
-1 -1
0 0.5 1 0 0.5 1
time time
resultant signal:signal1+signal2 resultant signal:dot product of signal1 and signal2
2 1
1 0.5
amplitude
amplitude
0 0
-1 -0.5
-2 -1
0 0.5 1 0 0.5 1
time time
16
SIGNALS & SYSTEMS LAB (C-13)
Conclusion : From the above, Various operations on signals and sequences are performed.
(a)Shifting of a signal.
%shifting of a signal
figure; t1=0:.01:pi;
x3=8*sin(2*pi*2*t1);
subplot(3,1,1); plot(t1,x3);
xlabel('time t1'); ylabel('amplitude'); title('sine wave of frequency 2Hz');
subplot(3,1,2); plot(t1+10,x3);
xlabel('t1+10'); ylabel('amplitude'); title('right shifted signal');
subplot(3,1,3); plot(t1-10,x3);
xlabel('t1-10'); ylabel('amplitude'); title('left shifted signal');
17
SIGNALS & SYSTEMS LAB (C-13)
-10
0 0.5 1 1.5 2 2.5 3 3.5
time t1
right shifted signal
10
amplitude
-10
10 10.5 11 11.5 12 12.5 13 13.5
t1+10
left shifted signal
10
amplitude
-10
-10 -9.5 -9 -8.5 -8 -7.5 -7 -6.5
t1-10
Conclusion :- All the operations have been performed using a MATLAB and results have been
seen on the command window.
18
SIGNALS & SYSTEMS LAB (C-13)
subplot(2,2,3); plot(t,x2);
xlabel('time'); ylabel('amplitude');
title('sine wave of frequency 8Hz');
subplot(2,2,4);plot(t,y4);
xlabel('time'); ylabel('amplitude');
title('amplified input signal2 ');
0.5 5
amplitude
amplitude
0 0
-0.5 -5
-1 -10
0 0.5 1 0 0.5 1
time time
sine wave of frequency 8Hz amplified input signal2
1 20
0.5 10
amplitude
amplitude
0 0
-0.5 -10
-1 -20
0 0.5 1 0 0.5 1
time time
Conclusion : From the above, Various operations on signals and sequences are performed.
19
SIGNALS & SYSTEMS LAB (C-13)
Conclusion : From the above, Various operations on signals and sequences are performed.
20
SIGNALS & SYSTEMS LAB (C-13)
x(n)signal
6
4
x(n)
0
0 1 2 3 4 5 6 7 8
n
y(n)=x(-n)signal
6
4
y(n)
0
-8 -7 -6 -5 -4 -3 -2 -1 0
n
Conclusion : From the above, Various operations on signals and sequences are performed.
21
SIGNALS & SYSTEMS LAB (C-13)
x1=[0 1 2 3 4];
subplot(3,1,1);stem(n1,x1);title('x_1(n)signal');
xlabel('n');ylabel('x_1(n)');
n2= -2:2;
x2=[2 2 2 2 2];
subplot(3,1,2);stem(n2,x2);title('x_2(n)signal');
xlabel('n');ylabel('x_2(n)');
n = min(min(n1),min(n2)):max(max(n1),max(n2)); %duration of y(n)
y1 = zeros(1,length(n));y2=y1; %initialization
y1((n>= min(n1))& (n<= max(n1))== 1)= x1; % x1 with duration of y
y2((n>= min(n2))& (n<= max(n2))== 1)= x2; % x2 with duration of y
y=y1+y2; % sequence addition
subplot(3,1,3);stem(n,y);
title('Addition of the discrete time signals');
xlabel('n');ylabel('y(n)');
OUTPUT:
Conclusion: From the above, Various operations on signals and sequences are performed.
22
SIGNALS & SYSTEMS LAB (C-13)
3. Addition
4. Shifting
PROGRAM:
clc;
close all;
clear all;
x=input('enter input sequence');
h=input('enter impulse response');
y=conv(x,h);
subplot(3,1,1); stem(x);
xlabel('n');ylabel('x(n)'); title('input signal');
subplot(3,1,2); stem(h);
xlabel('n');ylabel('h(n)'); title('impulse response');
subplot(3,1,3); stem(y);
xlabel('n');ylabel('y(n)'); title('linear convolution');
disp('The resultant signal is');
disp(y)
linear convolution
INTPUT:
23
SIGNALS & SYSTEMS LAB (C-13)
1 4 5 11 10 7 2
Conclusion: From the above, Various operations on signals and sequences are performed.
Knowing the conditions under which linear and circular convolution are equivalent allows you to use the
DFT to efficiently compute linear convolutions.
The linear convolution of an N-point vector, x and an L-point vector, y has length N + L - 1.
PROGRAM:
clc;
clear all;
close all;
24
SIGNALS & SYSTEMS LAB (C-13)
%Create two vectors, x and y, and compute the linear convolution of the two
vectors%
x = [2 1 2 1];y = [1 2 3];
clin = conv(x,y);
%Pad both vectors with zeros to length 4+3-1. Obtain the DFT of both vectors,
multiply the DFTs, and obtain the inverse DFT of the product%
xpad = [x zeros(1,6-length(x))];
ypad = [y zeros(1,6-length(y))];
ccirc = ifft(fft(xpad).*fft(ypad));
The circular convolution of the zero-padded vectors, xpad and ypad, is equivalent to the
linear convolution of x and y.
%Plot the output of linear convolution and the inverse of the DFT product to show the
equivalence%
subplot(2,2,1)
stem(clin,'filled')
ylim([0 11])
title('Linear Convolution of x and y')
subplot(2,2,2)
stem(ccirc,'filled')
ylim([0 11])
title('Circular Convolution of xpad and ypad')
Conclusion: From the above, Various operations on signals and sequences are performed.
25
SIGNALS & SYSTEMS LAB (C-13)
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,
2. Multiplication
3. Addition
These operations can be represented by a Mathematical Expression as follows:
Cross correlation
Autocorrelation
PROGRAM:
% Cross Correlation
clc;
close all;
clear all;
subplot(3,1,1); stem(x);
26
SIGNALS & SYSTEMS LAB (C-13)
subplot(3,1,2); stem(h);
y=xcorr(x,h);
subplot(3,1,3); stem(y);
xlabel('n'); ylabel('y(n)');
OUTPUT:
27
SIGNALS & SYSTEMS LAB (C-13)
OUTPUT:
AIM of the Experiment 10 : To find the Fourier Transform of a given signal and
plotting its magnitude and phase spectrum.
PROGRAM:
clc;
close all;
28
SIGNALS & SYSTEMS LAB (C-13)
clear all;
x=input ('enter the sequence');
N=length(x);
n=0:1:N-1;
y=fft(x,N);
subplot(2,1,1); stem(n,x);title('input sequence');
xlabel('time index n----->');
ylabel('amplitude x[n]----> ');
subplot(2,1,2);stem(n,y);title('OUTPUT sequence');
xlabel(' Frequency index K---->');
ylabel('amplitude X[k]------>');
OUTPUT: 12 -3 -3
Conclusion: From the above, Various operations on signals and sequences are performed.
29