MATLAB Programs For Beginners. | Abhi Sharma
-
Upload
abee-sharma -
Category
Technology
-
view
718 -
download
1
description
Transcript of MATLAB Programs For Beginners. | Abhi Sharma
![Page 1: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/1.jpg)
SRI SAI INSTITUTE OF ENGG. AND TECHNOLOGY
MATLAB PRACTICAL FILE
DSP ECE - 316
Submitted By:
![Page 2: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/2.jpg)
TABLE OF CONTENTS
Contents
InroductionToMATLAB_____________________________________________________________________1
ProgramForImpulseFunction_____________________________________________________________4
ProgramForUnitStepFunction____________________________________________________________6
ProgramForUnitRampFunction__________________________________________________________8
ProgramForExponentialFunction______________________________________________________10
ProgramForRealValueFunction________________________________________________________16
ProgramForShiftingFunction____________________________________________________________14
ProgramForAdditionFunction___________________________________________________________16
ProgramForMultiplicationFunction____________________________________________________18
ProgramForConvolutionFunction______________________________________________________20
ProgramForFoldingFunction____________________________________________________________23
![Page 3: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/3.jpg)
1
WHATISMATLAB?“ANINTRODUCTION”
• ItstandsforMATrixLAbORATORY
• ItisdevelopedbyTheMathworksInc.
• Itisaninteractive,integrated,environment
• Fornumericalcomputations
• Forsymboliccomputations
• Forscientificvisualizations
• Itisahighlevelprogramminglanguage
• Programrunsininterpreted,asopposedtocompiled,mode
• MATLAB is a high level technical computing language and interactive environment for
algorithmdevelopment,datavisualization,dataanalysisandnumericcomputation. Usingthe MATLAB product, you can solve technical computing problems faster than the
traditionalprogramminglanguagessuchasC,C++andFORTRAN.
• YoucanuseMATLABinawiderangeofapplications,includingsignalandimageprocessing,communication,controldesign,testandmeasurement,financialmodelingandanalysis,and
computationalbiology.Addontoolboxes(collectionofspecialpurposeMATLABfunctions,available separately) extend the MATLAB environment to solve particular classes of
problemsintheseapplicationareas.
• MATLABprovidesanumberof features fordocumentingandsharingyourwork.Youcanintegrate yourMATLAB codewith other languages and applications, and distribute your
MATLABalgorithmsandapplications.
![Page 4: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/4.jpg)
2
Characterstics Of MATLAB:
• ProgrammingLanguageBased(principally)OnMatrices.
• SlowcomparedwithFORTRANorCbecauseitisaninterpretedlanguage,i.enotpre‐compiled.Avoidforloops,insteadusevectorformwheneverpossible.
• Automaticmemorymanagement,i.eyoudon’thavetodeclarearraysinadvance.
• Intuitive,easytouse.
• Compact(arrayhandlingisFortran90‐like).
• ShorterprogramdevelopmenttimethantraditionalprogramminglanguagessuchasFORTRANandC.
• CanbeconvertedintoCcodeviaMATLABcompilerforbetterefficiency.
• Manyapplications‐specifictoolboxesavailable.
• CoupledwithMapleforsymboliccomputations.
• Onshared‐memoryparallelcomputerssuchastheSGIOrigin2000,certainoperations
processedinparallelautonomouslywhencomputationloadwarrants.
KEY FEATURES:-
• Highlevellanguagefortechnicalcomputing.
• Developmentenvironmentformanagingcode,files,anddata.
• Interactivetoolsforiterativeexploration,designandproblemsolving.
• Mathematicalfunctionsforlinearalgebra,statistics,Fourieranalysis,filtering,optimization,andnumericalintegration
• 2‐Dand3‐Dgraphicalfunctionsforvisualizingdata.
• Toolsforbuildingcustomgraphicaluserinterfaces.
• FunctionsforintegratingMATLABbasedalgorithmwithexternalapplicationandlanguages,
suchasC,C++,FORTRAN,Java,andMicrosoftExcel.
![Page 5: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/5.jpg)
3
EXAMPLES:-
• Matrixcomputationandlinearalgebra.
• Solvingnonlinearequation.
• Numericalsolutionofdifferentialequation.
• Mathematicaloptimization.
• Statisticalanddataanalysis.
• SignalProcessing.
• Modelingofdynamicalsystems.
• Solvingpartialdifferentialequation.
• SimulationofEngg.Systems.
USESINENGG.COMPANIES:‐
• Numericalanalysis
• Signalandsystem.
• Modelingofdynamicalsystems.
• Automaticcontrol.
BASICCOURSES:‐
• Automaticcontroladvancedcourse.
• Hybridandembedded.
• Controlsystem.
• Chemicalprocesscontrol.
• Controlprocesscontrol.
• Signaltheory.
• Digitalsignalprocessing.
• Adaptivesignalprocessing.
• Signalprocessingproject.
• Communicationtheory.
• Advancecommunicationtheory.
![Page 6: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/6.jpg)
4
Program - 1
To Develop Elementary Signal For Impulse Function
Program:
a=[‐2;1;2]
b=[zeros(1,2),ones(1,1),zeros(1,2)]
stem(a,b)
xlabel(‘a‐‐‐‐>’)
ylabel(‘amp‐‐‐>’)
Result:
a= ‐2 ‐1 0 1 2
b= 0 0 1 0 0
![Page 7: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/7.jpg)
5
Graph For Impulse Function:
![Page 8: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/8.jpg)
6
Program - 2
To Develop Elementary Signal For Unit Step Function
Program:
n=input(’enter the value of n’)
a=[1:1:n]
b=[ones,n]
subplotes
stem(a,b)
xlabel(‘n…..>’)
ylabel(‘amplitude’)
Result of unit step function:
Enter the value of n
n=5
a=0 1 2 3 4
b= 1 1 1 1 1
![Page 9: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/9.jpg)
7
Graph For Unit Step Function:
![Page 10: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/10.jpg)
8
Program - 3
To Develop Elementary Signal For Unit Ramp Function
Program:
a=[2:1:8]
b=[0;1;6]
subplot
stem(a,b)
xlabel(‘n.’)
ylabel(‘amp….’)
Result of unit ramp function:
a=2 3 4 5 6 7 8
b= 0 1 2 3 4 5 6
![Page 11: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/11.jpg)
9
Graph For Unit Ramp Function:
![Page 12: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/12.jpg)
10
Program - 4
To Develop Exponential Function Of (Given) Sequence
Program:
n=input(‘enter the value of n’)
a=input(‘enter the value of a’)
t=[0:1:n]
y=exp(a*t)
subplot
stem(t,y)
xlabel(‘a’)
ylabel(‘n’)
Result of exponential: Enter the value of n10
n= 10
enter the value of a0.5
a= 0.5000
t=0 1 2 3 4 5 6 7 8 9 10
y=columns 1 through 10
1.0000 1.6487 2.7183 4.4817 7.3891 12.1825 20.0855 33.1155 54.5982 90.0171
Column11
148.4132
![Page 13: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/13.jpg)
11
Graph For Exponential Function:
![Page 14: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/14.jpg)
12
Program - 5
To Develop Elementary Signal For Real Value
Program:
n=[0,1,2,3,4,5]
a=[0.5]
y=a.^n
subplot
stem(n,y)
xlabel(‘n…..’)
ylabel(‘a’)
Result of Real Value No.:
n= 0 1 2 3 4 5
a= 0.5000
y = 1.0000 0.5000 0.2500 0.1250 0.0625 0.0313
![Page 15: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/15.jpg)
13
Graph For Real Value Function:
![Page 16: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/16.jpg)
14
Program - 6
To Develop Elementary Signal For Shifting Program:
a=[‐3:1:3]
b=[1.2.3.2.1.1.2]
subplot(3,1,1)
stem(a,b)
xlabel(‘n‐‐‐‐>’)
ylabel(‘amp‐‐‐>’)
a=‐a
subplot(3,1,2)
stem(a,b)
xlabel(‘n‐‐‐‐>’)
ylabel(‘amp‐‐‐>’)
Result:
a = ‐3 ‐2 ‐1 0 1 2 3
b = 1 2 3 2 1 1 2
a = 3 2 1 0 ‐1 ‐2 ‐3
![Page 17: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/17.jpg)
15
Graph For Shifting Function:
![Page 18: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/18.jpg)
16
Program - 7
To Develop Elementary Signal For Addition Of Two Sequences
Program:
n=[‐3:1:3] b=[2,3,0,1,3,2,1] subplot(5,1,1) stem(n,b) xlabel('n….>') ylabel('amplitude') title('input of signal b') a=[3,4,5,6,7,8,9] subplot(5,1,3) stem(n,b) ylabel('amplitude') title('input of signal a') z=b+a subplot(5,1,5) stem(n,a) xlabel('n….>') ylabel('amplitude') title('addition of two signal is z(n)')
Result of Addition:
2 3 0 1 3 2 1
a = 3 4 5 6 7 8 9
z = 5 7 5 7 10 10 10
![Page 19: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/19.jpg)
17
Graph For Addition Function:
![Page 20: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/20.jpg)
18
Program - 8
To Develop Elementary Signal For Multiplication Of Two Sequences
Program:
n=[‐2:1:3] x=[1,2,3,4,5,6] subplot(3,1,1) stem(n,x) xlabel('n‐‐‐‐>') ylabel('amp‐‐‐>') y=[2] z=(x*y) subplot(3,1,2) stem(n,z) xlabel('n‐‐‐‐>') ylabel('amp‐‐‐>')
Result:
n = ‐2 ‐1 0 1 2 3
x = 1 2 3 4 5 6
y = 2
z = 2 4 6 8 10 12
![Page 21: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/21.jpg)
19
Graph For Multiplication Function:
![Page 22: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/22.jpg)
20
Program - 9
To Develop The Elementary Signal For Convolution Of Two Sequences
Program:
X=input(‘enter the value of x’)
h=input(‘enter the value of h’)
y=conv(x,h)
subplot(3,1,1)
stem(x)
xlabel(‘n….>’)
ylabel(‘amplitude….>’)
subplot(3,1,2)
stem(h)
xlabel(‘n….>’)
ylabel(‘amplitude….>’)
subplot(3,1,3)
stem(y)
xlabel(‘n….>’)
ylabel(‘amplitude….>’)
![Page 23: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/23.jpg)
21
Result of convolution:
Enter the sequence of x[1,2]
X=1 2
Enter the sequence of h[1,2,3,4]
h = 1 2 3 4
y = 1 4 7 10 8
![Page 24: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/24.jpg)
22
Graph For Convolution Function:
![Page 25: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/25.jpg)
23
Program - 10
To Develop Elementary Signal For Folding
Program:
a=[‐3:1:3]
b=[1,2,3,2,1,1,2]
subplot(3,1,1)
stem(a,b)
xlabel(‘n….. >’)
ylabel(‘amp…..>’)
a= ‐a
subplot(3,1,2)
stem(a,b)
xlabel(‘n…..>’)
ylabel(‘amp…..>’)
Result of Folding:
a= ‐3 ‐2 ‐1 0 1 2 3
b= 1 2 3 2 1 1 2
a= 3 2 1 0 ‐1 ‐2 ‐3
![Page 26: MATLAB Programs For Beginners. | Abhi Sharma](https://reader034.fdocuments.us/reader034/viewer/2022050804/54003b648d7f72ba408b467f/html5/thumbnails/26.jpg)
24
Graph For Folding Function: