C++ Platform Program Offers Versatile Waveform Spectral Analysis Tool

Dec. 17, 2001
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...

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 FS = sample frequency in Hertz.

The real frequency, F, is related to the index k by F = kFS/N, where the frequency spacing is FS/N. The DFT generates both real and image frequencies. From the Nyquist sampling criterion, kFS/N < FS/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.

Sponsored Recommendations

TTI Transportation Resource Center

April 8, 2024
From sensors to vehicle electrification, from design to production, on-board and off-board a TTI Transportation Specialist will help you keep moving into the future. TTI has been...

Cornell Dubilier: Push EV Charging to Higher Productivity and Lower Recharge Times

April 8, 2024
Optimized for high efficiency power inverter/converter level 3 EV charging systems, CDE capacitors offer high capacitance values, low inductance (< 5 nH), high ripple current ...

TTI Hybrid & Electric Vehicles Line Card

April 8, 2024
Components for Infrastructure, Connectivity and On-board Systems TTI stocks the premier electrical components that hybrid and electric vehicle manufacturers and suppliers need...

Bourns: Automotive-Grade Components for the Rough Road Ahead

April 8, 2024
The electronics needed for transportation today is getting increasingly more demanding and sophisticated, requiring not only high quality components but those that interface well...

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!