Professional Documents
Culture Documents
Basic Matlab Operations
Basic Matlab Operations
Input
Response
x[n] h[n]
0.5
(3,3,2)
0
10
11
10
0.2
0.1
0.4
0.2
0.6
0.3
0.8
1
1.2
1.4
1.6
1.8
2
0.5
1
BASIC MATLAB
0.5 0
1
0.2
0.4
OPERATIONS
0.6
0.5 0.8
0.4
0.5
FOR
MULTIPLICATION: 1
0.6
*NO.OF
COLUMNS = NO.OF(3,3,4)
ROWS
0.7
0.8
0.9
a=[1
2 3];
1
(3 COLUMNS) b=[1 2 3;4 5 0.5
6;7 8 9];
1
(3 ROWS) c=a*b
c=
30 36
0
0.5
42
0.5
1
0
0.5
1
FOR DIVISION:
*NO.OF ROWS = NO.OF COLUMNS
a=[1 2:2 1];
(2 ROWS)
b=[1 2];
(2 COLUMNS)
c= b\a
c=
0
0
0
0.5000 1.0000 0.5000
FOR ELEMENTS DIVISION:
a=[1 2 4 7];
b=[2 4 7 5 ];
c=b\a
c=
0
0
0
0
0
0
0
0
Page 1
0.1429
0
0.2857 0.5714
0
0
0
1.0000
c=a\b
c=
0
0
0
0.2857
0
0
0
0
0
0
0
0
0
0.5714 1.0000
0.7143
POWER OF ELEMENTS:
a=[1 2 3 4];
b=(a.^2)
b=1
4
16
c=(a.^3)
c=1
8 27
64
d=(a.^4)
d=1 16
81 256
& So On
ADDITION, SUBTRACTION, MULTIPLICATION, DIVISION:
a=[1 4 2 5];
a+1
ans =2
a-1
ans = 0
5
3
3
1
6
4
a*1
ans =1
a/1
ans =1
a\1
ans =
0
0
0
0.2000
COLUMNS ADDITION:
a=[2 4;5 6];
sum(a)
ans =
7
10
ROWS ADDITION:
a=[2 4;5 6];
sum(a,2)
ans =
6
11
ALL ELEMENTS ADDITION:
a=[2 4;5 6];
sum(sum(a))
ans =
17
INVERSE:
a=[2 4;5 6];
inv(a)
ans =
-0.7500 0.5000
0.6250 -0.2500
DETERMINATE:
a=[2 4;5 6];
det(a)
ans =
-8
MEAN:
Prepared by:Hayat Wali
Iqra University
Page 3
5.0000
1.4142
VARIATION:
a=[2 4;5 6];
var(a)
ans =
4.5000
2.0000
ans =
9
FOR MINIMUM ELEMENT:
a=[1 2 3 4;4 5 6 7;7 8 9 7];
min(min(a))
ans =
1
FOR SPECIFIC ROW:
a=[1 4 7;2 5 8;1 4 7];
a(2,:)
ans =
2
Page 5
SIZE OF ROWS:
a=[1 2 4 7;4 5 8 7;4 1 4 4];
size(a,1)
ans =
3
SIZE OF COLUMNS:
a=[1 2 4 7;4 5 8 7;4 1 4 4];
size(a,2)
ans =
4
ALL ZEROS WITH REFERENCE OF ANY MATRIX:
a=[1 2 4 7;4 5 8 7;4 1 4 4];
zeros(size(a))
ans =
0
0
0
0
0
0
0
0
0
0
0
0
REFRENCE ELEMENTS:
a=[1 2 4 7;4 5 8 7;4 1 4 4];
a(2:3,3:4)
ans =
8
4
7
4
PLOTING IN MATLAB
Asin(wt+ )
A=Amplitude
w=Angular frequency
t=Time
=Phase Differences
(w=2f)
(f=w/2)
x=[1 2 4 5 7];
y=[4 7 8 5 8];
plot(x,y)
8
7.5
7
Y-Axis
6.5
6
5.5
5
4.5
4
4
X-axis
x=[1 2 4 5 7];
y=[4 7 8 5 8];
plot(y,x)
7
X-Axis
4.5
5.5
6
Y=Axis
6.5
7.5
t=[pi*(0:0.02:2)];
y=sin(t);
plot(y)
Page 7
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
20
40
60
80
100
120
40
60
80
100
120
t=[pi*(0:0.02:2)];
y=sin(t+pi/2);
plot(y)
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
20
t=[pi*(0:0.02:2)];
plot(t,sin(t))
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
t=[pi*(0:0.02:2)];
plot(t,cos(t))
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
t=[pi*(0:0.02:2)];
y=3*sin(3*t+0);
plot(y)
3
-1
-2
-3
20
40
60
80
100
120
40
60
80
100
120
t=[pi*(0:0.02:2)];
y=2*sin(6*t+pi);
plot(y)
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
20
Page 9
t=[pi*(0:0.02:2)];
y=2*cos(2*t+0);
plot(y)
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
20
40
60
80
100
120
t=[pi*(0:0.02:2)];
plot(t,sin(t))
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
t=[pi*(0:0.02:2)];
plot(t,cos(t))
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
t=[pi*(0:0.02:2)];
plot(t,sinc(t))
1
0.8
0.6
0.4
0.2
-0.2
-0.4
t=[pi*(0:0.02:2)];
plot(t,exp(t))
600
500
400
300
200
100
t=[pi*(0:0.02:10)];
Prepared by:Hayat Wali
Iqra University
Page 11
plot(t,sawtooth(t))
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
15
20
25
30
35
x=[-5:0.0001:5];
y=x.^2;
plot(y)
25
20
15
10
10
12
4
x 10
x=[-5:0.0001:5];
y=x.^3;
plot(y)
150
100
50
-50
-100
-150
10
12
4
x 10
x=linspace(-5,5);
y=sinc(x);
plot(x,y)
1
0.8
0.6
0.4
0.2
-0.2
-0.4
-5
-4
-3
-2
-1
PLOTING
WITH COLOURS
t=[0:0.0001:2*pi];
plot(t,sin(t),'k')
With Black
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
plot(t,sin(t),'g')
Prepared by:Hayat Wali
Iqra University
Page 13
With Green
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
plot(t,sin(t),'b')
With Blue
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
plot(t,cos(t),'r')
With Red
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
PLOTING
WITH DESIGNS & COLOURS
x=[0:0.1:2*pi];
plot(x,sin(x),'o-')
Page 15
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
plot(x,sin(x),'g+')
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
plot(x,sin(x),'kO')
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
plot(x,cos(x),'R^')
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
plot(x,cos(x),'kd')
Prepared by:Hayat Wali
Iqra University
Page 17
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
plot(x,cos(x),'r+')
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
200
400
600
800
1000
1200
t=[0:0.001:1]';
plot([t,sin(t),cos(t)])
Page 19
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
200
400
600
800
1000
1200
t=[0:0.001:1];
plot(t,[sin(t) cos(t)])
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
x=0:0.001:2*pi;
fill(x,sin(x),'g')
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
fs=10000;
t=0:1/fs:1/5;
y=sawtooth(2*pi*5*t);
plot(t,y)
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
0.18
t=0:0.00001:10;
y=sawtooth(2*pi*3*t*3);
plot(t,y)
Prepared by:Hayat Wali
Iqra University
Page 21
0.2
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
t=0:0.00001:10;
y=sawtooth(t,.5);
plot(t,y)
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
t=0:0.0001:100;
rectpuls(t);
plot(t,rectpuls(t))
10
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
20
30
40
50
60
70
80
90
100
t=0:0.0001:100;
plot(t,square(t))
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
20
30
40
50
60
70
80
90
100
t=0:0.0001:100;
y=square(t,80);
fill(t,y,'r')
Page 23
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
20
30
40
50
60
70
80
90
100
30
40
50
60
70
80
90
100
t=0:0.0001:100;
y=square(t,100);
fill(t,y,'g')
y=square(t,40);
fill(t,y,'r')
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
20
153.5
7
3
6
2.5
153
2.5
5
2
152.5
4
1.5
1.5
3
152
1
2
151.5
0.5
1
151
0
151
0
0.5
1 151.5
1523
152.5
4
153 6
0
153.5
7
t=[0:0.1:2*pi];
y=exp(sin(t));
plotyy(t,y,t,y,'plot','stem')
153.5
7
3
6
2.5
153
2.5
5
2
152.5
4
1.5
1.5
3
152
1
2
151.5
0.5
1
151
0
151
0
0.5
1 151.5
1523
152.5
4
153 6
0
153.5
7
SUBPLOTTING
For plotting many Figures in a single figure
Prepared by:Hayat Wali
Iqra University
Page 25
x=linspace(0,2*pi);
subplot(2,2,1)
x=linspace(0,2*pi);
subplot(3,3,1)
subplot(3,3,2)
subplot(3,3,3)
subplot(3,3,4)
subplot(3,3,5)
x=linspace(0,2*pi);
subplot(3,3,1)
subplot(3,3,2)
subplot(3,3,3)
subplot(3,3,4)
subplot(3,3,5)
plot(x,sin(x))
1
0.8
0.5
0.6
0
0.4
-0.5
-1
0.2
0
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0.5
0.5
0.5
x=[-10:0.01:10];
plot(x,exp(x))
grid on
hold on
plot(x,exp(0.95*x))
plot(x,exp(0.85*x))
2.5
x 10
1.5
0.5
0
-10
-8
-6
-4
-2
10
PLOTTING WITH
COLOURS, TITLES, & LABELS
x=[-10:0.01:10];
plot(x,sin(x))
hold on
Prepared by:Hayat Wali
Iqra University
Page 27
grid on
plot(x,sin(2*x),'r--')
title('Multi sine plot')
ylabel('y-axis')
xlabel('x-axis')
legend('SinX','Sine2X')
0.8
0.6
0.4
y-axis
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-10
-8
-6
-4
-2
0
x-axis
10
SEMI-LOG PLOTTING
x=[1000 10000 100000];
y=[2 4 6];
semilogx(x,y)
6
5.5
5
4.5
4
3.5
3
2.5
2
3
10
10
10
x=[10000,10000];
y=[1000,1000];
loglog(x,y)
4
10
10
10
3
10
10
10
AXIS DEFINING
axis([0 10 0 10])
Page 29
10
9
8
7
6
5
4
3
2
1
0
10
axis([0 4 0 1])
(xlim 0 4; ylim 0 1)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0.5
1.5
2.5
3.5
axis([-10 10 0 10])
10
9
8
7
6
5
4
3
2
1
0
-10
-8
-6
-4
-2
10
PLOT TOOLS
Page 31
3D PLOTTING
x=pi*(0:0.05:1);
y=2*x;
[X,Y]=meshgrid(x,y);
plot(X(:),Y(:),'k.')
plot(X(:),Y(:),'k.')
surf(X,Y,sin(X^2))
camlight left
lighting phong
0.5
-0.5
-1
8
6
4
3
1
0
x=pi*(0:0.05:1);
y=2*x;
[X,Y]=meshgrid(x,y);
plot(X(:),Y(:),'k.')
surf(X,Y,sin(X.^2+Y))
0.5
-0.5
-1
8
6
4
3
1
0
x=pi*(0:0.05:1);
y=2*x;
[X,Y]=meshgrid(x,y);
plot(X(:),Y(:),'k.')
surf(x,y,sin(X))
1
0.8
0.6
0.4
0.2
0
8
6
4
3
4
2
1
0
x=pi*(0:0.05:1);
y=2*x;
[X,Y]=meshgrid(x,y);
plot(X(:),Y(:),'k.')
Page 33
surf(x,y,cos(X.^2))
0.5
-0.5
-1
8
6
4
3
4
2
1
0
[X,Y]=meshgrid(-8:0.5:8);
R=sqrt(X.^2+Y.^2)+eps;
Z=sin(R)./R;
mesh(X,Y,Z)
surf(X,Y,Z)
colormap gray
0.5
-0.5
10
5
10
5
-5
-5
-10
-10
[X,Y]=meshgrid(-8:0.5:8);
R=sqrt(X.^2+Y.^2)+eps;
Z=sin(R)./R;
mesh(X,Y,Z)
surf(X,Y,Z)
colormap hsv
0.5
-0.5
10
5
10
5
-5
-5
-10
-10
[X,Y]=meshgrid(-8:0.5:8);
R=sqrt(X.^2+Y.^2)+eps;
Z=sin(R)./R;
mesh(X,Y,Z)
surf(X,Y,Z)
colormap copper
0.5
-0.5
10
5
10
5
-5
-5
-10
-10
x=[7 3 9 2 11 15 20 7 5 9];
Prepared by:Hayat Wali
Iqra University
Page 35
bar([0:length(x)-1],x)
th=[0:0.0001:2*pi];
rho=2*sin(th).*cos(th);
polar(th,rho)
90
120
60
0.8
0.6
150
30
0.4
0.2
180
210
330
240
300
270
x=rand([1 100]);
hist(x,10);
15
10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
NUMERICAL ANALYSIS
syms t
f=@(t,y)2.*y-1
f=
@(t,y)2.*y-1
ode45(f,[0,1],1)
Page 37
4.5
3.5
2.5
1.5
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
f=@(t,y)2.*y^2-1
ode45(f,[0,1],1)
14
2.5
x 10
1.5
0.5
0.1
f=@(t,y)2.*y^3-1;
ode45(f,[-1,1],-1)
0.2
0.3
0.4
0.5
0.6
0.7
x 10
-2
-4
-6
-8
-10
-12
-14
-1
-0.95
-0.9
-0.85
-0.8
-0.75
f=@(t,y)2.*y-23;
ode45(f,[0,1],1)
10
0
-10
-20
-30
-40
-50
-60
-70
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.3
0.4
0.5
0.6
0.7
0.8
0.9
f=@(t,y)2.*y-2;
ode45(f,[0,1],1)
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
0.1
0.2
Page 39
f=@(t,y)2.*y-2;
ode45(f,[-1,1],-1)
0
-20
-40
-60
-80
-100
-120
-1
-0.8
-0.6
-0.4
-0.2
0.2
0.4
0.6
0.8
-0.4
-0.2
0.2
0.4
0.6
0.8
f=@(t,y)2.*y-23;
ode45(f,[-1,1],1)
100
-100
-200
-300
-400
-500
-600
-1
-0.8
-0.6
f=@(t,y)2.*y-3;
ode45(f,[-1,1],1)
-5
-10
-15
-20
-25
-30
-1
-0.8
-0.6
-0.4
-0.2
0.2
0.4
0.6
0.8
DIFFERENTIATION
Single Derivative:
syms x
g=sin(x);
diff(g)
ans =
cos(x)
d(g)/dx=d(sinx)/dx=Cosx
diff(x)
ans =
1
d(x)/dx=1
Single Derivative:
syms x
g=sin(x);
diff(g,x)
g=sin(x)
d(g)/dx=d(sinx)/dx=Cosx
ans =
cos(x)
g=cos(x);
diff(g,x)
ans =
-sin(x)
Prepared by:Hayat Wali
Iqra University
Page 41
cosx=cos(2.1)
Double Derivative:
syms x
g=sin(x);
diff(g,x,2)
g=sin(x)
d(g)/dx=d(sinx)/dx
ans =
-sin(x)
ans =
cos(x)
syms x
diff(sin(x),x,2)
ans =
-sin(x)
syms x
diff(sin(x),x,3)
ans =
-cos(x)
syms x
diff(sin(x),x,4)
ans =
sin(x)
SUBSTITUTING VALUES
This is the shortcut command for substituting values in any function.
Subs(diff(f(x)),x,?)
syms x
syms x
diff(tan(x))
ans =
1+tan(x)^2
(Differentiate Tanx)
subs(ans,x,2)
ans =
5.7744
syms x
subs(diff(tan(x)),x,2)
ans =
5.7744
syms x
subs(diff(sin(x)),x,1)
ans =
0.5403
syms x
subs(diff(cos(x)),x,36)
ans =
0.9918
Prepared by:Hayat Wali
Iqra University
Page 43
syms x
diff(tan(x^6-3*x+5))
ans =
(1+tan(x^6-3*x+5)^2)*(6*x^5-3)
(Differentiate Tan(x^6-3*x+5))
subs(ans,x,3/2)
ans =
69.9149
subs(diff(tan(x^6-3*x+5)),x,3/2)
ans =
69.9149
INTEGERATION
syms x
int(sin(x),x)
ans =
(Integrate sin(x) )
-cos(x)
syms x
int(x*sin(x),x)
ans =
(Integrate xsin(x))
sin(x)-x*cos(x)
DOUBLE INTEGERATION:
double(int(sin(x^5+x^3),x,0,pi/2))
sin(x^5+x^3) ) & (0-/2) is limit
ans =
(Integrate
0.2910
quad8(inline(sin(x^5+x^3)'),0,pi/2)
/2) is limit
ans =
0.2910
quad8(inline(sin(x^5+x^3)'),0,pi/2)
/2) is limit
ans =
0.2910
RELATIONAL OPERATION
x=[1 2;2 3;5 6]
x=
1
2
5
2
3
6
x>2
ans =
0
0
1
x>1
ans =
0
1
1
3>1
ans =
1
3<1
Page 45
ans =
0
3<=6
ans =
1
3==4
ans =
0
3<=3
ans =
1
POSITION/REFERENCE LOCATOR
COLOUMN WISE
x=[1 2;2 3;5 6]
x=
1
2
5
2
3
6
x([2])
ans =
2
x([2 3 4])
ans =
2
x(2)
ans =
2
x(3)
ans =
5
x(x>2)
ans =
5
3
6
x(x>1)
ans =
2
5
2
3
6
POLYNOMIAL EQUATIONS
Polynomial equations are derived from word Poly means many.
We are here to find out the slop of the equations.
E.g.:( ax^3+bx^2+cx+d )
x=[1:2:20];
y=[2:2:20];
x=x';
y=y';
fit=polyfit(x,y,1)
fit =
1.0000
1.0000
plot(x,y,'o',x,fit(1)*x+fit(2))
22
20
18
16
14
12
10
8
6
4
2
10
12
14
16
18
20
Page 47
If roots are:
x= +3
x= -1
We use the command POLY to converts the roots into polynomial.
Manually:
In MATLAB
E.g.: (x-3)(x+1)
x2 + x - 3x - 3= 0
x2 -2x -3 = 0
a=[3;-1]
poly(a)
ans =
1 -2 -3
x2 -2x -3 = 0
If equation is:
x2 -2x -3 = 0
We use the command ROOTS to find out the roots of the equation:
Manually:
x2-2x-3 = 0
x2+x -3x-3 = 0
(x-3)(x+1)=0
x= +3
x= -1
In MATLAB
p=[1 -2 -3];
roots(p)
ans =
+3
-1
OR
roots([1 -2 -3])
ans =
+3
-1
v=[1 0 6 -3];
polyval(v,2)
ans =
17
Evaluating by x=3
v=[1 0 6 -3];
polyval(v,3)
ans =
42
MATRICES
Manual
IN MATLAB
A =[2 3;1 4]
A=
A^-1
2
ans =
Inverse of A:
0.8000 -0.6000
-0.2000
Adj A = 4
-3
-1
Page 49
0.4000
|A| = (4x2)-(-1x-3)
|A| = 8-3
|A| = 5
A-1 =
A-1 =
-3-1
25
0.8000 -0.6000
-0.2000 0.4000
Manual
IN MATLAB
A=[2 3;1 4]
A=
B=[9;3];
X=A^-1*B
X=
B=[9;3]
5.4000
B=
-0.6000
9
3
X =[X1;X2]
X=
X1
X2
AX=B
X=A-1 B
X=
Page 51
X1= 5.4000
X2= -0.6000
PROGRAMMING IN MATLAB
Programming is defined as list of instructions.
We create M-file for algorithm of any program.
F5 is used as a shortcut key to run a program.
Example:
Assigning Comments:
Page 53
Solution is:
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
Page 55
a=
1 4
a=
1 4
a=
1 4
a=
1 4
a=
1 4
a=
1 4
a=
1 4
a=
1 4
9
9
16
16
25
16
25
36
16
25
36
49
16
25
36
49
64
16
25
36
49
64
81
16
25
36
49
64
81 100
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
10
By pressing 2:
Page 57
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
10
10
By pressing 3:
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
By pressing 4:
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
10
Page 59
USING MATLAB
CREATING SIGNALS (IN DISCREATE TIME):
Impulse function:
x=[1:11];
y=[1 zeros(1,10)];
stem(x,y)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
11
10
11
Page 61
x=[1:10];
y=[0,0 ones(1,8)];
stem(x,y)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
10
1200
1000
800
600
400
200
10
10
20
30
40
50
60
70
80
90
100
x 10
1.5
0.5
10
Page 63
10
CONVOLUTION
Method #1(On command window)
X[n] =0.5n u[n]
H[n]=1
Y[n]=?
Input:
n=0:10;
x=0.5.^n;
stem(n,x)
Impulse Response:
h=ones(1,5);
h=[h ones(1,5)];
stem(h)
Convolution:
y=conv(x,h);
stem(y)
0n4
LAPLACE TRANSFORM
The laplace transform of a signal x(t),
S2-1 = 0
S2=1
S= 1
S2+2S-3=0
S2+3S-S-3 = 0
S (S +3)-1(S +3) = 0
Prepared by:Hayat Wali
Iqra University
Page 65
(S -1)( S +3) = 0
S=1;S=-3
IN MATLAB:
For Equation:
For Roots:
o=[1 0 -1];
i=[1 2 -3];
Z1=roots(o)
Z1 =
1
-1
P1=roots(i)
P1 =
-3
1
h=tf(o,i)
Transfer function:
s^2 - 1
------------s^2 + 2 s - 3
Output
Input
Transfer function
Zeros
Poles
S-plane Map
Pole-Zero Map
1
0.8
0.6
Imaginary Axis
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-3
-2.5
-2
-1.5
-1
Real Axis
Output
Input
Transfer function
Zeros
Poles
Page 67
-0.5
0.5
pzmap(Z1,P1)
sgrid
S-plane Map
Pole-Zero Map
1
0.92
0.8
0.86
0.76
0.58
0.35
0.96
0.6
0.984
Imaginary Axis
0.4
0.2
0.996
3
0
-0.2
2.5
1.5
0.5
0.996
-0.4
0.984
-0.6
-0.8
0.96
0.92
-1
-3
-2.5
0.86
-2
-1.5
0.76
0.58
-1
Real Axis
0.35
-0.5
0.5
For Noise:
t=0:1/8192:1;
x=cos(2*pi*400*t);
soundsc(x,8000)
noise=randn(8192,1);
soundsc(noise,8000)
SIMULINK
X(t)=Acos(wt+)
A Gain
Cos Trigonometric function
W Frequency
T Time
Phase difference
dxdy=(-2x+1) dx
Page 69
dx=-2x+1dx
X=-2x22+x+c
X=-x2+x+c
X(k)=e(k-3)+2.2x(k-1)-1.57x(k-2)+0.3x(k-3)
For 0k8
Page 71