I saw someone do this in a presentation but I\'m having a hard time reproducing what he was able to do. Here\'s a slide from his presentation:
Pretty cool.
There are some issues with discrete Fourier transform that are not immediately obvious from playing with its continuous counterpart. For one thing, the periodicity of your input should match the range of your data, so it's going to be much easier if you use:
x = np.linspace(0, 4*np.pi, 200)
You can then follow your original idea:
sin1 = np.sin(x)
sin2 = np.sin(2*x)
sin3 = sin1 + sin2
fft3 = np.fft.fft(sin3)
Since in FFT sin
goes directly into the imaginary component, you can try plotting only the imaginary part:
plt.plot(fft3.imag)
plt.show()
What you should see will be peaks centered at x=2
and x=4
that correspond to the original sinusoidal components, which had frequencies of "2 per signal" (sin(x) from 0 to 4 pi) and "4 per signal" (sin(2x) from 0 to 4 pi).
To plot all individual components, you can go with:
for i in range(1,100):
plt.plot(x, fft3.imag[i] * np.sin(i*x)/100)
plt.show()