0

I really fail at FFT and now I'm in need to communicate from the headphone jack of my Android to the Arduino there's currently a library for Arduino (talks about it in the blog post Real-time spectrum analyzer powered by Arduino) and one for Android too!

How should I start? How should I build audio signals which ultimately can be turned into FFTs and the Arduino can analyse the same using the library and I can actuate anything?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Naaz
  • 273
  • 2
  • 6
  • 21
  • A college textbook on data communications? – hotpaw2 May 30 '13 at 22:23
  • Make you question more specific. What is your issue? Lack of understanding for FFT? Lack of hardware knowledge on how to connect a headphone jack? Lack of programming skills? – Udo Klein May 31 '13 at 05:28
  • Maybe you'd be better explaining what high-level function you really want to achieve. What and why are you wishing to communicate to the arduino? The FFT might not be the best solution for you, especially if you don't understand it already. – Martin Thompson May 31 '13 at 09:43
  • I need to send audio signals that can be decoded to match a certain condition on the Arduino and I actuate a PIN on/off on that basis, I strictly lack FFT knowledge , I'm recently studying about it and watched some videos on youtube which made be understand a bit about it – Naaz May 31 '13 at 11:54
  • I think I need to generate sounds on my Android and there on the Arduino use the FFT class to get the sound signals? I think I'm on right track? Kindly comment! – Naaz May 31 '13 at 18:22
  • 1
    What exactly do you try to achieve? This looks suspiciously like the xy problem: http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem. So why do you think you need FFT in the first place? – Udo Klein Jun 01 '13 at 09:50

1 Answers1

3

You are asking a very fuzzy question: "How should I build audio signals which ultimately can be turned into FFTs and the Arduino can analyse the same using the library and I can actuate anything?". I am going to help you think through the problem - asking yourself the right questions is essential to get any answers.

Presumably, your audio signals are "coming from somewhere" - i.e. they are sound. This means that you need to convert them into a stream of numbers first.

problem #1: converting audio signal into a stream of numbers

This breaks down into three separate sub problems:

  1. Getting the signal to the right amplitude
  2. Choosing the sampling rate needed
  3. Digitizing and storing the data for later processing

Items (1) and (3) are related, since you need to know how you are going to digitize the signal before you can choose the right amplitude. For example, if you have a microphone as your sound input source, you will need to amplify the signal (and maybe add some automatic gain control) before feeding it into an ADC (analog to digital converter) that has a 5 V input range, since the microphone may have an output in the mV range. Without more information about the hardware you are using, there's not a lot to add here. It sounds from your tag that you are trying to do that inside an Android device - in which case I wonder how you intend to move the digital signal to the Arduino (over USB?).

The second point, "choosing the sampling rate", is actually very important. A sound signal contains many different frequencies - think of them as keys on the piano. In order to detect a high frequency, you need to sample the signal "faster than it is changing". There is a formal theorem called "Nyquist's Theorem" that states that you have to sample at 2x the highest frequency that is present in your signal. Note - it's not just "that you are interested in", but "that is present". If you sample a high frequency signal with a low frequency sample clock, it will appear "aliased" - it wil show up in your output as something completely different. So before you digitize a signal you have to decide what the frequencies of interest are, and remove all higher frequencies with a filter. Let's say you are interested in frequencies up to 500 Hz (about 1 octave above middle C on a piano). To give your filter a chance to work, you might choose to cut off all frequencies above 1 kHz (filters "roll off" - i.e. they increase in strength over a range of frequencies), and would sample at 2 kHz. This means you get 2000 samples per second, and you need to figure out where to put them on your Arduino (memory fills up quickly on the little board.)

Problem #2: analyzing the signal Assuming that you have somehow captured a digital signal, your next task is analyzing it. The FFT is basicaly some clever math that tells you, for a given sound sample, "what keys on the piano were hit, and how hard". It breaks the sound signal into a series of frequency "bins", and determines how much energy is in each bin (it also computes the phase, but let's keep it simple). So if the input of a FFT algorithm is a sound sample, the output is an array of values telling you what frequencies were present in the signal. This is approximate, since it will find the "nearest bin". Sticking with the same analogy - if you were hitting a piano that's out of tune, the algorithm won't return "out of tune", but rather "a bit of C, and a bit of C sharp", since it cannot actually measure anything in between. The accuracy of an FFT is determined by the sampling frequency (which gives you the upper limit on the frequency you can detect) and the sample length: the longer you "listen" so the sample, the more subtle the differences you can "hear". So you have another trade-off to consider: if your audio signal changes rapidly, you have to sample for a short time (to capture the quick changes); but if you need an accurate frequency, you have to sample for a long time. For example if you are writing a Morse decoder, your sampling has to be short compared to a pause between "dits" and "dashes" - or they will slur together. Figuring out that a morse tone is present is pretty easy though, since there will be a single tone (one bin in the FFT) that is much larger than the others.

Exactly how you implement these things depends on your application. The third step, "doing something with it", requires you to decide what is a meaningful signal. Again, if you are making a Morse decoder, you would perhaps turn an LED ON when a single tone is present (one or two bins in the FFT have much bigger value than the mean of the others), and OFF when it is not (all noise - lots of bins with approximately the same size). But without a LOT more information from you, there's not much more one can say to help you.

You might learn a lot from reading the following articles:

http://www.arduinoos.com/2010/10/sound-capture/

http://www.arduinoos.com/2010/10/fast-fourier-transform-fft/

http://interface.khm.de/index.php/lab/experiments/frequency-measurement-library/

Floris
  • 45,857
  • 6
  • 70
  • 122
  • i have read all your wrote thoroughly and gone by the links ,now I need to know who I can generate tones which are unique(in Android app) and correspond to some alphabets like Tone A for char "A" and Tone B for char "B" these tones would goto the arduino using the android headphone jack and be analysed over it – Naaz Jun 03 '13 at 05:49