7/30/2019 Matera 2k13 Ppts
1/25
BY
DR.M.NARSING YADAV
B.TECH,MS,PH.DASSOCIATE PROFESSOR,
DEPT OF ECE,
BITS, KNL
MATLAB AND ITS
APPLICATIONS
7/30/2019 Matera 2k13 Ppts
2/25
Basics of MATLAB
Matlab Desktop
Command windowWorkspace
Current directory
Figure window
Editor window
7/30/2019 Matera 2k13 Ppts
3/25
Matlab Desktop Window
7/30/2019 Matera 2k13 Ppts
4/25
Figure window
7/30/2019 Matera 2k13 Ppts
5/25
Editor Window
7/30/2019 Matera 2k13 Ppts
6/25
File Types
.m files
.mat files
.fig files
.p files
.mex files
7/30/2019 Matera 2k13 Ppts
7/25
Some of the Desktop Command Windows
Who lists variables currently in the workspace
Whos lists variables currently in the workspace withtheir size
What lists .m, .mat and .mex files on the disk
Clear clears the workspace, all the variables areremoved
Clear all clears all the variables and functions from theworkspace
Clc clears the command window, command history isalso lost
Clf clears the figure window
Control c aborts and kills the current commandexecution
7/30/2019 Matera 2k13 Ppts
8/25
2. Various Mathematical
Operations
arithematic operations
Trignometric operations
Exponential operations
Complex operations
Logarithmic Operations
7/30/2019 Matera 2k13 Ppts
9/25
3. Formation of a Matrix
By explicit entering of elements
By Importing the data using real time signals
By using Generating Matrices
7/30/2019 Matera 2k13 Ppts
10/25
A = [ 1 2 3; 4 5 6; 7 8 9]
Y=wavread(C:\Documents andSettings\user\Desktop\sig1.wav)
Y=imread(C:\Documents and
Settings\user\Desktop\yoga.jpg)
7/30/2019 Matera 2k13 Ppts
11/25
4. Matrix Indexing
Declaring the input elements to a matrix
The matrix is always declared in the upper caseletter
A=[ 1 2 3; 4 5 6; 7 8 9]
Null Matrix A=[ ]
The powerful colon operator ; it can be used in
many ways for performing various matrixoperations
7/30/2019 Matera 2k13 Ppts
12/25
For example:
Producing a row of integers
A=1:5
A=[1 2 3 4 5]
hence can be used to generate a row vector of size N
A=1:N
Can also be used as A=colon(1,N)
Can also be used for producing an array of non uniform spacing
x=100:-10:50
X=[100 90 80 70 60 50]X=50:10:100
Can be used to select a part of a matrix
A=[ 1 2 3; 4 5 6; 7 8 9]
C3=A(:,3)
C3= 3
6
9
R2=A(2,:)
T=A(1:2,1:3)
Can be used to convert a two dimensional matrix into a single column vector
=
7/30/2019 Matera 2k13 Ppts
13/25
Generating Matrices zeros(M,N)
Ones(M,N)
Rand(M,N)
Randn(M,N)
Randint(M,N)
Eye(M,N)
Diag(A)
Rot90(A)
Fliplr(A)
Flipud(A)
Tril(A)
Triu(A)
Reshape(A,[m n])
7/30/2019 Matera 2k13 Ppts
14/25
Some other operations
reshaping matrices
Let A be a 4x4 matrix , then reshape(A,2,8)
Appending a row or a column
A=[A;u] , A=[A v], A=[ A u]
Deleting a row or a column
A(2,: )=[ ]
A(:, 3:5) = [ ]
A([1 3], : ) = [ ]
Transpose of a Matrix
7/30/2019 Matera 2k13 Ppts
15/25
Creating vectors
The general expression for creating avector is
v=Initial value: increment: Final value
Linspace(a,b,n) Logspace(a,b,n)
Importance of .operator
7/30/2019 Matera 2k13 Ppts
16/25
Creating plots and graphs Basic 2D plots
plot(x values, y values, style-option);style option=color_linestyle_markerstyle
Labels, titles
xlabel( );ylabel( );
title( );
Use of legend
legend(string1,string2, ..) Generating overlay plots
line(xdata, ydata, parameter name, parametervalue)
7/30/2019 Matera 2k13 Ppts
17/25
t=linspace(0,2*pi,100)y1=sin(t);y2=t;y3=t-(t.^3)/6+(t.^5)/120;plot(t,y1)line(t,y2,'linestyle','--')
line(t,y3,'marker','o')xlabel('t')ylabel('approximations of sin(t)')title('fun with sin(t)')legend('sint(t)','linear approx','fifthorder approx')
0 1 2 3 4 5 6 7-10
0
10
20
30
40
50
t
approxim
ationsofsin(t)
fun with sin(t)
sint(t)
linear approx
fifth order approx
7/30/2019 Matera 2k13 Ppts
18/25
Subplot of a figure window
0 50 1000
0.2
0.4
0.6
0.8
1
0 50 1000
0.2
0.4
0.6
0.8
1
0 2 4 6 8
x 104
0
2
4
6
0 2 4 6 8
x 104
0
10
20
30
40
t=0:0.0001:6
%unit impulse
y1= [1 zeros(1,99)];
%figure,plot(y1)
%%%% unit step
y2=ones(1,100);
%figure,stem(y2)
%%%% unit ramp %%%%%
y3=t;%figure,stem(y3)
%%%%%%%% quadratic signal %%%%%%%
y4=t.^2;
figure,subplot(2,2,1),stem(y1)subplot(2,2,2),stem(y2)
subplot(2,2,3),stem(y3)subplot(2,2,4),stem(y4)
7/30/2019 Matera 2k13 Ppts
19/25
Examples of periodic signals
Square wave Sine and cosine wave
Saw tooth wave; triangular wave
some common signals
Unit impulse
Unit step
Ramp Parabolic
cubic
7/30/2019 Matera 2k13 Ppts
20/25
Examples of aperiodic signals
Gaussian Pulse
Pulse train functionThe chirp signal
The sinc signalThe dirac function
7/30/2019 Matera 2k13 Ppts
21/25
The Guassian pulse
Syntax
yi = gauspuls(t,fc,bw)yi = gauspuls(t,fc,bw,bwr)
tc = gauspuls('cutoff',fc,bw,bwr,tpe)
yi = gauspuls(t,fc,bw) returns a unity-amplitude Gaussian RF pulse at
the times indicated in array t, with a center frequency fc in hertz anda fractional bandwidth bw, which must be greater than 0. Thedefault value for fc is 1000 Hz and for bw is 0.5.
tc = gauspuls('cutoff',fc,bw,bwr,tpe) returns the cutoff time tc(greater than or equal to 0) at which the trailing pulse envelope falls
below tpe dB with respect to the peak envelope amplitude. Thetrailing pulse envelope level tpe must be less than 0, because itindicates a reference level less than the peak (unity) envelopeamplitude. The default value for tpe is -60 dB.
7/30/2019 Matera 2k13 Ppts
22/25
The Pulstran function
y = pulstran(t,d,'func')pulstran(t,d,'func',p1,p2,...)pulstran(t,d,p,fs)
pulstran(t,d,p)pulstran(...,'func')
y = pulstran(t,d,'func') generates a pulse train based on samples of acontinuous function, 'func', where 'func'is
'gauspuls', for generating a Gaussian-modulated sinusoidal pulse
'rectpuls', for generating a sampled aperiodic rectangle
'tripuls', for generating a sampled aperiodic triangle
t = 0 : 1/1e3 : 1; % 1 kHz sample freq for 1 secd = 0 : 1/3 : 1; % 3 Hz repetition freq
y = pulstran(t,d,'tripuls',0.1,-1); plot(t,y)
7/30/2019 Matera 2k13 Ppts
23/25
The Sinc Function
Syntax
y = sinc(x)
7/30/2019 Matera 2k13 Ppts
24/25
The Chirp Signal
y = chirp(t,f0,t1,f1)
y = chirp(t,f0,t1,f1,'method') y = chirp(t,f0,t1,f1) generates samples of a linear
swept-frequency cosine signal at the time instancesdefined in array t, where f0 is the instantaneousfrequency at time 0, and f1 is the instantaneous
frequency at time t1. f0 and f1 are both in hertz. Ifunspecified, f0 is e-6 for logarithmic chirp and 0 for allother methods, t1 is 1, and f1 is 100.
y = chirp(t,f0,t1,f1,'method') specifies alternativesweep method options, where methodcan be:
Linear
Quadratic
logarithmic
7/30/2019 Matera 2k13 Ppts
25/25
The Diric Function
y = diric(x,n)
x = linspace(0,4*pi,300);
figure,plot(x,diric(x,7));
figure,plot(x,diric(x,8));
Top Related