MATLAB PROJECT Name : Mohamed kamal Aed Name : Mohamed

MATLAB PROJECT
Name : Mohamed kamal Aed
Sec : 6
B.N. 23
Name : Mohamed Tarek
Sec : 6
B.N.7
Prof. / Abdellatief Elshafei
Solution
(Q1-a)
x1= -1:0.001:0;
y1= zeros(1,length(x1));
x2= 0:0.001:3;
y2= 0.7.*exp(-x2).*cos(x2);
x3= 3:0.001:6;
y3= zeros(1,length(x3));
x= [x1 x2 x3];
y= [y1 y2 y3];
plot(x,y);
xlabel('time sec'); ylabel('x(t)');
(Q1-b)
x1= [-1 0 1];
y1= ones(1,3);
x2= [1 2];
y2=x2;
x3= [2 3 4];
y3= -2*x3+6;
x4= [4,5];
y42*x4-10;
x= [x1 x2 x3 x4];
y= [y1 y2 y3 y4];
plot(x,y);
axis([-1 5 -3 3]);
xlabel('time sec');
ylabel('x(t)');
(Q1-c)
n= -5:17;
x1= ones(1,length(n));
y1= ((0.7).^n).*x1;
stem(n,y1);
(Q1-d)
n= -5:17;
x= ((.85).^n).*(sin(pi.*n/3)+cos(pi.*n/3));
stem(n,x);
Solution
(Q2-a)
π‘₯(𝑑) = π‘π‘œπ‘ 2πœ‹π‘‘ + 𝑠𝑖𝑛7πœ‹π‘‘
π‘₯(𝑑) = π‘₯1 (𝑑) + π‘₯2 (𝑑)
The period of π‘₯1 (𝑑) is T1 =
The period of π‘₯2 (𝑑) is T2 =
2πœ‹
2πœ‹
2πœ‹
7πœ‹
=1
=
2
7
t= -5:0.001:5;
x= cos(2*pi*t)+sin(7*pi*t);
plot(t,x);
axis([-5 5 -1 1]);
xlabel('t'); ylabel('x(t)');
∴ the period of π‘₯(𝑑) is
𝑇1
𝑇2
∴ π‘₯(𝑑) is periodic function .
=𝑇=
7
2
(Q2-b)
π‘₯(𝑑) = π‘π‘œπ‘ 2πœ‹π‘‘ + 𝑠𝑖𝑛3𝑑
π‘₯(𝑑) = π‘₯1 (𝑑) + π‘₯2 (𝑑)
2πœ‹
∴ the period of π‘₯(𝑑) is
The period of π‘₯1 (𝑑) is T1 = 2πœ‹ = 1
The period of π‘₯2 (𝑑) is T2 =
2πœ‹
3
𝑇1
𝑇2
=𝑇=
∴ π‘₯(𝑑) isn’t periodic function .
t= -10:0.001:10;
x= cos(2*pi*t)+sin(3*t);
plot(t,x);
axis([-10 10 -3 3]);
xlabel('t'); ylabel('x(t)');
3
2
x(t)
1
0
-1
-2
-3
-10
-8
-6
-4
-2
0
t
2
4
6
8
10
3
2πœ‹
(Q2-c)
T (period time) =
2πœ‹
3
not cop rime ∴ not periodic fn
n= -5:5;
x= cos(3.*n);
stem(n,x);
axis([-6 6 -2 5]);
xlabel('n'); ylabel('x');
5
4
3
x
2
1
0
-1
-2
-6
-4
-2
0
n
2
4
6
(Q2-d)
2πœ‹
T (period time) = 2πœ‹
⁄3
cop rime ∴ periodic fn
=3
n= -5:5;
x= cos(2*pi.*n/3);
stem(n,x);
axis([-6 6 -2 5]);
xlabel('n'); ylabel('x');
5
4
3
x
2
1
0
-1
-2
-6
-4
-2
0
n
2
4
6
Solution
(Q3-a)
By Appling Laplace on the circuit ,
𝑖(𝑠) =
1βˆ’ 𝑒 βˆ’π‘ 
𝑠
𝑣(𝑠) = 𝑖(𝑠) βˆ— ( 𝑅 β‹°β‹° 𝑠𝐿)
𝑣(𝑠) =
𝑣(𝑠) =
1βˆ’ 𝑒 βˆ’π‘ 
𝑠
βˆ—
𝑅𝐿𝑠
𝑅+𝐿𝑠
𝑅𝐿(1βˆ’ 𝑒 βˆ’π‘  )
𝑅+𝐿𝑆
𝑅
𝑣(𝑠) = 𝑅
𝐿
+𝑠
βˆ’
=
𝑅𝐿
𝑅+𝐿𝑆
βˆ’
𝑅𝐿 𝑒 βˆ’π‘ 
𝑅+𝐿𝑠
𝑅 𝑒 βˆ’π‘ 
𝑅
+𝑠
𝐿
β„’ βˆ’1 𝑣(𝑠) = 𝑣(𝑑) =
𝑅
𝑅
𝑦(𝑑) = 𝑅 𝑒 βˆ’ 𝐿 𝑑 𝑒(𝑑) βˆ’ 𝑅 𝑒 βˆ’ 𝐿 (π‘‘βˆ’1) 𝑒(𝑑 βˆ’ 1) ↳𝑅=1 & 𝐿=1
𝑦(𝑑) = 𝑒 βˆ’π‘‘ 𝑒(𝑑) βˆ’ 𝑒 βˆ’(π‘‘βˆ’1) 𝑒(𝑑 βˆ’ 1)
(Q3-b)
𝑖(𝑑) =
𝑑𝑖(𝑑)
𝑑𝑑
1
𝑅
=
𝑑𝑦(𝑑)
𝑑𝑑
𝑦(𝑑) +
1 𝑑𝑦(𝑑)
𝑅
𝑑𝑑
+
+ 𝑦(𝑑) =
𝑑
1
βˆ«βˆ’ 𝑦(πœ†) π‘‘πœ†
𝐿
1
𝐿
𝑦(𝑑) ↳𝑅=1 & 𝐿=1
𝑑𝑖(𝑑)
𝑑𝑑
𝐡𝑦 πΈπ‘’π‘™π‘’π‘Ÿ β€² 𝑠 π‘Žπ‘π‘π‘Ÿπ‘œπ‘₯π‘–π‘šπ‘Žπ‘‘π‘–π‘œπ‘› π‘œπ‘“ π‘‘β„Žπ‘’ π‘‘π‘’π‘Ÿπ‘–π‘£π‘Žπ‘‘π‘–π‘£π‘’
𝑦[𝑛+1]βˆ’ 𝑦[𝑛]
𝑇
+ 𝑦[𝑛] =
𝑖[𝑛+1]βˆ’π‘–[𝑛]
𝑇
𝑖[𝑛] = 𝑒[𝑛] βˆ’ 𝑒[𝑛 βˆ’ 1]
𝑑𝑖[𝑛]
𝑑𝑛
=
𝑦[𝑛] =
𝑒[𝑛]βˆ’ 2𝑒[𝑛]+ 𝑒[π‘›βˆ’2]
𝑇
1
𝑇+1
[ 𝑦[𝑛 βˆ’ 1] + 𝑒[𝑛] βˆ’ 2𝑒[𝑛 βˆ’ 1] + 𝑒[𝑛 βˆ’ 2] ]
(Q3-c)
For exact solution
t1=0:0.001:1;
y1=exp(-t1);
t2=1:0.001:5;
y2=exp(-t2)-exp(-(t2-1));
t=[t1 t2]; y=[y1 y2];
plot(t,y);
xlabel('t');
ylabel('y(t)');
1
0.8
0.6
0.4
y(t)
0.2
0
-0.2
-0.4
-0.6
-0.8
0
0.5
1
1.5
2
2.5
t
3
3.5
4
4.5
5
For approximation solution
function y = recur(a,b,n,x,x0,y0)
N = length(a);
M = length(b)-1;
x = [x0 x];
y = [y0 zeros(1,length(n))];
a1 = a(length(a):-1:1);
b1 = b(length(b):-1:1);
for i=N+1:N+length(n);
y(i) = -a1*y(i-N:i-1)'+ b1*x(i-N:i-N+M)';
end
y = y(N+1:N+length(n));
stem(n,y);
Solution
(Q4-1)
x=ones(1,26);
y(1)=0;
for i=2:length(x)
y(i)=(((0.7)^i)*y(i-1))+x(i);
end
stem(y)
1.4
1.2
1
0.8
0.6
0.4
0.2
0
0
5
10
15
20
25
30
(Q4-2)
x=3*ones(1,26);
y(1)=0;
for i=2:length(x)
y(i)=(((0.7)^i)*y(i-1))+x(i);
end
stem(y)
4.5
4
3.5
3
2.5
2
1.5
1
0.5
0
0
5
10
15
20
25
30
(Q4-3)
x1=ones(1,26);
x2=3*ones(1,26);
y3(1)=0;
for i=2:length(x1)
x3(i)=x1(i)+2*x2(i);
y3(i)=(((0.7)^i)*y3(i-1))+x3(i);
end
stem(y3);
10
9
8
7
6
5
4
3
2
1
0
0
5
10
15
20
25
30
(Q4-4)
x=[ ones(3,26)];
y(1,2)=0;
for i=2:length(x)
y(i)=(((0.7) ^i)*y(i-1))+x(i);
end
stem(y)
1.4
1.2
1
0.8
0.6
0.4
0.2
0
0
5
10
15
20
25
30
(Q4-5)
All the systems have the same properties:
-linear
-time variant
-causal
-dynamic
Solution
(Q5-a)
x1=[1 1 1 0 0];
v1=[1 1 1 1 0 0];
y1=conv(x1,v1);
stem(y1);
xlabel('n');
ylabel('y');
3
2.5
y
2
1.5
1
0.5
0
1
2
3
4
5
6
n
7
8
9
10
(Q5-b)
x2=[2 1 0 0 0];
v2=[1 1 1 1 0 0];
y2=conv(x2,v2);
stem(y2);
xlabel('n');ylabel('y');
3
2.5
y
2
1.5
1
0.5
0
1
2
3
4
5
6
n
7
8
9
10
(Q5-c)
x3=[2 1 0 0 0];
v3=[0 1 2 0 0 0];
y3=conv(x3,v3);
stem(y3);
xlabel('n');ylabel('y');
Solution
(Q6-b)
t=-7:0.001:7;
N=input('number of harmonics = ');
c0=0;
w0=pi/3;
xN=c0*ones(1,length(t));
for n=1:2:N
xN=xN+8/(3*w0*n)*cos(w0*n*t+3*pi/2);
end
plot(t,xN);
For 5 harmonics
For 20 harmonics
For 50 harmonics