0% found this document useful (0 votes)
21 views

Matlab Familiarisation

Uploaded by

Deepa V.V
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Matlab Familiarisation

Uploaded by

Deepa V.V
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Familiarization with Matlab,

A Hands-on Training.
BRIDGE COURSE
Course Prerequisite:
• Mathematical Foundations for Digital Signal
Processing
Course Outcome:
At the end of the course, students shall be able to:
• CO 1: Recognize and recall information learned during the
bridge course 'Mathematical Foundations for Digital Signal
Processing'. (Remember)
• CO 2: Understand and visualize the practical aspects of
Digital Signal Processing through Matlab. (Understand)
• CO 3: Apply their knowledge for numerical computations
using Matlab. (Apply)
Course Content:
• The what, why and how of Matlab
– What? (Brief introduction)
– Why? (Need/Applications)
– How? (Explained with practical examples)
• Operations on Vectors and Matrices
• Basic Matlab commands
• Built-in Matlab functions
• Creation of M-file
• Use of GUI
What is Matlab?

• Stands for MATrix LABoratory


• To Start
– Go to “C:\Program Files\Matlab\
R2013a\bin\Matlab.exe”
– An open source alternative for Matlab
• Octave
http://www.gnu.org/software/octave/
Why Matlab?

• User Friendly (GUI)


• Easy to work with
• Powerful tool for numerical computations with matrices

• Suitable for
– Math and computation
– Algorithm development (optimized for DSP)
– Data acquisition
– Modeling, simulation, and prototyping
– Data analysis, exploration, and visualization
– Scientific and engineering graphics
Menu and toolbar MATLAB Screen shot

workspace
type commands here

current directory
history

command window

screen shot of the Matlab window


Editor/Debugger
HELP BROWSER

Figure
Wokspace Window
Browser

Command
History
• MATLAB is so rich that ‘help’ is essential!
• To get started, select "MATLAB Help" from the
Help menu.
>> help for

how to use Matlab’s “for” statement


Matlab’s help features

you can also access “on-line” help by clicking the


question mark in the toolbar

separate window
Practical Examples

Matlab can be used as a calculator.


• 3*2^4
• (3*2)^4
• 8/2^4
Operations on Vectors and Matrices
Define a matrix and vector:
Vector :
A=[1 2 3; 4 5 6; 7 8 9] >> b=[1 2 3];
b =[1 2 3]; >> b'
1
Transpose 2
3
b'
Matrix-vector multiplication:
c=b*A
d=A*b’
Matrix operations
>> determinant=det(A)
>> eigenvalue=eig(A)
Vectors
• A = [3 4 7 11] % array
• B=3:8
• C = 8 : -1 : 0
• D = linspace(0,1)
• E = [ 8 7 6 5 4 3 2 1 0];
• E
• E (3)
• length(E)
• size(E)
• E'
Matrices
• A = zeros(m, n)
• B = ones(m, n)
• I = eye(m, n)
• Size(A)
• Length(A)
• B = A(2:4,3:5)
M-Files

• You can create your own programs using M-


files.
• These are text files containing MATLAB code.
• Save the file under a name that ends in .m
Creation of M-file
To create an m-file, open the Matlab text editor

Click on the “page” icon

The Matlab text editor window will open


MATLAB m-files
Script Files

On the command line In the script file named test.m

>>x=3.0;
>>y=x^2;
>>y
y =
9.0
>>

On the command line

>>test
y =
9.0
>>
Function m-File
Keyword: function
Function Name (same as filename)

outputs in square brackets, [ ] inputs in parentheses ( )

Multiple Inputs and Outputs


MATLAB Flow Control
example

script file to cycle through x values

function file to generate the y values


MATLAB Plotting
Basic Plotting
plot, title, xlabel, grid, legend, hold, axis

example y = sin(t)
the “plot” function alone
Title

Ylabel
Grid

Legend

Xlabel
Basic Matlab commands

• what List all m-files in current directory


• dir List all files in current directory
• ls Same as dir
• type test Display test.m in command window
• delete test Delete test.m
• cd a: Change directory to a:
• chdir a: Same as cd
• pwd Show current directory
• which test Display current directory path to
test.m
• why In case you ever needed a reason
Built-in Matlab Functions

• input - Read/get input from user


• disp - Print/display text on the screen
• exp - Exponential.
• log - Natural logarithm.
• log10 - Common (base 10) logarithm.
• log2 - Base 2 logarithm
• pow2 - Base 2 power
• sqrt - Square root.
• nthroot - Real n-th root of real numbers.
• nextpow2 - Next higher power of 2.
• inv - Matrix inverse
• eig - Evaluate eigenvalues and eigenvectors
• rank - Rank of matrix
Toolboxes

• Collections of functions to solve problems


from several application fields.
– DSP (Digital Signal Processing) Toolbox
– Image Toolbox
– Wavelet Toolbox
– Neural Network Toolbox
– Fuzzy Logic Toolbox
– Control Toolbox
– And many others…
Use of GUI

• Graphical User Interface Design Environment (GUIDE)


• for creating graphical user interfaces (GUIs).
• GUIDE automatically generates an M-file that controls
how the GUI operates.
• Starting GUIDE: axes Push
buttons
>> guide
OR:

Static
text

Pop-up menu
Axes static text
Frames

Checkbox Slider

Edit text

Radio Buttons Push Buttons


You are now free to explore…
Activity planned/ Nano Projects

• ‘Hello World’ – A sample program in Matlab.


• Waveform generation.
• Amplify a 1D signal.
• Addition of two 1D signals.
• Plot an impulse function which is 1 at the origin and 0 elsewhere.
• Input and display a grayscale image.
• Apply transformations such as scaling and rotation on an image.
• Smoothen an image.
• Sharpen an image.
• Input and display a colour image.
• Input and display a video sequence.
Useful Links/Tutorials/Video lectures/Course websites

• http://ocw.mit.edu/courses/mathematics/18-s997-
introduction-to-matlab-programming-fall-2011/
• https://onlinecourses.nptel.ac.in/noc16_ch01/preview
• http://ocw.mit.edu/resources/res-6-008-digital-signal-
processing-spring-2011
• http://in.mathworks.com/academia/student_center/
tutorials/signal-processing-tutorial-launchpad.html?
s_tid=srchtitle
• http://nptel.iitm.ac.in/video.php?
subjectId=117102060
Test
1. Matlab program to find the sum of first n Fibonacci numbers.
2. Matlab program to find the sum of geometric series

3. Matlab program to compute sin(x) and cos(x).


4. Matlab program to compute mean and variance.
5. Matlab program to compute cumulative sum of elements in an
array.
6. Matlab program to compute eigenvalues of a matrix.
7. Matlab program to compute nCr and nPr.
8. Matlab program to compute the area &perimeter of a rectangle.
9. Matlab program to search for a number in an array.
10. Matlab program to sort an array.

You might also like