SlideShare a Scribd company logo
1 of 47
Download to read offline
MATLABMATLAB TutorialTutorial
MATLAB Basics
&
Signal Processing Toolbox
TOCTOC
Part 2: Signal Processing Toolbox
• Representing Signals
• Basic Waveform Generation
• Convolution
• Impulse Response
• Frequency Response
• Discrete Fourier Transform
• Filters
Part 1: Introduction
• Toolboxes & Simulink
• Commands & functions
• Help system
• Variables & operators
• Graphics
• Symbolic Math Toolbox
MATLABMATLAB TutorialTutorial
Part 1Part 1
MATLAB Basics
WhatWhat isis MATLAB?MATLAB?
Matlab = Matrix Laboratory
A software environment for interactive numerical computations
Examples:
Matrix computations and linear algebra
Solving nonlinear equations
Numerical solution of differential equations
Mathematical optimization
Statistics and data analysis
Signal processing
Modelling of dynamical systems
Solving partial differential equations
Simulation of engineering systems
MATLAB ToolboxesMATLAB Toolboxes
MATLAB has a number of add-on software modules, called toolboxes, that
perform more specialized computations.
Signal & Image Processing
Signal Processing- Image Processing Communications - System
Identification - Wavelet Filter Design
Control Design
Control System - Fuzzy Logic - Robust Control -
µ-Analysis and Synthesis - LMI Control
Model Predictive Control
More than 60 toolboxes!More than 60 toolboxes!
SimulinkSimulink
Simulink - a package for modeling dynamic systems
SimulinkSimulink ((cont‘dcont‘d))
Analyzing results:
MATLABMATLAB WorkspaceWorkspace
The MATLAB environment is command oriented
Some Useful MATLAB commandsSome Useful 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
ConstructionConstruction
• Core functionality: compiled C-routines
• Most functionality is given as m-files, grouped into toolboxes
– m-files contain source code, can be copied and altered
– m-files are platform independent (PC, Unix/Linux, MAC)
• Simulation of dynamical systems is performed in Simulink
MathMath
• MATLAB can do simple math just as a calculator.
2^16^Exponentiation, ab
56/8 = 856/ or Division, a b
3.14*4.20*Multiplication, a*b
90-44-Subtraction, a – b
3 + 22+Addition, a + b
EXAMPLESYMBOLOPERATION
÷
Interactive CalculationsInteractive Calculations
Matlab is interactive, no need to declare variables
>> 2+3*4/2
>> a=5e-3; b=1; a+b
Most elementary functions and constants are already defined
>> cos(pi)
>> abs(1+i)
>> sin(pi)
FunctionsFunctions
MATLAB has many built-in functions.
Some math functions are:
acos, acosh acot, acsc, acsch, asec, asech, asin,
asinh, atan, atan2, atanh, cos, cosh, cot, coth,
csc, csch, sec, sech, sin, sinh, tan, tanh, exp,
log, log10, log2, pow2, sqrt, nextpow2, abs, angle,
conj, imag, real, unwrap, isreal, cplxpair, fix,
floor, ceil, round, mod, rem, sign, cart2sph,
cart2pol, pol2cart, sph2cart, factor, isprime,
primes, gcd, lcm, rat, rats, perms, nchoosek, airy,
besselj, bessely, besselh, besseli, besselk, beta,
betainc, betaln, ellipj, ellipke, erf, erfc, erfcx,
erfinv, expint, gamma, gammainc, gammaln, legendre,
cross, dot
The Help SystemThe Help System
Search for appropriate function
>> lookfor keyword
Rapid help with syntax and function definition
>> help function
An advanced hyperlinked help system is launched by
>> helpdesk
Complete manuals (html & pdf)
http://www.mathworks.com/access/helpdesk/help/helpdesk.html
>> lookfor convolution
CONV Convolution and polynomial multiplication.
CONV2 Two dimensional convolution.
CONVN N-dimensional convolution.
DECONV Deconvolution and polynomial division.
CONVENC Convolutionally encode binary data.
DISTSPEC Compute the distance spectrum of a convolutional code.
...
>> help conv
CONV Convolution and polynomial multiplication.
C = CONV(A, B) convolves vectors A and B. The resulting
vector is length LENGTH(A)+LENGTH(B)-1.
If A and B are vectors of polynomial coefficients, convolving
them is equivalent to multiplying the two polynomials.
Class support for inputs A,B:
float: double, single
See also deconv, conv2, convn, filter and, in the Signal
Processing Toolbox, xcorr, convmtx.
...
The help system exampleThe help system example
Step 1:
Step 2:
MATLAB Variable NamesMATLAB Variable Names
• Variable names ARE case sensitive
• Variable names can contain up to 63 characters (as of MATLAB
6.5 and newer)
• Variable names must start with a letter followed by letters, digits,
and underscores.
All variables are shown with
>> who
>> whos
Variables can be stored on file
>> save filename
>> clear
>> load filename
ans Default variable name for results
pi Value of ππππ
inf
NaN Not a number e.g. 0/0
i and j i = j =
eps Smallest incremental number
realmin The smallest usable positive real number
realmax The largest usable positive real number
MATLAB Special VariablesMATLAB Special Variables
∞
1−
MATLAB Math & Assignment OperatorsMATLAB Math & Assignment Operators
Power ^ or .^ a^b or a.^b
Multiplication * or .* a*b or a.*b
Division / or ./ a/b or a./b
or  or . ba or b.a
NOTE: 56/8 = 856
- (unary) + (unary)
Addition + a + b
Subtraction - a - b
Assignment = a = b (assign b to a)
MATLAB MatricesMATLAB Matrices
• MATLAB treats all variables as matrices. For our purposes a matrix can be
thought of as an array, in fact, that is how it is stored.
• Vectors are special forms of matrices and contain only one row OR one
column.
• Scalars are matrices with only one row AND one column
Vectors and MatricesVectors and Matrices
Vectors (arrays) are defined as
>> v = [1, 2, 4, 5]
>> w = [1; 2; 4; 5]
Matrices (2D arrays) defined similarly
>> A = [1,2,3;4,-5,6;5,-6,7]
Polynomial examplePolynomial example
01045.02.1 23
=+++ xxx
>> x=[1.2,0.5,4,10]
x =
1.200 0.500 4.00 10.00
>> roots(x)
ans =
0.59014943179299 + 2.20679713205154i
0.59014943179299 - 2.20679713205154i
-1.59696553025265
Find polynomial roots:
GraphicsGraphics
Visualization of vector data is available
>> x=-pi:0.1:pi; y=sin(x);
>> plot(x,y)
>> xlabel(’x’); ylabel(’y=sin(x)’);
stem(x,y)plot(x,y)
Matlab Selection StructuresMatlab Selection Structures
An if-elseif-else structure in MATLAB.
if expression1 % is true
% execute these commands
elseif expression2 % is true
% execute these commands
else % the default
% execute these commands
end
A for loop in MATLAB: for x = array
for x = 1: 0.5 : 10
% execute these commands
end
A while loop in MATLAB: while expression
while x <= 10
% execute these commands
end
MATLAB Repetition StructuresMATLAB Repetition Structures
>> x = -1:.05:1;
>> for n = 1:8
subplot(4,2,n);
plot(x,sin(n*pi*x));
end
““for” loop examplefor” loop example
function [A] = area(a,b,c)
s = (a+b+c)/2;
A = sqrt(s*(s-a)*(s-b)*(s-c));
To evaluate the area of a triangle with side of length 10, 15, 20:
>> Area = area(10,15,20)
Area =
72.6184
File area.m:
mm--file examplefile example
Task:
Usage example:
IntegrationIntegration exampleexample
example with trapz function:
>> x = 0:0.5:10; y = 0.5 * sqrt(x) + x .* sin(x);
>> integral1 = trapz(x,y)
integral1 =
18.1655
∫ 





+
10
0
)sin(
2
1
dxxxxFind the integral:
SymbolicSymbolic MathMath ToolboxToolbox
The Symbolic Math Toolbox uses "symbolic objects" produced by the "sym" funtion.
>> x = sym('x'); % produces a symbolic variable named x
>> f=x^3; % defines a function
Example: ( )3
x
dx
d
- ? dxx∫
3
- ?
>> x = sym('x');
>> diff(x^3)
ans =
3*x^2
>> int(x^3)
ans =
1/4*x^4
SymbolicSymbolic MathMath ToolboxToolbox
Once a symbolic variable is defined, you can use it to build functions. EZPLOT
makes it easy to plot symbolic expressions.
>> x = sym('x');
>> f = 1/(5+4*cos(x))
>> ezplot(f)
SymbolicSymbolic MathMath ToolboxToolbox
sinc(x)=si(πx)=sin(πx)/(πx)
>> ezplot(sinc(x))
Plot the following functions:
>> x = sym('x');
Gaussian
>> ezplot(exp(-pi*x*x))
MATLABMATLAB TutorialTutorial
Part 2Part 2
Signal Processing Toolbox
WhatWhat IsIs thethe SignalSignal ProcessingProcessing Toolbox?Toolbox?
The Signal Processing Toolbox is a collection of tools or functions
expressed mostly in M-files, that implement a variety of signal
processing tasks.
Command line functions for:
• Analog and digital filter analysis
• Digital filter implementation
• FIR and IIR digital filter design
• Analog filter design
• Statistical signal processing and
spectral analysis
• Waveform generation
Interactive tools (GUIs) for:
• Filter design and analysis
• Window design and analysis
• Signal plotting and analysis
• Spectral analysis
• Filtering signals
RepresentingRepresenting signalssignals
MATLAB represents signals as vectors:
>> x=[1,2,3,5,3,2,1]
x =
1 2 3 5 3 2 1
>> stem(x)
WaveformWaveform GenerationGeneration
A sample signal y consisting of two sinusoids, one at 50Hz and one at 120 Hz with twice
the amplitude:
>> y = sin(2*pi*50*t) + 2*sin(2*pi*120*t);
>> plot(t(1:50),y(1:50));
Consider generating data with a 1000 Hz sample frequency.
An appropriate time vector:
>> t = 0:0.001:1; % a 1001-element row vector that represents
% time running from zero to one second
% in steps of one millisecond.
WaveformWaveform GenerationGeneration
Basic Signals:
Unit impulse:
>> t = 0:0.01:1;
>> y = [zeros(1,50),1,zeros(1,50)];
>> plot(t,y);
Unit step:
>> y = [zeros(1,50),ones(1,51)];
>> plot(t,y);
Triangle:
>> t=-1:0.001:1;
>> y=tripuls(t);
>> plot (t,y);
Rectangle:
>> t=-1:0.001:1;
>> y=rectpuls(t);
>> plot (t,y);
WaveformWaveform GenerationGeneration
Common Sequences:
Sawtooth:
>> fs = 10000;
>> t = 0:1/fs:1.5;
>> x = sawtooth(2*pi*50*t);
>> plot(t,x), axis([0 0.2 -1 1]);
Square wave:
>> t=0:20;
>> y=square(t);
>> plot(t,y)
Sinc function:
>> t = -5:0.1:5;
>> y = sinc(t);
>> plot(t,y)
ConvolutionConvolution
>> t1=-1:0.001:1;
>> tri=tripuls(t1,2);
>> plot(t1,tri);
*
=>> c=conv(tri,tri);
>> t2=-2:0.001:2;
>> plot(t2,c);
ConvolutionConvolution ((ExampleExample))
Let the rectangular pulse x(n)= r(0.1n-5) be an input to an LTI system with
impulse response h(n)=0.9n s(n). Determine the output y(n).
>> x=rectpuls(n,10);
>> x=circshift(x,[0 5]);
>> stem(n,x)
>> step=[zeros(1,5),ones(1,51)];
>> h=0.9.^n.*step;
>> stem(n,h)
>> y=conv(h,x);
>> stem(y)
FiltersFilters
Z-transform Y(z) of a digital filter’s output y(n) is related to the z-transform
X(z) of the input by:
The system can also be specified by a linear difference equation:
MATLAB function filter - filter data with a recursive (IIR) or
nonrecursive (FIR) filter
FilterFilter ((ExampleExample 1)1)
Given the following difference eqaution of a filter:
Calculate and plot the impulse response h(n) and unit step response s(n) at n= -20,…,100.
y(n)-y(n-1)+0.9y(n-2)=x(n)
>> a=[1,-1,0.9]; b=[1];
>> n=[-20:120];
>> x=[zeros(1,20),1,zeros(1,120)];
>> h=filter(b,a,x);
>> stem(n,h); title('impulse response');
>> x=[zeros(1,20),ones(1,121)];
>> s=filter(b,a,x);
>> stem(n,s); title('step response');
FilterFilter ((ExampleExample 2)2)
Create a 10-point averaging lowpass FIR filter:
]9[
10
1
...]1[
10
1
][
10
1
][ −++−+= nxnxnxny
As an input consider a 1-second duration signal sampled at 100 Hz, composed of
two sinusoidal components at 3 Hz and 40 Hz.
>> fs = 100;
>> t = 0:1/fs:1;
>> x = sin(2*pi*t*3)+.25*sin(2*pi*t*40);
>> b = ones(1,10)/10; % 10 point averaging filter
>> y = filter(b,1,x);
>> plot(t,x,'b',t,y,'r')
DiscreteDiscrete--Time Fourier SeriesTime Fourier Series
DTFS is a frequency-domain representation for periodic discrete-time sequences.
For a signal x[n] with fundamental period N, the DTFS equations are given by:
nNjk
N
k
k eanx )/2(
1
0
][ π
∑
−
=
=
nNjk
N
n
k enx
N
a )/2(
1
0
][
1 π−
−
=
∑=
fft – is an efficient implementation in MATLAB to calculate ak.
DiscreteDiscrete--Time Fourier SeriesTime Fourier Series ((ExampleExample))
Find DTFS for periodic discrete-time signal x[n]
with period N=30
>> x=[1,1,zeros(1,28)];
>> N=30; n=0:N-1;
>> a=(1/N)*fft(x);
>> real_part=real(a);
>> stem(n,real_part);
>> xlabel('k'); ylabel('real(a)');
>> imag_part=imag(a);
>> stem(n,imag_part);
>> xlabel('k'); ylabel('imag(a)');
FrequencyFrequency ResponseResponse ((ExampleExample))
Find the frequency response of a 10-point averaging lowpass FIR filter and
plot ist magnitude and phase
]9[
10
1
...]1[
10
1
][
10
1
][ −++−+= nxnxnxny
>> b = ones(1,10)/10; a=1;
>> [H omega]=freqz(b,a,100,'whole');
>> magH=abs(H);
>> plot(omega, magH); grid;
>> angH=angle(H);
>> plot(omega, angH/pi); grid;
>> N=256; % number of samples
>> T=1/128; % sampling frequency=128Hz
>> k=0:N-1; time=k*T;
>> f=0.25+2*sin(2*pi*5*k*T)+1*sin(2*pi*12.5*k*T)+…
+1.5*sin(2*pi*20*k*T)+0.5*sin(2*pi*35*k*T);
>> plot(time,f); title('Signal sampled at 128Hz');
>> F=fft(f);
>> magF=abs([F(1)/N,F(2:N/2)/(N/2)]);
>> hertz=k(1:N/2)*(1/(N*T));
>> stem(hertz,magF), title('Frequency components');
ExampleExample
Find the spectrum of the following signal:
f=0.25+2sin(2π5k)+sin(2π12.5k)+1.5sin(2π20k)+0.5sin(2π35k)
ExampleExample
Find the frequency components of a signal buried in noise. Consider data
sampled at 1000 Hz. Form a signal consisting of 50 Hz and 120 Hz sinusoids
and corrupt the signal with random noise.
>> t = 0:0.001:0.6;
>> x = sin(2*pi*50*t) + sin(2*pi*120*t);
>> y = x + 2*randn(1,length(t));
>> plot(y(1:50));
ExampleExample ((cont‘dcont‘d))
It is difficult to identify the frequency components by studying the original signal.
The discrete Fourier transform of the noisy signal using a 512-point fast Fourier transform
(FFT):
>> Y = fft(y,512);
The power spectral density, a measurement of the energy at various frequencies, is
>> Pyy = Y.*conj(Y) / 512;
>> f = 1000*(0:255)/512;
>> plot(f,Pyy(1:256))
LinksLinks
One-hour recorded online Webinars
http://www.mathworks.com/company/events/archived_webinars.html
All matlab manuals
http://www.mathworks.com/access/helpdesk/help/helpdesk.html
Matlab Tutorials
http://www.math.ufl.edu/help/matlab-tutorial/
http://www.math.unh.edu/~mathadm/tutorial/software/matlab/

More Related Content

What's hot

Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabBilawalBaloch1
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Randa Elanwar
 
Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsRay Phan
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab IntroductionDaniel Moore
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to MatlabAmr Rashed
 
Matlab (Presentation on MATLAB)
Matlab (Presentation on MATLAB)Matlab (Presentation on MATLAB)
Matlab (Presentation on MATLAB)Chetan Allapur
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introductionideas2ignite
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1Elaf A.Saeed
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABBhavesh Shah
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operatorsLuckshay Batra
 
Matlab introduction lecture 1
Matlab introduction lecture 1Matlab introduction lecture 1
Matlab introduction lecture 1Mohamed Awni
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlabkrajeshk1980
 
Matrix operations in MATLAB
Matrix operations in MATLABMatrix operations in MATLAB
Matrix operations in MATLABSaloni Singhal
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arraysAmeen San
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
Basic operators in matlab
Basic operators in matlabBasic operators in matlab
Basic operators in matlabrishiteta
 

What's hot (20)

Matlab
MatlabMatlab
Matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
 
Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & Scientists
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Matlab (Presentation on MATLAB)
Matlab (Presentation on MATLAB)Matlab (Presentation on MATLAB)
Matlab (Presentation on MATLAB)
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Fundamentals of matlab
Fundamentals of matlabFundamentals of matlab
Fundamentals of matlab
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operators
 
Matlab introduction lecture 1
Matlab introduction lecture 1Matlab introduction lecture 1
Matlab introduction lecture 1
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Matrix operations in MATLAB
Matrix operations in MATLABMatrix operations in MATLAB
Matrix operations in MATLAB
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Basic operators in matlab
Basic operators in matlabBasic operators in matlab
Basic operators in matlab
 

Similar to Matlab intro

matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxlekhacce
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshopVinay Kumar
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsMukesh Kumar
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionAmeen San
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab Arshit Rai
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxprashantkumarchinama
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab Arshit Rai
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab OverviiewNazim Naeem
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013amanabr
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Kurmendra Singh
 

Similar to Matlab intro (20)

matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsx
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab Overviiew
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Matlab
MatlabMatlab
Matlab
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 

Recently uploaded

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 

Recently uploaded (20)

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 

Matlab intro

  • 2. TOCTOC Part 2: Signal Processing Toolbox • Representing Signals • Basic Waveform Generation • Convolution • Impulse Response • Frequency Response • Discrete Fourier Transform • Filters Part 1: Introduction • Toolboxes & Simulink • Commands & functions • Help system • Variables & operators • Graphics • Symbolic Math Toolbox
  • 4. WhatWhat isis MATLAB?MATLAB? Matlab = Matrix Laboratory A software environment for interactive numerical computations Examples: Matrix computations and linear algebra Solving nonlinear equations Numerical solution of differential equations Mathematical optimization Statistics and data analysis Signal processing Modelling of dynamical systems Solving partial differential equations Simulation of engineering systems
  • 5. MATLAB ToolboxesMATLAB Toolboxes MATLAB has a number of add-on software modules, called toolboxes, that perform more specialized computations. Signal & Image Processing Signal Processing- Image Processing Communications - System Identification - Wavelet Filter Design Control Design Control System - Fuzzy Logic - Robust Control - µ-Analysis and Synthesis - LMI Control Model Predictive Control More than 60 toolboxes!More than 60 toolboxes!
  • 6. SimulinkSimulink Simulink - a package for modeling dynamic systems
  • 8. MATLABMATLAB WorkspaceWorkspace The MATLAB environment is command oriented
  • 9. Some Useful MATLAB commandsSome Useful 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
  • 10. ConstructionConstruction • Core functionality: compiled C-routines • Most functionality is given as m-files, grouped into toolboxes – m-files contain source code, can be copied and altered – m-files are platform independent (PC, Unix/Linux, MAC) • Simulation of dynamical systems is performed in Simulink
  • 11. MathMath • MATLAB can do simple math just as a calculator. 2^16^Exponentiation, ab 56/8 = 856/ or Division, a b 3.14*4.20*Multiplication, a*b 90-44-Subtraction, a – b 3 + 22+Addition, a + b EXAMPLESYMBOLOPERATION ÷
  • 12. Interactive CalculationsInteractive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> a=5e-3; b=1; a+b Most elementary functions and constants are already defined >> cos(pi) >> abs(1+i) >> sin(pi)
  • 13. FunctionsFunctions MATLAB has many built-in functions. Some math functions are: acos, acosh acot, acsc, acsch, asec, asech, asin, asinh, atan, atan2, atanh, cos, cosh, cot, coth, csc, csch, sec, sech, sin, sinh, tan, tanh, exp, log, log10, log2, pow2, sqrt, nextpow2, abs, angle, conj, imag, real, unwrap, isreal, cplxpair, fix, floor, ceil, round, mod, rem, sign, cart2sph, cart2pol, pol2cart, sph2cart, factor, isprime, primes, gcd, lcm, rat, rats, perms, nchoosek, airy, besselj, bessely, besselh, besseli, besselk, beta, betainc, betaln, ellipj, ellipke, erf, erfc, erfcx, erfinv, expint, gamma, gammainc, gammaln, legendre, cross, dot
  • 14. The Help SystemThe Help System Search for appropriate function >> lookfor keyword Rapid help with syntax and function definition >> help function An advanced hyperlinked help system is launched by >> helpdesk Complete manuals (html & pdf) http://www.mathworks.com/access/helpdesk/help/helpdesk.html
  • 15. >> lookfor convolution CONV Convolution and polynomial multiplication. CONV2 Two dimensional convolution. CONVN N-dimensional convolution. DECONV Deconvolution and polynomial division. CONVENC Convolutionally encode binary data. DISTSPEC Compute the distance spectrum of a convolutional code. ... >> help conv CONV Convolution and polynomial multiplication. C = CONV(A, B) convolves vectors A and B. The resulting vector is length LENGTH(A)+LENGTH(B)-1. If A and B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two polynomials. Class support for inputs A,B: float: double, single See also deconv, conv2, convn, filter and, in the Signal Processing Toolbox, xcorr, convmtx. ... The help system exampleThe help system example Step 1: Step 2:
  • 16. MATLAB Variable NamesMATLAB Variable Names • Variable names ARE case sensitive • Variable names can contain up to 63 characters (as of MATLAB 6.5 and newer) • Variable names must start with a letter followed by letters, digits, and underscores. All variables are shown with >> who >> whos Variables can be stored on file >> save filename >> clear >> load filename
  • 17. ans Default variable name for results pi Value of ππππ inf NaN Not a number e.g. 0/0 i and j i = j = eps Smallest incremental number realmin The smallest usable positive real number realmax The largest usable positive real number MATLAB Special VariablesMATLAB Special Variables ∞ 1−
  • 18. MATLAB Math & Assignment OperatorsMATLAB Math & Assignment Operators Power ^ or .^ a^b or a.^b Multiplication * or .* a*b or a.*b Division / or ./ a/b or a./b or or . ba or b.a NOTE: 56/8 = 856 - (unary) + (unary) Addition + a + b Subtraction - a - b Assignment = a = b (assign b to a)
  • 19. MATLAB MatricesMATLAB Matrices • MATLAB treats all variables as matrices. For our purposes a matrix can be thought of as an array, in fact, that is how it is stored. • Vectors are special forms of matrices and contain only one row OR one column. • Scalars are matrices with only one row AND one column
  • 20. Vectors and MatricesVectors and Matrices Vectors (arrays) are defined as >> v = [1, 2, 4, 5] >> w = [1; 2; 4; 5] Matrices (2D arrays) defined similarly >> A = [1,2,3;4,-5,6;5,-6,7]
  • 21. Polynomial examplePolynomial example 01045.02.1 23 =+++ xxx >> x=[1.2,0.5,4,10] x = 1.200 0.500 4.00 10.00 >> roots(x) ans = 0.59014943179299 + 2.20679713205154i 0.59014943179299 - 2.20679713205154i -1.59696553025265 Find polynomial roots:
  • 22. GraphicsGraphics Visualization of vector data is available >> x=-pi:0.1:pi; y=sin(x); >> plot(x,y) >> xlabel(’x’); ylabel(’y=sin(x)’); stem(x,y)plot(x,y)
  • 23. Matlab Selection StructuresMatlab Selection Structures An if-elseif-else structure in MATLAB. if expression1 % is true % execute these commands elseif expression2 % is true % execute these commands else % the default % execute these commands end A for loop in MATLAB: for x = array for x = 1: 0.5 : 10 % execute these commands end A while loop in MATLAB: while expression while x <= 10 % execute these commands end MATLAB Repetition StructuresMATLAB Repetition Structures
  • 24. >> x = -1:.05:1; >> for n = 1:8 subplot(4,2,n); plot(x,sin(n*pi*x)); end ““for” loop examplefor” loop example
  • 25. function [A] = area(a,b,c) s = (a+b+c)/2; A = sqrt(s*(s-a)*(s-b)*(s-c)); To evaluate the area of a triangle with side of length 10, 15, 20: >> Area = area(10,15,20) Area = 72.6184 File area.m: mm--file examplefile example Task: Usage example:
  • 26. IntegrationIntegration exampleexample example with trapz function: >> x = 0:0.5:10; y = 0.5 * sqrt(x) + x .* sin(x); >> integral1 = trapz(x,y) integral1 = 18.1655 ∫       + 10 0 )sin( 2 1 dxxxxFind the integral:
  • 27. SymbolicSymbolic MathMath ToolboxToolbox The Symbolic Math Toolbox uses "symbolic objects" produced by the "sym" funtion. >> x = sym('x'); % produces a symbolic variable named x >> f=x^3; % defines a function Example: ( )3 x dx d - ? dxx∫ 3 - ? >> x = sym('x'); >> diff(x^3) ans = 3*x^2 >> int(x^3) ans = 1/4*x^4
  • 28. SymbolicSymbolic MathMath ToolboxToolbox Once a symbolic variable is defined, you can use it to build functions. EZPLOT makes it easy to plot symbolic expressions. >> x = sym('x'); >> f = 1/(5+4*cos(x)) >> ezplot(f)
  • 29. SymbolicSymbolic MathMath ToolboxToolbox sinc(x)=si(πx)=sin(πx)/(πx) >> ezplot(sinc(x)) Plot the following functions: >> x = sym('x'); Gaussian >> ezplot(exp(-pi*x*x))
  • 30. MATLABMATLAB TutorialTutorial Part 2Part 2 Signal Processing Toolbox
  • 31. WhatWhat IsIs thethe SignalSignal ProcessingProcessing Toolbox?Toolbox? The Signal Processing Toolbox is a collection of tools or functions expressed mostly in M-files, that implement a variety of signal processing tasks. Command line functions for: • Analog and digital filter analysis • Digital filter implementation • FIR and IIR digital filter design • Analog filter design • Statistical signal processing and spectral analysis • Waveform generation Interactive tools (GUIs) for: • Filter design and analysis • Window design and analysis • Signal plotting and analysis • Spectral analysis • Filtering signals
  • 32. RepresentingRepresenting signalssignals MATLAB represents signals as vectors: >> x=[1,2,3,5,3,2,1] x = 1 2 3 5 3 2 1 >> stem(x)
  • 33. WaveformWaveform GenerationGeneration A sample signal y consisting of two sinusoids, one at 50Hz and one at 120 Hz with twice the amplitude: >> y = sin(2*pi*50*t) + 2*sin(2*pi*120*t); >> plot(t(1:50),y(1:50)); Consider generating data with a 1000 Hz sample frequency. An appropriate time vector: >> t = 0:0.001:1; % a 1001-element row vector that represents % time running from zero to one second % in steps of one millisecond.
  • 34. WaveformWaveform GenerationGeneration Basic Signals: Unit impulse: >> t = 0:0.01:1; >> y = [zeros(1,50),1,zeros(1,50)]; >> plot(t,y); Unit step: >> y = [zeros(1,50),ones(1,51)]; >> plot(t,y); Triangle: >> t=-1:0.001:1; >> y=tripuls(t); >> plot (t,y); Rectangle: >> t=-1:0.001:1; >> y=rectpuls(t); >> plot (t,y);
  • 35. WaveformWaveform GenerationGeneration Common Sequences: Sawtooth: >> fs = 10000; >> t = 0:1/fs:1.5; >> x = sawtooth(2*pi*50*t); >> plot(t,x), axis([0 0.2 -1 1]); Square wave: >> t=0:20; >> y=square(t); >> plot(t,y) Sinc function: >> t = -5:0.1:5; >> y = sinc(t); >> plot(t,y)
  • 36. ConvolutionConvolution >> t1=-1:0.001:1; >> tri=tripuls(t1,2); >> plot(t1,tri); * =>> c=conv(tri,tri); >> t2=-2:0.001:2; >> plot(t2,c);
  • 37. ConvolutionConvolution ((ExampleExample)) Let the rectangular pulse x(n)= r(0.1n-5) be an input to an LTI system with impulse response h(n)=0.9n s(n). Determine the output y(n). >> x=rectpuls(n,10); >> x=circshift(x,[0 5]); >> stem(n,x) >> step=[zeros(1,5),ones(1,51)]; >> h=0.9.^n.*step; >> stem(n,h) >> y=conv(h,x); >> stem(y)
  • 38. FiltersFilters Z-transform Y(z) of a digital filter’s output y(n) is related to the z-transform X(z) of the input by: The system can also be specified by a linear difference equation: MATLAB function filter - filter data with a recursive (IIR) or nonrecursive (FIR) filter
  • 39. FilterFilter ((ExampleExample 1)1) Given the following difference eqaution of a filter: Calculate and plot the impulse response h(n) and unit step response s(n) at n= -20,…,100. y(n)-y(n-1)+0.9y(n-2)=x(n) >> a=[1,-1,0.9]; b=[1]; >> n=[-20:120]; >> x=[zeros(1,20),1,zeros(1,120)]; >> h=filter(b,a,x); >> stem(n,h); title('impulse response'); >> x=[zeros(1,20),ones(1,121)]; >> s=filter(b,a,x); >> stem(n,s); title('step response');
  • 40. FilterFilter ((ExampleExample 2)2) Create a 10-point averaging lowpass FIR filter: ]9[ 10 1 ...]1[ 10 1 ][ 10 1 ][ −++−+= nxnxnxny As an input consider a 1-second duration signal sampled at 100 Hz, composed of two sinusoidal components at 3 Hz and 40 Hz. >> fs = 100; >> t = 0:1/fs:1; >> x = sin(2*pi*t*3)+.25*sin(2*pi*t*40); >> b = ones(1,10)/10; % 10 point averaging filter >> y = filter(b,1,x); >> plot(t,x,'b',t,y,'r')
  • 41. DiscreteDiscrete--Time Fourier SeriesTime Fourier Series DTFS is a frequency-domain representation for periodic discrete-time sequences. For a signal x[n] with fundamental period N, the DTFS equations are given by: nNjk N k k eanx )/2( 1 0 ][ π ∑ − = = nNjk N n k enx N a )/2( 1 0 ][ 1 π− − = ∑= fft – is an efficient implementation in MATLAB to calculate ak.
  • 42. DiscreteDiscrete--Time Fourier SeriesTime Fourier Series ((ExampleExample)) Find DTFS for periodic discrete-time signal x[n] with period N=30 >> x=[1,1,zeros(1,28)]; >> N=30; n=0:N-1; >> a=(1/N)*fft(x); >> real_part=real(a); >> stem(n,real_part); >> xlabel('k'); ylabel('real(a)'); >> imag_part=imag(a); >> stem(n,imag_part); >> xlabel('k'); ylabel('imag(a)');
  • 43. FrequencyFrequency ResponseResponse ((ExampleExample)) Find the frequency response of a 10-point averaging lowpass FIR filter and plot ist magnitude and phase ]9[ 10 1 ...]1[ 10 1 ][ 10 1 ][ −++−+= nxnxnxny >> b = ones(1,10)/10; a=1; >> [H omega]=freqz(b,a,100,'whole'); >> magH=abs(H); >> plot(omega, magH); grid; >> angH=angle(H); >> plot(omega, angH/pi); grid;
  • 44. >> N=256; % number of samples >> T=1/128; % sampling frequency=128Hz >> k=0:N-1; time=k*T; >> f=0.25+2*sin(2*pi*5*k*T)+1*sin(2*pi*12.5*k*T)+… +1.5*sin(2*pi*20*k*T)+0.5*sin(2*pi*35*k*T); >> plot(time,f); title('Signal sampled at 128Hz'); >> F=fft(f); >> magF=abs([F(1)/N,F(2:N/2)/(N/2)]); >> hertz=k(1:N/2)*(1/(N*T)); >> stem(hertz,magF), title('Frequency components'); ExampleExample Find the spectrum of the following signal: f=0.25+2sin(2π5k)+sin(2π12.5k)+1.5sin(2π20k)+0.5sin(2π35k)
  • 45. ExampleExample Find the frequency components of a signal buried in noise. Consider data sampled at 1000 Hz. Form a signal consisting of 50 Hz and 120 Hz sinusoids and corrupt the signal with random noise. >> t = 0:0.001:0.6; >> x = sin(2*pi*50*t) + sin(2*pi*120*t); >> y = x + 2*randn(1,length(t)); >> plot(y(1:50));
  • 46. ExampleExample ((cont‘dcont‘d)) It is difficult to identify the frequency components by studying the original signal. The discrete Fourier transform of the noisy signal using a 512-point fast Fourier transform (FFT): >> Y = fft(y,512); The power spectral density, a measurement of the energy at various frequencies, is >> Pyy = Y.*conj(Y) / 512; >> f = 1000*(0:255)/512; >> plot(f,Pyy(1:256))
  • 47. LinksLinks One-hour recorded online Webinars http://www.mathworks.com/company/events/archived_webinars.html All matlab manuals http://www.mathworks.com/access/helpdesk/help/helpdesk.html Matlab Tutorials http://www.math.ufl.edu/help/matlab-tutorial/ http://www.math.unh.edu/~mathadm/tutorial/software/matlab/