288 C H A P T E R 4: Frequency Analysis: The Fourier Series
FIGURE 4.18
Two periods of the approximate triangular signal
xN(t)using 100 harmonics.
0 0.5 1 1.5 2
0
0.2
0.4
0.6
0.8
1
xN
(t
)
t(sec)
and the average term is
Z 0 =−
∑
m6= 0
Gm
1
j 2 mπ
=
∑
m6= 0
(− 1 )m
cos(πm)− 1
(πm)^2
=0.5
∑∞
m=−∞,m6= 0
(− 1 )m+^1
[
sin(πm/ 2 )
(πm/ 2 )
] 2
where we used 1−cos(πm)=2 sin^2 (πm/ 2 ). We used the following script to obtain the average,
and to approximate the triangular signal using 100 harmonics (see Figure 4.18). The mean is
obtained as 0.498.
%%%%%%%%%%%%%%%%%
% Example 4.18
%%%%%%%%%%%%%%%%
clf; clear all
w0 = 2 * pi; N = 100; % parameters of periodic signal
% computation of mean value
DC = 0;
for m = 1:N,
DC = DC + 2 * (-1) ˆ (m) * (cos(pi * m) -1)/(pi * m) ˆ 2;
end
% computation of Fourier series coefficients
Ts = 0.001; t = 0:Ts:2 - Ts;
for k = 1:N,
X(k) = (-1)ˆ(k + 1)*(cos(pi * k) - 1)/((pi * k)ˆ2);
end
X = [DC X]; % Fourier series coefficients
xa = X(1)*ones(1,length(t));
figure(1)