Program Converts Real Sequences To Cosine Series

June 18, 2001
This program converts a sampled real sequence stored in a disk file to a harmonically related set of cosine waveforms To view the program, click Download the Code at the top of the page.. The cosine series can be used for waveform...

This program converts a sampled real sequence stored in a disk file to a harmonically related set of cosine waveforms To view the program, click Download the Code at the bottom of the page.. The cosine series can be used for waveform approximation, circuit design and analysis, simulation, and waveform synthesis.

First, the program downloads N samples of the waveform from disk and copies the data to the signal\\[n\\] array. Then, the discrete Fourier transform (DFT) is applied to the real sequence in signal\\[n\\]. The resulting N complex-amplitude spectral components X(k) are stored in the spectrum\\[k\\] array. Real and image frequencies (k), which have conjugate-symmetry for real sequences, make up the spectrum X(k). If N is even, the program eliminates the last sample, forcing an odd value of N. This ensures complete conjugate pairs of real/image frequencies.

As shown in the following, the inverse DFT applied to the spectrum X(k) has the form of a cosine series.

where θ(k) = tan−1( imX( k )/reX( k ) ) radians.

From the Nyquist sampling criterion,

where F = actual frequency (Hz) and FS = sampling frequency (Hz).

The coefficients of the series are stored in an array of coefficient structures \\[k\\] as demonstrated below:

These coefficients are listed in tabular form. To test the program, a single pulse is used. Next, the function get_real-data( ) in function main( ) is disabled and these statements are added:

int i;

for (i=0; i < 50; i++) signal(i) = 10.0;

for (i=50; i < 250; i++) signal(i) = 0.0;

After this, the program is recompiled and run, generating a 10-V input pulse that's 50 samples wide. At the prompt, the number of real data points is entered as 200. The program then displays the calculated cosine coefficients versus index k (see the table).

To download the listings, click Download the Code.

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!