Professional Documents
Culture Documents
WINSEM2022-23 BECE301P LO VL2022230502551 2022-12-07 Reference-Material-I
WINSEM2022-23 BECE301P LO VL2022230502551 2022-12-07 Reference-Material-I
PROCESING LABORATORY
WINTER-2022
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 1
FACULTY PROFILE
Dr.S.KALAIVANI, B.E.,M.E.,Ph.D.,
Professor,
Department of Communication Engineering,
School of Electronics Engineering (SENSE),
Vellore Institute of Technology, Vellore.
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 2
ASSESSMENT METHODOLOGY
TASK 1
TASK 2
TASK 3
TASK 4
TASK 5
MID LAB FAT (TASK 6)
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 3
INTRODUCTION TO MATLAB
WINTER_ 2023
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 4
MATLAB
The name MATLAB stands for;
MATrix LABoratory.
• MATLAB is a powerful, general-purpose
system or environment for doing
mathematics, scientific and engineering
calculations.
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 5
Contd.,
• MATLAB is a "High-Performance
Numeric Computation and Visualization
Software" package
• MATLAB is an interactive system whose
basic data is a matrix that does not
require dimensioning
• MATLAB has a number of add-on
software modules, called toolbox , that
perform more specialized computations
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 6
MATAB INTRODUCTION
In Windows systems
MATLAB is started
by double-clicking
the mouse on the
appropriate icon.
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 7
Matlab Screen
Command Window
type commands
Current Directory
View folders and m-files
Workspace
View program variables
Double click on a variable
to see it in the Array Editor
Command History
view past commands
save a whole session
using diary
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 8
MATLAB Screen
• Desktop Menus
• File Menu
– New
• Create new MATLAB
program file (m-file)
– Open existing m-file
– Import data
– Set Path
– Open recent m-files
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 9
MATLAB Screen
Edit Menu
Copy, cut, paste
Find and replace
phrases
Clear command
history, workspace
Desktop Menu
Change
appearance of
desktop
Select windows to
display BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 10
Use of M-File
Click to create
a new M-File
• Extension “.m”
• A text file containing script or function or program to run
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 11
Use of M-File
Save file as Denem430.m
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 12
Starting MATLAB
MATLAB displays >> prompt when
ready for a command
Will have no >> prompt when processing
commands
Newer versions also say “Ready” or “Busy”
in lower left corner of GUI
Can use arrow keys to work through
command history and modify commands
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 13
Interactive Commands
Enter commands at >> prompt
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 15
Interactive Commands
Format of output
Defaults to 4 decimal places
Can change using format statement
format long changes output to 15
decimal places
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 16
Operators (arithmetic)
+ addition
- subtraction
* multiplication
/ division
^ power
‘ complex conjugate transpose
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 17
Order of Operations
• Parentheses
• Exponentiation
• Multiplication and division have equal
precedence
• Addition and subtraction have equal
precedence
• Evaluation occurs from left to right
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 18
Logical Operators
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 19
Variables
MATLAB is case sensitive
X is not equal to x
Variable names must start
with a letter
You’ll get an error if this
doesn’t happen
After that, can be any
combination of letters,
numbers and underscores
No special characters though
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 20
Variables
Variable types
Numeric
Logical
Character and string
Cell and Structure
Function handle
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 21
Variables
Don’t name your variables the same as
functions
min, max, sqrt, cos, sin, tan, mean,
median, etc
Funny things happen when you do this
MATLAB reserved words don’t work
either
i, j, eps, nargin, end, pi, date, etc
i, j are reserved as complex numbers
initially
13-12-2022
BECE301P_WINTER_2022-23
Dr S KALAIVANI 22
Array, Matrix
a vector x = [1 2 5 1]
x =
1 2 5 1
a matrix A = [1 2 3; 5 1 4; 3 2 -1]
A =
1 2 3
5 1 4
3 2 -1
transpose y = x’
y =
1
2
5
1
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 23
Long Array, Matrix
=1:10
t
t =
1 2 3 4 5 6 7 8 9 10
T=1:2:10
T = 1 3 5 7 9
k =2:-0.5:-1
k =
2 1.5 1 0.5 0 -0.5 -1
B = [1:4; 5:8]
x =
1 2 3 4
5 6 7 8
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 24
Generating Vectors from
functions
zeros(M,N) MxN matrix of zeros x = zeros(1,3)
x =
0 0 0
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 25
Matrix Index
The matrix indices begin from 1 (not 0 (as in C))
The matrix indices must be positive integer
Given: A(8)=?
A(3,2)=?
A(2,:)=?
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 26
Concatenation of Matrices
x = [1 2], y = [4 5], z=[ 0 0]
A = [ x y]
1 2 4 5
B = [x ; y]
1 2
4 5
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 27
Matrix Operations
A*B A.*B
Given A and B:
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 29
Operators (Element by
Element)
.* - element-by-element multiplication
./ - element-by-element division
.^ - element-by-element power
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 30
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 31
Plots in MATLAB
MATLAB has remarkable graphics
capacities:
2-D and 3-D plots,
Line plotting,
3-D surface plot,
Splash screen plot,
Plot of complex functions and ...
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 32
EXAMPLE OF A 2-D PLOT Legend
Plot title
Light Intensity as a Function of Distance
1200
Theory
y axis Experiment
label 1000
Text
Tick-mark
800
INTENSITY (lux)
600
400
Data symbol
200
0
8 10 12 14 16 18 20 22 24
DISTANCE (cm)
x axis Tick-mark label
label BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 33
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 34
TWO-DIMENSIONAL plot() COMMAND
plot(x,y)
where x is a vector (one dimensional array), and y is a vector.
Both vectors must have the same number of elements.
Given data:
x 1 2 3 5 7 7.5 8 10
y 2 6.5 7 7 5.5 4 6 8
A plot can be created by the commands shown below. This can be done
in the Command Window, or by writing and then running a script file.
Once the plot command is executed, the Figure Window opens with the
following plot.
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 36
PLOT OF GIVEN DATA
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 37
LINE SPECIFIERS IN THE plot() COMMAND
plot(x,y,’line specifiers’)
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 38
LINE SPECIFIERS IN THE plot() COMMAND
plot(x,y,‘line specifiers’)
EXAMPLES:
plot(x,y) A solid blue line connects the points with no markers.
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 40
PLOT OF GIVEN DATA USING LINE
SPECIFIERS IN THE plot()
COMMAND
Year 1988 1989 1990 1991 1992 1993 1994
Line Specifiers:
dashed red line and
asterisk markers.
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 41
PLOT OF GIVEN DATA USING LINE
SPECIFIERS IN THE plot()
COMMAND
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 42
CREATING A PLOT OF A FUNCTION
Consider:
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 43
A PLOT OF A FUNCTION
0.5 x
y 3.5 cos(6 x) for 2 x 4
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 44
CREATING A PLOT OF A FUNCTION
If the vector x is created with large spacing, the graph is not accurate.
Below is the previous plot with spacing of 0.3.
x = [-2:0.3:4];
y = 3.5.^(-0.5*x).*cos(6*x);
plot(x,y)
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 45
THE fplot COMMAND
The fplot command can be used to plot a function
with the form: y = f(x)
fplot(‘function’,limits)
The limits is a vector with the domain of x, and optionally with limits
of the y axis:
[xmin,xmax] or [xmin,xmax,ymin,ymax]
Line specifiers can be added.
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 46
PLOT OF A FUNCTION WITH THE fplot() COMMAND
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 47
PLOTTING MULTIPLE GRAPHS IN THE SAME PLOT
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 48
USING THE plot() COMMAND TO PLOT
MULTIPLE GRAPHS IN THE SAME PLOT
plot(x,y,u,v,t,h)
plot(x,y,’-b’,u,v,’—r’,t,h,’g:’)
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 49
USING THE plot() COMMAND TO PLOT
MULTIPLE GRAPHS IN THE SAME PLOT
120
100
80
60
40
20
-20
-40
-2 -1 0 1 2 3 4
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 51
USING THE hold on, hold off, COMMANDS
TO PLOT MULTIPLE GRAPHS IN THE SAME PLOT
hold on Holds the current plot and all axis properties so that
subsequent plot commands add to the existing plot.
This method is useful when all the information (vectors) used for the
plotting is not available a the same time.
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 52
USING THE hold on, hold off, COMMANDS
TO PLOT MULTIPLE GRAPHS IN THE SAME PLOT
Plot of the function, y 3x 3 26 x 10and its first and second
derivatives, for
2 x 4 all in the same plot.
x = [-2:0.01:4];
y = 3*x.^3-26*x+6;
yd = 9*x.^2-26;
ydd = 18*x;
plot(x,y,'-b')
First graph is created.
hold on
plot(x,yd,'--r')
plot(x,ydd,':k') Two more graphs are created.
hold off
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 53
USING THE plot() COMMAND TO PLOT
MULTIPLE GRAPHS IN THE SAME PLOT
120
100
80
60
40
20
-20
-40
-2 -1 0 1 2 3 4
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 54
FORMATTING PLOTS
title(‘string’)
Adds the string as a title at the top of the plot.
xlabel(‘string’)
Adds the string as a label to the x-axis.
ylabel(‘string’)
Adds the string as a label to the y-axis.
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 56
FORMATTING A PLOT IN THE FIGURE WINDOW
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 57
Experiment 1
Generate the following Signals;
i. 𝑦(𝑡) = 2 ∗ 𝑠𝑖𝑛(2 ∗ 𝑝𝑖 ∗ 500 ∗ 𝑡) + 3 ∗ 𝑠𝑖𝑛(2 ∗ 𝑝𝑖 ∗ 1000 ∗ 𝑡).
ii. 𝑥1[𝑛] = 𝑢[𝑛] − 𝑢[𝑛 − 4]
iii. 𝑥2[𝑛] = 𝛿[𝑛] + 2𝛿[𝑛 − 1] + 4 𝛿[𝑛 − 2] − 6 𝛿[𝑛 − 3]
iv. 𝑥3[𝑛] = 𝑟[𝑛 − 2]
v. 𝑥4[𝑛] = 𝑠𝑞𝑢𝑎𝑟𝑒 𝑤𝑎𝑣𝑒 𝑤𝑖𝑡ℎ 𝑓𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦 4𝐻𝑧, 𝑑𝑢𝑡𝑦 𝑐𝑦𝑐𝑙𝑒 50%
vi. 𝑥5[𝑛] =
𝑆𝑎𝑤𝑡𝑜𝑜𝑡ℎ 𝑤𝑎𝑣𝑒 𝑤𝑖𝑡ℎ 𝑓𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦 3𝐻𝑧 𝑎𝑛𝑑 𝑝𝑒𝑎𝑘 𝑖𝑠 ℎ𝑎𝑙𝑓𝑤𝑎𝑦 𝑡ℎ𝑟𝑜𝑢𝑔ℎ 𝑡ℎ𝑒 𝑝𝑒𝑟𝑖𝑜𝑑
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 58
Code
clc
clear all
close all
% GENERATION OF SINE WAVE%
t=0:0.05e-3:5e-3;
A=2*sin(2*pi*500*t)+3*sin(2*pi*1000*t);
figure, subplot(2,2,1),plot(t,A);grid on
title('SINE WAVE');
xlabel('----->t');
ylabel('Amplitude');
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 59
%Generation of u[n]-u[n-4]%
n=-10:1:10;
Y=[zeros(1,10),ones(1,4),zeros(1,7)];
subplot(2,2,2);
stem(n,Y),grid on
title('u[n]-u[n-4]');
xlabel('----->n');
ylabel('Amplitude');
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 60
% Generation of Unit impulse shifted
and scaled sequence%
y1=[zeros(1,10),ones(1,1),2*ones(1,1)
,4*ones(1,1),-6*ones(1,1),zeros(1,7)]
subplot(2,2,3);
stem(n,y1);grid on
title('Impulse');
xlabel('----->n');
ylabel('Amplitude');
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 61
%Generation of Shifted Ramp Sequence%
t=[-10:10];
y2=zeros(size(n));
t2=t-2;
y2(t>=3)=t2(t>=3)
subplot(2,2,4);
stem(t,y2);grid on
title('r[n-2]');
xlabel('----->n');
ylabel('Amplitude');
BECE301P_WINTER_2022-23
13-12-2022 Dr S KALAIVANI 62