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

So, bottom line: I’m impressed by Python, and its very vibrant community, more so for every day I get to spend with the language. It’s almost become like a drug for me, I need my daily dosis of Python to feel good…. 🙂


About swdevperestroika

High tech industry veteran, avid hacker reluctantly transformed to mgmt consultant.
This entry was posted in development, Math, software and tagged , , , . Bookmark the permalink.

One Response to Fast Fourier Transforms with Python – the noise and the signal

  1. titide says:

    Hi there, I would like to do this and more. Would the links above help?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s