## Fast Fourier Transforms with Python – the noise and the signal

Continuing my exploration of Python and its magnificient libraries, I decided to experiment a bit with FFT’s.

The above graph shows (on top) a simple periodic wave in blue, generated by the sine function with period of 1s. Nothing remarkable there (except the fact that these plots are piece of cake to draw with Python’s matplotlib,scipy & numpy modules – I’m impressed by the intuitiveness and general ease-of-use of these libraries! MS Excel is far from this in terms of functionality and ease-of-use, and I wonder what the good folks at Mathworks think about this very capable freeware…? 🙂 )

The subgraph shows the ‘spectral analysis’ of the original wave, i.e. its constituent frequencies. Since I started out with a clean sine wave, there’s only one spike in the frequency distribution graph, at 1Hz, as it should be.

Now, let’s introduce some noise to the original signal, by adding some randomly generated disturbances:

Here, I’ve added some noise: The green line in the top part shows the original signal filtered by the FFT, the blue line the new,noisy input signal. In the frequency chart we can see that the new signal has some disturbances all over the spectrum:

In the next graph, I’ve added some non-harmonic periods to the signal:

from the graph on the signal itself, it’s very hard if not impossible to see what signal frequencies were added, but the frequency chart immediately reveals that in addition to the initial 1Hz signal, I now also have 2,5,7, and 9 Hz components.

Let’s add some noise to this new signal:

Now, the top chart starts to look really messy, and in the bottom section, we can see why: in addition to the frequencies deliberately added in the previous step, we now also have noise all over the frequency spectrum. I suspect there are few gizmos available that would be able to make any meaningful sense of such a noisy signal.

The inspiration for this experiment came from a couple of sources, mainly these:

The Glowing Python

http://www.thefouriertransform.com/