MATLAB Programs For Beginners. - Abhi Sharma
MATLAB Programs For Beginners. - Abhi Sharma
AND TECHNOLOGY
DSP
ECE - 316
Submitted By:
Abhishek Sharma
ECE - 6th Sem.
TABLEOFCONTENTS
Contents
Inroduction To MATLAB _____________________________________________________________________ 1
Program For Impulse Function _____________________________________________________________ 4
Program For Unit Step Function ____________________________________________________________ 6
Program For Unit Ramp Function __________________________________________________________ 8
Program For Exponential Function ______________________________________________________ 10
Program For Real Value Function ________________________________________________________ 16
Program For Shifting Function ____________________________________________________________ 14
Program For Addition Function ___________________________________________________________ 16
Program For Multiplication Function ____________________________________________________ 18
Program For Convolution Function ______________________________________________________ 20
Program For Folding Function ____________________________________________________________ 23
WHAT IS MATLAB?
AN INTRODUCTION
MATLAB is a high level technical computing language and interactive environment for
algorithm development, data visualization, data analysis and numeric computation. Using
the MATLAB product, you can solve technical computing problems faster than the
traditional programming languages such as C, C++ and FORTRAN.
You can use MATLAB in a wide range of applications, including signal and image processing,
communication, control design, test and measurement, financial modeling and analysis, and
computational biology. Add on toolboxes(collection of special purpose MATLAB functions,
available separately) extend the MATLAB environment to solve particular classes of
problems in these application areas.
MATLAB provides a number of features for documenting and sharing your work. You can
integrate your MATLAB code with other languages and applications, and distribute your
MATLAB algorithms and applications.
Characterstics Of MATLAB:
Slow compared with FORTRAN or C because it is an interpreted language, i.e not pre
compiled. Avoid for loops, instead use vector form whenever possible.
Automatic memory management, i.e you dont have to declare arrays in advance.
Can be converted into C code via MATLAB compiler for better efficiency.
KEY FEATURES:
Mathematical functions for linear algebra, statistics, Fourier analysis, filtering, optimization,
and numerical integration
Functions for integrating MATLAB based algorithm with external application and languages,
such as C, C++, FORTRAN, Java, and Microsoft Excel.
EXAMPLES:
Mathematical optimization.
Signal Processing.
Numerical analysis
Automatic control.
BASIC COURSES:
Control system.
Signal theory.
Communication theory.
Program - 1
ToDevelopElementarySignalForImpulseFunction
Program:
a=[2;1;2]
b=[zeros(1,2),ones(1,1),zeros(1,2)]
stem(a,b)
xlabel(a>)
ylabel(amp>)
Result:
a=21012
b=00100
GraphForImpulseFunction:
Program - 2
ToDevelopElementarySignalForUnitStepFunction
Program:
n=input(enterthevalueofn)
a=[1:1:n]
b=[ones,n]
subplotes
stem(a,b)
xlabel(n..>)
ylabel(amplitude)
Resultofunitstepfunction:
Enterthevalueofn
n=5
a=01234
b=11111
GraphForUnitStepFunction:
Program - 3
ToDevelopElementarySignalForUnitRampFunction
Program:
a=[2:1:8]
b=[0;1;6]
subplot
stem(a,b)
xlabel(n.)
ylabel(amp.)
Resultofunitrampfunction:
a=2345678
b=0123456
GraphForUnitRampFunction:
Program - 4
ToDevelopExponentialFunctionOf(Given)Sequence
Program:
n=input(enterthevalueofn)
a=input(enterthevalueofa)
t=[0:1:n]
y=exp(a*t)
subplot
stem(t,y)
xlabel(a)
ylabel(n)
Resultofexponential:
Enterthevalueofn10
n=10
enterthevalueofa0.5
a=0.5000
t=012345678910
y=columns1through10
1.00001.64872.71834.48177.389112.182520.085533.115554.598290.0171
Column11
148.4132
10
GraphForExponentialFunction:
11
Program - 5
ToDevelopElementarySignalForRealValue
Program:
n=[0,1,2,3,4,5]
a=[0.5]
y=a.^n
subplot
stem(n,y)
xlabel(n..)
ylabel(a)
ResultofRealValueNo.:
n=012345
a=0.5000
y=1.00000.50000.25000.12500.06250.0313
12
GraphForRealValueFunction:
13
Program - 6
ToDevelopElementarySignalForShiftingProgram:
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=3210123
b=1232112
a=3210123
14
GraphForShiftingFunction:
15
Program - 7
ToDevelopElementarySignalForAdditionOfTwo
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('inputofsignalb')
a=[3,4,5,6,7,8,9]
subplot(5,1,3)
stem(n,b)
ylabel('amplitude')
title('inputofsignala')
z=b+a
subplot(5,1,5)
stem(n,a)
xlabel('n.>')
ylabel('amplitude')
title('additionoftwosignalisz(n)')
ResultofAddition:
2301321
a=3456789
z=5757101010
16
GraphForAdditionFunction:
17
Program - 8
ToDevelopElementarySignalForMultiplicationOfTwo
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=210123
x=123456
y=2
z=24681012
18
GraphForMultiplicationFunction:
19
Program - 9
ToDevelopTheElementarySignalForConvolutionOf
TwoSequences
Program:
X=input(enterthevalueofx)
h=input(enterthevalueofh)
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.>)
20
Resultofconvolution:
Enterthesequenceofx[1,2]
X=12
Enterthesequenceofh[1,2,3,4]
h=1234
y=147108
21
GraphForConvolutionFunction:
22
Program - 10
ToDevelopElementarySignalForFolding
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..>)
ResultofFolding:
a=3210123
b=1232112
a=3210123
23
GraphForFoldingFunction:
24