blob: b8cbb06fd712ade003ce9e4f8edb8af53fc86b0e (
plain)
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
47
48
49
50
51
52
53
54
55
56
57
|
//numerical fourier analysis
//Exa_1_13
clc;
clear;
close;
n=12;
//number of time stations
m=3;
//number of harmonics required
time=0.12; //time period
x=[20000.0;34000.0;42000.0;49000.0;53000.0;70000.0;60000.0;36000.0;22000.0;
16000.0;7000.0;0.0]';
//presure in N/m^2
t=0.01:0.01:0.12; //time in second
sumz=0.0;
//temporary variable
for i=1:n //calculating the coefficients
sumz=sumz+x(i);
end
azero=2.0*sumz/n;
//first term of fourier series
for ii=1:m
sums=0.0;
sumc=0.0;
for i=1:n
theta=2.0*%pi*t(i)*ii/time;
coss(i)=x(i)*cos(theta);
sinn(i)=x(i)*sin(theta);
sums=sums+sinn(i);
sumc=sumc+coss(i);
end
a(ii)=2.0*sumc/n;
//coefficient of cos terms
b(ii)=2.0*sums/n; //coefficient of sin term
s
end
//printing the table of values
printf('Fourier series expansion of the function x(t)\n\n');
printf('Data:\n\n');
printf('Number of data points in one cycle = %3.0f \n',n);
printf(' \n');
printf('Number of Fourier Coefficients required = %3.0f \n',m);
printf(' \n');
printf('Time period = %8.6e \n\n',time);
printf('Station i ')
printf('Time at station i: t(i) ')
printf('x(i) at t(i)')
for i=1:12
printf('\n %8d%25.6e%27.6e ',i,t(i),x(i));
end
printf(' \n\n');
printf('Results of Fourier analysis:\n\n');
printf('azero=%8.6e \n\n',azero);
printf('values of i a(i) b(i)\n');
for i=1:3
printf('%10.0g %8.6e%20.6e \n',i,a(i),b(i));
end
|