I measured a (real) voltage waveform (red curve below). Then I took its FFT and used the magnitudes of the first 20 harmonics (even and odd) to model the signal (blue trace below), by summing the fundamental and harmonic-related sine wave components as follows:


I expected a better match between the two curves. What portion of the spectrum am I missing in my model to get a better match?

The model (blue) has symmetrical rising and falling edges, whereas the measured waveform (red) appears asymmetrical (capacitive charging/discharging; that is, the transitions begin sharply then decay). How does the FFT capture this effect if not in the harmonics?

Measured (red) versus modeled (blue)


I modified the above equation to include the phase as follows:


where phiN is the phase for each harmonic computed from FFT coefficients between 0 and Nyquist frequencies (e.g. atan(imag/real)).

enter image description here

The model (blue) does show an improvement in addressing asymmetric rise and fall transitions, but I'm still missing something.

Is there a way to improve the model based on FFT coefficients as I'm trying to do here, without computing the IFFT explicitly? I'm trying to create a waveform where every cycle is exactly the same, with the same period (within machine error), which represents the waveform of an average cycle (repeated many times).

  • 2
    $\begingroup$ It looks like you are not using the phase of the FFT $\endgroup$
    – Hilmar
    Commented Jun 12, 2017 at 1:36
  • $\begingroup$ in $V_\text{out}(t)$ why are all the terms $\sin(k \omega t)$? no cosine in there? $\endgroup$ Commented Jun 12, 2017 at 4:02
  • 1
    $\begingroup$ The FFT result is a complex quantity which means it has magnitude and phase. The simplest approach would be to use the form $Ae^{jn\omega_o t + \phi}$ for each FFT bin, where A is the FFT magnitude, $\phi$ is the FFT phase, \omega_o is the fundamental radian frequency, and n is a positive integer including 0. The fundamental frequency is $2\pi/T$ where T is the length of your time domain waveform in seconds. This form is much simpler than cosines and sines, and is equivalent due to Eulers identlty: $e^{j\theta}=cos(\theta)+j sin(\theta)$ $\endgroup$ Commented Jun 12, 2017 at 5:14
  • $\begingroup$ Note to be indentical you will also need to scale the FFT magnitude by 1/N where N is the number of samples in the FFT. $\endgroup$ Commented Jun 12, 2017 at 5:15
  • 1
    $\begingroup$ A truncated Fourier Series corresponds to a least squares error criteria. Another error criteria is to minimize the Chebychev error. In Theory and Application of digital signal processing by Rabinier and Gold, 1975 they show how to formulate a Chebychev minimization by setting up a Linear Program (Simplex). I don't want to suggest that Rabbit hole but if you have some familiarity with Linear Programming it might be worth it. This was the standard prior to Remez exchange so most DSP people don't have much familiarity with it but it seems to be coming back with sparse sampling $\endgroup$
    – user28715
    Commented Jun 13, 2017 at 0:20

1 Answer 1


I found the answer here:


Just change atan() to atan2() to account for the correct phase in all quadrants.

  • $\begingroup$ ah, so some of your harmonics were outa phase by 180° ? that will screw up the waveform, but it's unlikely to sound different. $\endgroup$ Commented Jun 17, 2017 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.