Professional Documents
Culture Documents
Books:
Getting Started with MATLAB - Rudra Pratap Digital Signal Processing - Sanjit K. Mitra. Digital Signal Processing-A Practitioners Approach - Kaluri V. Rangarao - Ranjan K. Mallik
BEIT, 6th Semester
Introduction
MATLAB -> MATrix LABoratory Built-in Functions -Computations -Graphics -External Interface -Optional Toolbox for Signal Processing, System analysis, Image Processing
BEIT, 6th Semester
MATLAB Windows
Command window: main window characterized by >> command prompt. Edit window: where programs are written and saved as M-files. Graphics window: shows figures, alternately known as Figure window.
Edit Window
Command Window
Figure Window
BEIT, 6th Semester
Matlab Basics
Variables
several i j pi predefined variables sqrt(-1) sqrt(-1) 3.1416...
Variables
Global Variables Local Variables
MATLAB Basics:
Arithmetic operators: + addition, - subtraction, * multiplication, /division, ^ power operator, ' transpose
Matrices
Matrices : Basic building block Elements are entered row-wise >> v = [1 3 5 7] creates a 1x4 vector >> M = [1 2 4; 3 6 8] creates a 2x3 matrix >> M(i,j) => accesses the element of ith row and jth column
BEIT, 6th Semester
Basics Matrices
Special Matrices null matrix: nxm matrix of zeros: nxm matrix of ones: nxn identity matrix: M M M M = = = = []; zeros(n,m); ones(n,m); eye(n);
Matrix Operations
Matrix operations: A+B is valid if A and B are of same size A*B is valid if As number of columns equals Bs number of rows. A/B is valid and equals A.B-l for same size square matrices A & B. Element by element operations: .* , ./ , .^ etc
--a = [1 2 3], b = [2 2 4], =>do a.*b and a*b
BEIT, 6th Semester
Vectors
Waveform representation
2D Plotting
plot: creates linear continuous plots of vectors and matrices; plot(t,y): plots the vector t on the x-axis versus vector y on the y-axis. To label your axes and give the plot a title, type xlabel('time (sec)') ylabel('step response') title('My Plot') Change scaling of the axes by using the axis command after the plotting command:axis([xmin xmax ymin ymax]);
BEIT, 6th Semester
2D Plotting
stem(k,y): for discrete-time signals this command is used. To plot more than one graph on the screen, subplot(m,n,p): breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axis for the current plot grid : shows the underlying grid of axes
BEIT, 6th Semester
Matlab Plot
Matlab Plot
Matlab Plot
Functions
r=a-d.*floor(a./d);
%You should make a file named mod.m and enter this program exactly as it is written. %Now assign some integer values for a and d writing another .m file and Run a =[10 10 10]; d = [3 3 3]; Another .m file to access mod(x,y); above function
BEIT, 6th Semester
Loops, flows:
for m=1:10:100 num = 1/(m + 1) end
%i is incremented by 10 from 1 to 100
I = 6; j = 21 if I > 5 k = I; elseif (i>1) & (j == 20) k = 5*I + j else k = 1; end %if statement
BEIT, 6th Semester
Recapitulate
Type help, followed by the function name on the Matlab command window, press enter. This will display the function definition. Study the definition of each function.
BEIT, 6th Semester
Practice
1>Draw a straight line satisfying the equation: y = 3*x + 10 2>Draw a cosine wave with frequency 10kHz. Use both plot and stem functions to see the difference. 3>Draw a circle with radius unity. (use cos for x axis, sin for y axis) 4>Multiply two matrices of sizes 3x3.
BEIT, 6th Semester