How To Build Your Own FFT Audio Analyzer

KHM-019-00.png

The Fast Fourier Transform (FFT) is an algorithm capable of converting a signal from its original domain (often time or space) to a representation in the frequency domain and vice versa. It works alongside the consideration that every non-periodical signal in the time domain is a sum of periodic ones in terms of sines and cosines that can be broken down.

In the audio field, this tool can help us to find and filter unwanted noises (frequencies), analyze functions harmonics, extract meaningful features of a signal for Machine Learning purposes, and much more.

FFT is considered the most important numerical algorithm of our lifetime, and in this guide, you will be implementing it with WisBlock.

If you are a visual learner, you can watch the video tutorial instead.

Hardware

To carry out this test you need some WisBlock hardware:

You can choose between several microphones:

đź“ť NOTE: This is also compatible with the ESP32 and RP2040 cores.

Software

  • Arduino IDE

Follow the installation guide of BSP to set up your Arduino IDE to program WisBlock boards.

WisBlock Assembly

To put together the different modules, you just need to connect them to the respective slots in the base board.

KHM-019-01.png

KHM-019-02.png

Code

To open the code, download and install the RAKwireless Audio Library from the GitHub repository.

Open the Arduino IDE, and search for the ZIP file by navigating to Sketch > Include Library > Add .ZIP Library…

KHM-019-03.png

On the Arduino IDE, navigate to File > Examples > RAKwireless Audio Library > RAK4631 > PDMSerialPlotterFFT.

📝 NOTE There’s also a High Rate FFT example.

KHM-019-04.png

Select the board you are using, connect it through the USB cable, and select the respective COM port.

KHM-019-05.png

Click Upload, and wait for the core to be flashed.

KHM-019-06.png

Testing

Once the code is uploaded, open the Serial Plotter on the Arduino IDE and you should see a line graph.

📝 NOTE: The line graph doesn’t work with Arduino IDE 2.0.

KHM-019-07.png

To better see the FFT in action, use Online Tone Generator to generate pure tones of any frequency to play some notes.

KHM-019-08.png

Lastly, set the frequency to 440 Hz. The Serial Plotter shows us a high amplitude spike and specifies the frequency component extracted. It almost perfectly matches the set on the tone generator, so we are up and running with very accurate results, which is great.

KHM-019-09.png

Updated