NUMERICAL COMPUTATION OF D n

6.6 NUMERICAL COMPUTATION OF D n

We can compute D n numerically by using the DFT (the discrete Fourier transform discussed in Section 8.5) , which uses the samples of

a periodic signal x(t) over one period. The sampling interval is T seconds. Hence, there are N 0 =T 0 /T number of samples in one period T 0 . To find the relationship between D n and the samples of x(t), consider Eq. (6.29b)

where x(kT) is the kth sample of x(t) and

In practice, it is impossible to make T → 0 in computing the right-hand side of Eq. (6.96) . We can make T small, but not zero, which will cause the data to increase without limit. Thus, we shall ignore the limit on T in Eq. (6.96) with the implicit understanding that T is reasonably small. Nonzero T will result in some computational error, which is inevitable in any numerical evaluation of an integral. The error resulting from nonzero T is called the aliasing error, which is discussed in more detail in Chapter 8 . Thus, we can express Eq. (6.96) as

Now, from Eq. (6.97) , Ω 0 N 0 =2 π. Hence, e j Ω 0 (k+N 0) =e j Ω 0k and from Eq. (6.98a) , it follows that

The periodicity property D n+N 0 =D n means that beyond n=N 0 /2, the coefficients represent the values for negative n. For instance, when

N 0 =32, D 17 =D −15 ,D 18 =D -14 , ..., D 31 =D −1 . The cycle repeats again from n=32 on.

We can use the efficient FFT (the fast Fourier transform discussed in Section 8.6) to compute the right-hand side of Eq. (6.98b) . We shall use MATLAB to implement the FFT algorithm. For this purpose, we need samples of x(t) over one period starting at t = 0. In this

algorithm, it is also preferable (although not necessary) that N 0 be a power of 2, that is N 0 =2 m , where m is an integer.

COMPUTER EXAMPLE C6.4

Numerically compute and then plot the trigonometric and exponential Fourier spectra for the periodic signal in Fig. 6.2a ( Example 6.1 ). The samples of x(t) start at t =0 and the last (N 0 th) sample is at t=T 0 − T. At the points of discontinuity, the sample value is taken as

the average of the values of the function on two sides of the discontinuity. Thus, the sample at t =0 is not 1 but (e −π/2 + 1)/2 =0.604. To determine N 0 , we require that D n for n ≥N 0 /2 to be negligible. Because x(t) has a jump discontinuity, D n decays rather slowly as

1/n. Hence, a choice of N 0 =200 is acceptable because the (N 0 /2)nd (100th) harmonic is about 1% of the fundamental. However, we

also require N 0 to be power of 2. Hence, we shall take N 0 =256=2. [ 8 ]

First, the basic parameters are established. >> T_0 = pi; N_0 = 256; T = T_0/N_0; t = (0:T:T*(N_0-1))'; M = 10;

>> x = exp(-t/2); x(1) = (exp(-pi/2) + 1)/2; Next, the DFT, computed by means of the fft function, is used to approximate the exponential Fourier spectra over −M ≤ n ≤ M.

>> D_n = fft (x)/N_0; n = [-N_0/2:N_0/2-1]'; >> clf; subplot (2, 2, 1); stem(n, abs(fftshift (D_n)),'k'); >> axis ([-M M -.1 .6]); xlabel('n'); ylabel('|D_n|'); >> subplot (2, 2, 2); stem(n, angle(fftshift(D_n)),'k'); >> axis([-M M -pi pi]); xlabel ('n'); ylabel('\angle D n [rad]');

The approximate trigonometric Fourier spectra over 0 ≤ n ≤ M immediately follow. >> n = [0:M]; C_n(1) = abs(D_n(1)); C_n(2:M+1) = 2*abs (D_n(2:M+1));

>> theta_n(1) = angle(D_n(1)); theta_n(2:M+1) = angle(D_n(2:M+1)); >> subplot (2, 2, 3); stem(n,C_n,'k');

>> xlabel ('n'); ylabel('C_n'); >> subplot (2, 2, 4); stem(n,theta_n,'k'); >> xlabel ('n'); ylabel('\theta n [rad]');

Figure C6.4

[ 8 ] Bôcher, M. Annals of Mathematics, vol. 7, no. 2, 1906.