What is MATLAB? MATLAB stands for MATrix LABoratory.. Why Learn MATLAB and DSP? Digital Signal Processing DSP is the dominant technology today, and into the future, for small-signal
Trang 2What is MATLAB?
MATLAB stands for MATrix LABoratory
MATLAB is a high-performance language for
technical computing.
Math and computation
Algorithm development (optimized for DSP)
Data acquisition
Modeling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical
user interface building
Trang 3Why Learn and Use MATLAB?
Heavily used in EET/CET courses with DSP
content (CET311, EET350, EET453)
Extensive built-in commands for scientific
and engineering mathematics
Easy way to generate class demonstrations
and test examples
Simple and intuitive programming for more
complex problems
Standard and widely-used computational
environment with many features,
extensions, and links to other software.
Trang 4Code
Composer
DSP Processor Platform
MATLAB + PC = DSP Processor!! (just less efficient)
Trang 5Why Learn MATLAB (and DSP)?
Digital Signal Processing (DSP) is the
dominant technology today, and into the
future, for small-signal electronic systems (i.e., just about everything)
MATLAB has become one of the standard
design environments for DSP engineering
Our students need to be literate and skilled
in this environment: knowledgeable in both
DSP and MATLAB
Trang 6How Can I Learn MATLAB?
Keep a copy of this presentation for
reference (available on my Web
Page)
Get MATLAB loaded on your PC
Read the “Getting Started” Users
Guide at the MathWorks web site
Study some of the built-in help files
and demos
Dive right in and use it!
Trang 7This Presentation
The MATLAB System
The basics of MATLAB computation
The basics of MATLAB graphing
The basics of MATLAB programming
Various course examples
Mathematics
Electronics
Physics
Signal Processing(*)
Trang 8The MATLAB System
MATLAB desktop
Editor and debugger for MATLAB programs (“m-files”)
Browsers for help, built-in and on-line documentation
Extensive demos
Elementary functions, like sum, sine, cosine, and complex arithmetic
More sophisticated functions like matrix inverse, matrix eigenvalues, Bessel
functions, and fast Fourier transforms
“Toolboxes” for special application areas such as Signal Processing
“Programming in the small" to rapidly create quick and dirty throw-away
programs, or
“Programming in the large" to create large and complex application programs
2D and 3D plots
Editing and annotation features
A library that allows you to write C and Fortran programs that interact with
MATLAB
Trang 9MATLAB Development Environment (Workspace)
Trang 10MATLAB “Help” Utilities
MATLAB is so rich that ‘help’ is essential
Command name and syntax
Command input/output parameters
Trang 11MATLAB Function Library
(A Subset)
matlab\general - General purpose commands.
matlab\ops - Operators and special characters.
matlab\lang - Programming language constructs.
matlab\elmat - Elementary matrices and matrix manipulation matlab\elfun - Elementary math functions.
matlab\specfun - Specialized math functions.
matlab\matfun - Matrix functions - numerical linear algebra matlab\datafun - Data analysis and Fourier transforms.
matlab\polyfun - Interpolation and polynomials.
matlab\funfun - Function functions and ODE solvers.
matlab\sparfun - Sparse matrices.
matlab\scribe - Annotation and Plot Editing.
matlab\graph2d - Two dimensional graphs.
matlab\graph3d - Three dimensional graphs.
matlab\specgraph - Specialized graphs.
matlab\graphics - Handle Graphics.
Trang 12Some Elementary Functions
Exponential
exp - Exponential.
expm1 - Compute exp(x)-1 accurately.
log - Natural logarithm.
log1p - Compute log(1+x) accurately.
log10 - Common (base 10) logarithm.
log2 - Base 2 logarithm and dissect floating point number pow2 - Base 2 power and scale floating point number.
realpow - Power that will error out on complex result.
reallog - Natural logarithm of real number.
realsqrt - Square root of number greater than or equal to zero sqrt - Square root.
nthroot - Real n-th root of real numbers.
nextpow2 - Next higher power of 2.
Trang 13Some Specialized Functions
Number theoretic functions.
factor - Prime factors
isprime - True for prime numbers
primes - Generate list of prime numbers
gcd - Greatest common divisor
lcm - Least common multiple
rat - Rational approximation
rats - Rational output
perms - All possible permutations
nchoosek - All combinations of N elements taken K at a time factorial - Factorial function
Trang 14The MATLAB Language
(M-file example)
function one_period(amp,freq,phase)
% ONE_PERIOD(AMP,FREQ,PHASE)
% This function plots one period of a sine wave with a given amplitude,
% frequency (in Hz), and phase ( in degrees).
T=1000/freq; % Compute the period in ms
t=0:T/100:T; % Define a 100 point ms time vector 1 period long
y=amp*sin(2*pi*t/T+phase*pi/180); % One period of the sine function
plot(t,y) % Plot the result and format the axes and title
xlabel('milliseconds')
ylabel('amplitude')
title(['One Period of a ',num2str(freq),' Hz Sinewave with
',num2str(phase), ' Degree phase'])
Trang 15MATLAB Graphics:
2D Functions (Physics Example)
Trang 16MATLAB Graphics:
2D Functions (Physics Example)
0 500 1000 1500 2000 2500 3000 3500
Trang 17MATLAB Graphics:
3D Functions (DSP Example)
Trang 18Basic MATLAB Computation:
Representation of Numbers and Variables
MATLAB operates on n row by m column
Trang 19Basic MATLAB Computation:
Array, vector, and scalar operators
Matrix and vector addition and
multiplication
Element-by-element operations
Variable statements and definitions
Trang 20MATLAB Plotting and Graphics
Rich set of commands for 2D and 3D
plotting of functions
Command formatting and editing
GUI formatting and editing
Image display capabilities
Animation capabilities
Simple “copy and paste” for
publishing generated figures
Trang 21MATLAB Plotting
Basic Commands
representation of digital signals)
Etc, etc - See MATLAB help documentation
Trang 22Basic Plotting - Examples
Plot of sin(x) function
Stem of sin(x) function
Bar of sin(x) function
Several sine functions with “hold”
Several sine functions with “subplot”
Trang 23Basic MATLAB Programming
Scripts
Functions
Trang 24Structure of m-file Functions:
Use of MATLAB functions as subroutines
Use of “nargin” test and branch
Trang 25Mathematics Example:
Polynomial Algebra (Convolution Operator)
Polynomial products and factoring:
8 20
26 21
8 )
4 4
5 )(
2 3
Trang 264
33
25
=+
−
−
=+
z y
z y x
Trang 29Electronic Circuits Example:
Mesh Analysis (Linear System)
Find the currents in
A*X = B
Trang 30Electronic Circuits Example:
FET Operating Point
Find the DC operating point of the following
D
S
GS D
V
V I
I
R V I
Trang 31Electronic Circuits Example: FET Operating Point
M-file: [Vgs_o,Id_o]=NFET_OP(Idss,Vp,Rs)
[v,id]=nfet_op(12,-4,1200);
-4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0
0.002 0.004 0.006 0.008 0.01 0.012
Trang 3250 m in front of goalposts whose
horizontal bar is 3.44 m above the
ground?
Trang 33Physics Example:
Field Goal Problem
Solution: The general solution is the “trajectory equation.”
where y = height, x = distance from goal, v0 = take-off
speed, θ0 = take-off angle Given the take-off speed of
25 m/s, the problem requires the solutions for θ0 that
result in a minimum height of y = 3.44 m at a distance
of x = 50 m from the goal post Although an analytical
solution is possible, a graphical solution provides more
) ( cos 2
2 0
θ
θ
v
gx x
Trang 34Physics Example:
Field Goal Problem
MATLAB code for a graphical solution:
Trang 35Physics Example:
MATLAB Results
Trang 36Signal Processing Examples
Fourier Synthesis and the Gibbs Phenomenon
][n 0 SINC 0n
π
,
5 , 3 , 1
) 2 sin(
2 ) (
s
n square
π π