Electronic Design

Program Converts Real Sequences To Cosine Series

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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish