Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Using line-in for FFT

  1. #1
    Junior Member
    Join Date
    Oct 2016
    Posts
    7

    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"
    //....
    float m=fft1024_1.read(i);
    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. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,700
    Quote Originally Posted by Maxim View Post
    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. #3
    Junior Member
    Join Date
    Oct 2016
    Posts
    7
    Ok, thanks!
    But if I'm not mistaken the 1 is the maximum value of
    fft1024_1.read(i);
    and not the minimum one.

  4. #4
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,700
    Quote Originally Posted by Maxim View Post
    Ok, thanks!
    But if I'm not mistaken the 1 is the maximum value of
    fft1024_1.read(i);
    and not the minimum one.
    I don't know, I'm not using this. OK, I checked it, it gives you normalized values. In this case take max(1.0e-5,fft1024_1.read(ii)), this way the min value is 0dB (20*log10(1e-5) = -100)

  5. #5
    Junior Member
    Join Date
    Oct 2016
    Posts
    7
    Ok, thaks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •