create, learn

Forward Fast-Mo-Fo-Fourier-Transform Disco LEDs

The fundamental idea here was to simulate Low-Pass, Band-Pass and High-Pass filters using computer processing and use them to drive a set of LEDs.. or in short, make some funky disco lights.

This is an idea I’ve had since first getting an Arduino last year and watching this video of the same concept implemented using only analogue components. Whilst that approach would be a lovely foray into the world of EE principles, it seemed slightly old-fashioned and not quite educational enough (I would just be following somebody else’s plans).

I guess this brings me to an important point, this blog isn’t meant to be ground-breaking, or even mildly interesting. It’s just my place for writing up (consolidating if you will) whatever projects and new activities I do. I’m quite rusty on computer techniques and just leapt into the second year of a BSc Computer Science with my 6 year out-of-date programming knowledge. So in this project I aimed to get up to scratch at some ideas involved in Java applications, but with some end result that isn’t another “Hello World!”.

Music plays.. Lights flash.. ok so its not Deep Blue

So you clicked for more, lets talk basic principles..

(like i said, this is just my personal blog, these are the component parts of this exercise and I just aim to summarise with some background info)

GUI‘s in Java have never been something I’ve ventured far into, but as with most of the component parts in this project (and here’s where i sound like an old man) it seems that all one needs to do is string together a whole bag of pre-written libraries when writing a program. I’m going to digress, back in the days I began coding there were no libraries and OOP was a new concept, everything had to be built (or at least copied and modified) from the ground up, I’ve had some trouble acclimatising to the idea that we don’t have to fire the clay to make the bricks for our new house any more. In-fact now its as easy as buying  a house and simply passing it the parameters of how many windows and doors it should have, the rest is done by pixies. (i’m not really a grumpy old man, it’s just a character flaw that i take pleasure in painfully re-inventing the wheel, and i suck at crafting, so it usually ends up square.. go figure) 

Where was I?.. I chose to use the controlP5 library for processing which includes a whole horde of customisable GUI components, I hastily threw together a grid system and arranged the components, though this did take a few hours. The colour scheme came from my new favourite lovable colour website COLOURlovers

Forward Fast-Fourier-Transform is the a complicated maths wizardry technique for analysing frequency bands, usually detecting or singling out a single frequency amongst a whole load of noise. It’s a technique I’ve encountered before when repairing missile systems for the Royal Navy where an entire rack of 80’s era circuit boards covered with discrete components performed Forward FFT on radar returns in order to pick out the single frequency returned ( + doppler shift ) from fast-moving incoming missiles. Stand-fast the maths used, it’s a complicated method and something I have no idea of the cogs and wheels used to perform it. Here I’m just using it to grab the gain of a sample of frequency bands to build the graphic equalizer. The Minim sound library takes 1024 frequency samples across the spectrum each time the function is called, this is a little excessive for three LEDs so part of the program divides this number by the number of frequencies shown on the EQ, this result is used to evenly space out the samples displayed and used to control the pass filters.

Wikipedia can tell you more: Fast Fourier Transform  along with Filter (signal processing) for a description of what real filters do. (as opposed to my simulated filters, which don’t require explanation unless your a potato)

And Envelope Curve was applied to the spectrum as it became apparent that for some reason (investigation showed this to be a normal thing) the Minim spectrum was showing > 10 * gain in the low frequencies. See the wiki Envelope (Mathematics) for an explanation.

Serial Arduino communication was a bit that required some intuition. I shall explain.. (do note that I could have avoided all this by ramping back the sampling speed, the resolution of serial updates to the arduino or a whole bunch of other sensible stuff. but i found the challenge in optimising the speed the arduino could handle being pelted with bytes more interesting).

At first the Arduino sketch very nonchalantly accepted the incoming data to a buffer, parsed the data and used a switch case control structure to determine which LEDs to light at a certain time. This needed to happen 60 times a second to keep up with the serial data. 60 times a second seems slow in computing terms, however the Arduino is already quite sluggish, and having to make so many decisions, interpretations and type-casting slowed it down such that it could only ever fire two LEDs before a new set of serial data arrived (3 bytes were being sent, one for the state of each filter).

Some basic EE principle thinking was needed and since this post is becoming a chunk of War and Peace, I shall explain with a diagram…

Optimized serial-port output method

Coming up on 1000 words, I think it’s time to end this post..

Source (Processing and Arduino) is available to download, no license or otherwise, use it as you will:

Thanks for reading. Andy

3 thoughts on “Forward Fast-Mo-Fo-Fourier-Transform Disco LEDs

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