Download plot - Inplant Training in chennai

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to MATLAB
What 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
WWW.KAASHIVINFOTECH.COM
Why 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.
WWW.KAASHIVINFOTECH.COM
MATLAB in DSP Product Development
Develop and
Test Algorithms
in MATLAB
Code
Composer
SIMULINK
Simulation
DSP
Processor
Platform
MATLAB + PC = DSP Processor!! (just less efficient)
WWW.KAASHIVINFOTECH.COM
Why 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
WWW.KAASHIVINFOTECH.COM
How 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!
WWW.KAASHIVINFOTECH.COM
This 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(*)
WWW.KAASHIVINFOTECH.COM
The MATLAB System

Development Environment.





The MATLAB Mathematical Function Library.




“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.
Graphics.



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
The MATLAB Language.



MATLAB desktop
Editor and debugger for MATLAB programs (“m-files”)
Browsers for help, built-in and on-line documentation
Extensive demos
2D and 3D plots
Editing and annotation features
The MATLAB Application Program Interface (API).

A library that allows you to write C and Fortran programs that interact with MATLAB.
WWW.KAASHIVINFOTECH.COM
MATLAB Development Environment
(Workspace)
WWW.KAASHIVINFOTECH.COM
MATLAB “Help” Utilities
 MATLAB is so rich that ‘help’ is essential
 Command name and syntax
 Command input/output parameters
 Usage examples
 Help command
 help command_name
 help [partial_name] tab
 Help documents
 Demos
WWW.KAASHIVINFOTECH.COM
MATLAB Function Library
(A Subset)
matlab\general
matlab\ops
matlab\lang
matlab\elmat
matlab\elfun
matlab\specfun
matlab\matfun
matlab\datafun
matlab\polyfun
matlab\funfun
matlab\sparfun
matlab\scribe
matlab\graph2d
matlab\graph3d
matlab\specgraph
matlab\graphics
- General purpose commands.
- Operators and special characters.
- Programming language constructs.
- Elementary matrices and matrix manipulation.
- Elementary math functions.
- Specialized math functions.
- Matrix functions - numerical linear algebra.
- Data analysis and Fourier transforms.
- Interpolation and polynomials.
- Function functions and ODE solvers.
- Sparse matrices.
- Annotation and Plot Editing.
- Two dimensional graphs.
- Three dimensional graphs.
- Specialized graphs.
- Handle Graphics.
WWW.KAASHIVINFOTECH.COM
Some 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.
WWW.KAASHIVINFOTECH.COM
Some 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.
WWW.KAASHIVINFOTECH.COM
The 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'])
WWW.KAASHIVINFOTECH.COM
MATLAB Graphics:
2D Functions (Physics Example)
WWW.KAASHIVINFOTECH.COM
MATLAB Graphics:
2D Functions (Physics Example)
Planck Radiation Law
3500
kilowatts/sq.meter-micron
3000
3000 K
2700 K
2500 K
2500
2000
1500
1000
500
0
0
1
2
WWW.KAASHIVINFOTECH.COM
3
4
5
6
wavelength microns
7
8
9
10
MATLAB Graphics:
3D Functions (DSP Example)
WWW.KAASHIVINFOTECH.COM
Basic MATLAB Computation:
Representation of Numbers and Variables
 MATLAB operates on n row by m column matrices:
 A n x m quantity is an array
A1x
[8
1
6
m 3or a n5 x 1 7quantity is
4 [89 1 2]
6]
 A 1 x 1 quantity is a scalar
[8]
WWW.KAASHIVINFOTECH.COM
a vector
Basic MATLAB Computation:
Basic Operations
 Array manipulation (Magic Square example)
 Sum, diag, transpose, colon operator, indexing
 Array, vector, and scalar operators
 Matrix and vector addition and multiplication
 Element-by-element operations
 Variable statements and definitions
WWW.KAASHIVINFOTECH.COM
MATLAB 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
WWW.KAASHIVINFOTECH.COM
MATLAB Plotting
Basic Commands
 plot – x,y line plots
 stem – n,y discrete plots (standard representation of digital signals)
 bar – vertical bar plots
 plot3 – 3D x,y,z line plots
 mesh, surf, etc. – 3D surface plots
 show_img – display matrix as an image
 hold – hold current figure for multiple line plots
 subplot – put multiple plots in one figure frame
 Etc, etc. - See MATLAB help documentation
WWW.KAASHIVINFOTECH.COM
Basic 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”
 2D plot of sinc(x)
 3D plot of sinc(x) [“plot_sinc” m-file]
 GUI editing
 View by rotation
 Animation [“brownian_demo” m-file]
WWW.KAASHIVINFOTECH.COM
Basic MATLAB Programming
 Scripts






String of MATLAB commands
Stored as m-file (*.m)
Use variables from command line
Variables have names consistent with script variable names
Used for “quick and dirty” programs
Example: “dydx_script”
 Functions







String of MATLAB commands
Stored as m-file (*.m)
Use variables as function parameters
No restriction on parameter names
Can return variable results
Used for general purpose programs
Example: “yy=dydx(x,y)
WWW.KAASHIVINFOTECH.COM
Structure of m-file Functions:
Examples
 “one_period”
 Use of “num2str” for variable formatting
 “sumofsines”
 Use of parameter-controlled data input loops
 “fft_plot”
 Use of MATLAB functions as subroutines
 Use of “nargin” test and branch
WWW.KAASHIVINFOTECH.COM
Mathematics Example:
Polynomial Algebra (Convolution Operator)
 Polynomial products and factoring:
( x 2  3x  2)( x3  5x 2  4 x  4)  x5  8x 4  21x3  26 x 2  20 x  8
>> p1=[1,3,2];
>> p2=[1,5,4,4];
>> pc=conv(p1,p2)
pc =
1
8 21 26
20
>> deconv(pc,p2)
ans =
1
3
2
>> deconv(pc,p1)
ans =
1
5
4
4
WWW.KAASHIVINFOTECH.COM
8
Mathematics Example:
Linear Systems
 Solve the system:
5 x  2 y  3z  3
4 y  3 z  2
x  y  9 z  60
 A*S=B
 MATLAB Code:
>> A=[5,-2,-3;0,4,3;1,-1,9];
>> B=[-3,-2,60]'; % Note vector transpose (‘)
>> S=linsolve(A,B)
S=
1.0000
-5.0000
6.0000
WWW.KAASHIVINFOTECH.CO
M
Mathematics Example:
Polynomial Roots
 Find the roots of the following system:
y  12 x 2  x  8
 MATLAB code:
>> roots([12 -1 -8])
ans =
0.8592
-0.7759
WWW.KAASHIVINFOTECH.CO
M
Mathematics Example:
Polynomial Roots
 Graphical Solution:
>>
>>
>>
>>
>>
>>
a=12;
b=-1;
c=-8;
x=-1:0.1:1;
y=a*x.^2+b*x+c;
plot(x,y)
WWW.KAASHIVINFOTECH.CO
M
Electronic Circuits Example:
Mesh Analysis (Linear System)
Find the currents in
each branch: I1, I2
-7I1 + 6I2 = 5
6I1 – 8I2 = -10
A*X = B
WWW.KAASHIVINFOTECH.COM
>> A=[-7,6;6,-8];
>> B=[5;-10];
>> X=linsolve(A,B)
ans =
1.0000
2.0000
Electronic Circuits Example:
FET Operating Point
 Find the DC operating point of the following circuit:
VGS
ID  
RS
 VGS
I D  I DSS 1 
 VP
WWW.KAASHIVINFOTECH.CO
M



2
Electronic Circuits Example:
FET Operating Point
 M-file: [Vgs_o,Id_o]=NFET_OP(Idss,Vp,Rs)
 [v,id]=nfet_op(12,-4,1200);
Operating Point: Vgs = -2.3754 volts and Id = 1.9795 ma
0.012
Drain Current Transfer Function
Source Resistance Load Line
0.01
Drain Current, Id
0.008
0.006
0.004
0.002
0
-4
-3.5
-3
-2.5
-2
-1.5
Gate-Source Voltage, Vgs
-1
-0.5
WWW.KAASHIVINFOTECH.CO
M
0
Physics Example:
Graphical Solution of a Trajectory
 Problem:
A football kicker can give the ball an initial speed of 25 m/s.
Within what two elevation angles must he kick the ball to
score a field goal from a point 50 m in front of goalposts
whose horizontal bar is 3.44 m above the ground?
WWW.KAASHIVINFOTECH.COM
Physics Example:
Field Goal Problem
Solution: The general solution is the “trajectory equation.”
gx 2
y  x tan( 0 )  2
2v0 cos 2 ( 0 )
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 physical insight.
WWW.KAASHIVINFOTECH.COM
Physics Example:
Field Goal Problem
 MATLAB code for a graphical solution:
>> v0=25;
>> x=50;
>> g=9.8;
>> y=3.44;
>> theta=5:.1:70;
>> theta_r=theta*pi/180;
>> z=y*ones(1,length(theta));
>> zz=x*tan(theta_r)-g*x^2./(2*v0^2*(cos(theta_r)).^2);
>> plot(theta,zz)
>> hold
Current plot held
>> plot(theta,z)
WWW.KAASHIVINFOTECH.COM
Physics Example:
MATLAB Results
WWW.KAASHIVINFOTECH.COM
Signal Processing Examples

Fourier Synthesis and the Gibbs Phenomenon
 “square_jms” m-file
2    sin( n2ft ) 
ssquare(t )   

  n 1 
n

n  1,3,5,...
 Finite Impulse Response (FIR) Filter Design
h[n] 
0
 Use of “fvtool”
SINC (0 n)

Analog-to-Digital Converter Emulation
 “adc” m-file

Digital Transfer Function in the Z-domain
 “plotH” m-file
WWW.KAASHIVINFOTECH.CO
M
Thank U
WWW.KAASHIVINFOTECH.COM
Related documents