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.