Hi Ming, glad you enjoyed it!
So, the recipe for each time spike has to be scaled by the size of the spike. Let’s say we just want (1 0 0 0) as a time spike. This would be equal strengths from each possible frequency, or
[1/4 1/4 1/4 1/4]
In this case, there’s no phase offset needed. Now, let’s say we have the spike of (0 2 0 0). We still need equal strengths, except this time it’s double, since we want to sum to 2.0 and not 1.0:
[1/2 1/2 1/2 1/2]
Whoops! We need to add in the phase offsets. It should be:
[1/2 1/2:-90 1/2:-180 1/2:-270]
since each Hz component needs to line up at t=1, not t=0. If we were to combine the signals (1 2 0 0) we would have:
[1/4 1/4 1/4 1/4] + [1/2 1/2:-90 1/2:-180 1/2:-270] = ?
The first term [0Hz component] can combine easily, to get 3/4. But the other terms have to be added like they are vectors:
1/4 pointing at 0 degrees + 1/2 pointing at -90 degrees is, with some trig:
Amplitude: sqrt[ (1/4)^2 + (1/2)^2 ] = .559
Angle: atan( -(1/2) / (1/4)) = -63.43 degrees
If you plug in (1 2 0 0) into the simulator, you get
[0.75 0.56:-63.4 0.25:180 0.56:63.4]
which are the first two terms. The others can be computed similarly. Of course, it’s a pain to do all this trig – we typically keep the components (amplitude + angle) as complex numbers (a + bi) so we can simply add them up to combine them. The simulator shows the phase offset as an actual angle to help visualize them. But the Fourier Transform formula only deals with complex numbers.
Phew – hope that helps!