Frequency analysis

Hello community!

I've been trying to "split" an audio signal into its frequency components, just like any music player with a visualizer does. There are quite a lot of tutorials around. Most of them seem to be using "Processing" and communicating with it via serial. The only problem with that approach is that I need the Arduino to be able to do the splitting on its own. So far, the only library that worked alone was one named "fix_fft" that was posted by a user on this forum (I believe this?).

As per an example sketch, I did 4 tests. The first one was with a floating cable, and the other 3 were done while having the analog in wire connected to a channel from an audio out (those 3.5mm things) from my phone, laptop and computer (to be sure that at least one doesn't use PWM or anything like that). Looking at the resulting plot (IDE's serial plotter), I literally can't tell any one apart from the other, so I feel that I'm doing something wrong. Do I have to use an audio amplifier for it to work? What am I doing wrong?

The first one was with a floating cable

What do you mean "floating"?

while having the analog in wire connected to a channel

What about the ground?

Pete

I've been trying to "split" an audio signal into its frequency components, just like any music player with a visualizer does. There are quite a lot of tutorials around. Most of them seem to be using "Processing" and communicating with it via serial. The only problem with that approach is that I need the Arduino to be able to do the splitting on its own.

I've never done this stuff, but the FFT/FHT library should output some variables and then it's up to you and your application to decide what to do with those values. You can find examples of people making Arduino based spectrum analyzers (where the output is usually an array of LEDs).

As per an example sketch, I did 4 tests. The first one was with a floating cable, and the other 3 were done while having the analog in wire connected to a channel from an audio out (those 3.5mm things) from my phone, laptop and computer (to be sure that at least one doesn't use PWM or anything like that). Looking at the resulting plot (IDE's serial plotter), I literally can't tell any one apart from the other

Did you [u]bias[/u] the Arduino's input? Without bias, your audio signal is negative half the time and negative voltages can damage the Arduino, distort the audio, and since the Arduino can't read negative voltages, your FFT calculations will be messed-up.

A floating-input probably isn't that helpful because it can pick up noise, but you could try grounding the input because you know that's "silence". And then for testing, I recommend some test-tones. You can generate sine waves at known frequencies with [u]Audacity[/u] and play them back on your computer.

To test your hardware and to make sure you're getting a good signal, run the [u]Analog Read Serial Example[/u]. With the biased input, silence should read about 512. Quiet sounds should jump around a little, and louder sounds should jump-around much-higher than 512 and much lower. Note that even a constant tone will jump around because you are reading at random places along the waveform, and the wave passes-through zero (512) twice per cycle.

el_supremo:
What do you mean "floating"?
What about the ground?

Pete

Floating meaning literally floating around. The jumper cable was attached to an analog pin but the other end was touching nothing (or a piece of paper every now and then :slight_smile: )

I tried with the ground as well (the jack's ground). Nothing distinguishable either. The physical ground (GND on arduino, or my metal radiator) resulted in a constant value, so I thought that works. Even touching the end of the cable resulted in a change of waveform, but connecting it to the audio out just doesn't do anything.

DVDdoug:
I've never done this stuff, but the FFT/FHT library should output some variables and then it's up to you and your application to decide what to do with those values. You can find examples of people making Arduino based spectrum analyzers (where the output is usually an array of LEDs).

Did you [u]bias[/u] the Arduino's input? Without bias, your audio signal is negative half the time and negative voltages can damage the Arduino, distort the audio, and since the Arduino can't read negative voltages, your FFT calculations will be messed-up.

A floating-input probably isn't that helpful because it can pick up noise, but you could try grounding the input because you know that's "silence". And then for testing, I recommend some test-tones. You can generate sine waves at known frequencies with [u]Audacity[/u] and play them back on your computer.

To test your hardware and to make sure you're getting a good signal, run the [u]Analog Read Serial Example[/u]. With the biased input, silence should read about 512. Quiet sounds should jump around a little, and louder sounds should jump-around much-higher than 512 and much lower. Note that even a constant tone will jump around because you are reading at random places along the waveform, and the wave passes-through zero (512) twice per cycle.

I haven't biased the signal. I though that absolutely any change in voltage should do something (be it negative).

I checked with a ground attached and it resulted in a constant value (I think it's okay). As for test tones, I tried a constant 50Hz sinewave and also a sweeping sinewave from 20Hz-ish to 18kHz-ish. Still looked like random values to me.

I think my hardware is (still XD) good. I have tried outputting raw analogRead values to the plotter and it resulted in a pretty neat sinewave while the cable was floating (I think it was the mains influencing it, no idea). After connecting it to the same audio "sources" (my 3 devices) the sinewave was a bit "cracky" (screenshots attached), so it means that something is actually happening.

Bump

Link

MasterT:
Link

That is exactly what I'm trying to do. I think I will end up using a MSGEQ7...

By the way, is there any alternative IC to it?

That is exactly what I'm trying to do. I think I will end up using a MSGEQ7...

By the way, is there any alternative IC to it?

You can find active filter chips or make active filters from op-amps, but I've never seen anything that's as easy to use as the MSGEQ7.

You may get code for arduino UNO from here:
SA_Remix-1a

SplitRadixRealT

TFT-LGDP