Forum Rule: Always post complete source code & details to reproduce any issue!

# Thread: Using line-in for FFT

1. ## Using line-in for FFT

Hi!

A couple of questions:
I have a Teensy 3.2 and an audio shield.

1)I want to receive audio input and to do a real-time FFT.
Did I understand correctly that all I need is just to solder in a 3.5mm stereo female socket, and then I can use AudioInputI2S of GUI?
http://www.pjrc.com/teensy/gui/?info=AudioInputI2S

2)If a logarithmic scale is needed, a simple

Code:
```//...
#include "math.h"
//....
int x = max(20*log(m)+100,0);```
is enough, or there is a more efficient way to do it?

3)If I want to use the built-in ADC of Teensy, I don't need SGTL5000 at all?
Is the circuitry here
http://www.pjrc.com/teensy/gui/?info=AudioInputAnalog
sufficient for this purpose or an anti-aliasing filter is needed?

Thanks,
Maxim.

2. Originally Posted by Maxim
Code:
```float m=fft1024_1.read(i);
int x = max(20*log(m)+100,0);```
You should limit the m value to positive numbers before taking the logarithm
Code:
```float m=(float)max(1,fft1024_1.read(i));
int x = (int)(20.0f*log10f((float)m))+100;```
as m is integer log10(1) = 0, so you do not need the second max after logarithm
You should use log10 as log is natural log that gives you 20*Neper and not dB

3. Ok, thanks!
But if I'm not mistaken the 1 is the maximum value of
and not the minimum one.

4. Originally Posted by Maxim
Ok, thanks!
But if I'm not mistaken the 1 is the maximum value of