1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
clc
//Chapter1: Signals
//Example2,page no12
//Given:
//a // Referance Figure on page no 9.. (1.6d)
t=0:2*3.14,t0=0,t1=2*3.14
disp('a) The value of constants Cn are:')
for i=1:7
C(i)=((integrate('sin(i*t)','t',t0,t1/2)-integrate('sin(i*t)','t',t1/2,t1))/integrate('(sin(i*t))^2','t',t0,t1))
if C(i)<=0.01 then C(i)=0
end
mprintf('%f for n= %d\n',C(i),i)
end
//b Mean Square error
int1=integrate('(1)^2','t',t0,t1)
for n=1:7
if modulo(n,2)==0 then
C(n)=0
else
C(n)=4/(n*%pi)
end
end
for n=1:7
K(n)=integrate('(sin(n*t))^2','t',t0,t1)
end
K(n)=%pi
for n=1:7
S(1)=0
S(n+1)=S(n)+(((C(n))^2)*K(n))
end
//Mean Square error
for n=1:7
epsi(n)=(1/(t1-t0)*(int1-S(n+1)))
end
disp('b) Mean Square error is')
for n=1:2:7
mprintf('epsi(%d)=%f\n',n,round(100*epsi(n))/100)
end
|