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

Highly Integrated 20A Digital Power Module for High Current Applications

March 20, 2024
Renesas latest power module delivers the highest efficiency (up to 94% peak) and fast time-to-market solution in an extremely small footprint. The RRM12120 is ideal for space...

Empowering Innovation: Your Power Partner for Tomorrow's Challenges

March 20, 2024
Discover how innovation, quality, and reliability are embedded into every aspect of Renesas' power products.

Article: Meeting the challenges of power conversion in e-bikes

March 18, 2024
Managing electrical noise in a compact and lightweight vehicle is a perpetual obstacle

Power modules provide high-efficiency conversion between 400V and 800V systems for electric vehicles

March 18, 2024
Porsche, Hyundai and GMC all are converting 400 – 800V today in very different ways. Learn more about how power modules stack up to these discrete designs.

Comments

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