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

Near- and Far-Field Measurements

April 16, 2024
In this comprehensive application note, we delve into the methods of measuring the transmission (or reception) pattern, a key determinant of antenna gain, using a vector network...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Empowered by Cutting-Edge Automation Technology: The Sustainable Journey

April 16, 2024
Advanced automation is key to efficient production and is a powerful tool for optimizing infrastructure and processes in terms of sustainability.

Comments

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