This idea presents a C++ program that uses the complex class, which enables complex arithmetic. The Discrete Fourier Transform (DFT) is applied to the waveform stored in a disk file—a real sequence of double-precision floating-point binary values. (See the program listing.)

The function dft( ) performs a DFT on the real sequence of N samples in Datain(n) and outputs the resulting spectra in the complex array Dataout(k). The program is set up for a 1024-point DFT; however, this can be altered by revising MAXPTS.

The transform is given by:

for k = 0 to N 1 and F_{S} = sample frequency in Hertz.

The real frequency, F, is related to the index k by F = kF_{S}/N, where the frequency spacing is F_{S}/N. The DFT generates both real and image frequencies. From the Nyquist sampling criterion, kF_{S}/N < F_{S}/2, where the real frequencies are k < N/2 and the image frequencies are k >= N/2. The real and image frequencies have conjugate symmetry—i.e., Dataout(k) = conjugate\[Datain(N k)\] for real sequences.

An example 10-V, 50-ms pulse waveform is shown in the figure. Three *for( ) *loops will generate this waveform:

for(n = 0; n < 75; n++) a(n)

= 0.0;

for(n = 75; n < 125; n++) a(n) = 10.0;

for(n = 125; n < 199; n++) a(n) = 0.0;

To test your program, in the main( ) function, block out the disk operations and add the for( ) statements. The representative waveform characteristics of power, energy, and voltage are shown in Figure 2. In addition to amplitude, the spectra, power, energy, and voltage spectral densities of the example pulse waveform are shown. The frequency band (k_low, k_high) is user-selectable, allowing calculation of in-band characteristics.

Note that the program is set up to handle odd values of N, which generates the same number of real and image frequencies. However, the program will accept even values of N and will make the required adjustment in the value of N.

A 1024-point DFT was run on the 120-MHz Pentium I and a 350-MHz Pentium II. The respective run times were approximately eight and two seconds. For slower platforms, a run indicator is included.