# derive an average waveform from an FFT spectrum, where all cycles have same shape and period

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:

Vout(t)=A1*sin(wt)+A2*sin(2wt)+A3*sin(3wt)+...+A20*sin(20wt)


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?

UPDATE

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

Vout(t)=A1*sin(wt-phi1)+A2*sin(2wt-phi2)+A3*sin(3wt-phi3)+...+A20*sin(20wt-phi20)


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

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).

• It looks like you are not using the phase of the FFT – Hilmar Jun 12 '17 at 1:36
• in $V_\text{out}(t)$ why are all the terms $\sin(k \omega t)$? no cosine in there? – robert bristow-johnson Jun 12 '17 at 4:02
• 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)$ – Dan Boschen Jun 12 '17 at 5:14
• 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. – Dan Boschen Jun 12 '17 at 5:15
• 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 – Stanley Pawlukiewicz Jun 13 '17 at 0:20

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