Go Down

Topic: Analyzing Audio w/ Arduino FFT (Read 6872 times) previous topic - next topic

tmd3

Well, you will soon figure out how to identify it.  Check the documentation for the FFT library that you're using for this project.  Does it tell you where the input data is?  Look at your sketch, too:  it should be storing data somewhere.


 

funfrancis

Have you worked with Ardiuno FFT library?
If yes, could you post your codes here.

tmd3

I decline.  I'm happy to work with you as you learn, but I'm not going to write your sketch for you.

funfrancis

For better viewing, I d like to make the FFT output in the serial monitor similar to the one from Teensy
For eg, https://www.dropbox.com/s/3sat3e7xk8syx0j/Recording%20Ended_Error.png?dl=0

jremington

#19
Feb 25, 2016, 05:45 am Last Edit: Feb 25, 2016, 05:46 am by jremington
Quote
I can't identify the input data
Hint: read the comments in the code you posted.
Code: [Select]

     fft_input[i] = k; // put real data into even bins
     fft_input[i+1] = 0; // set odd bins to 0

funfrancis

If I want to see just 40 or 50 freq analysis bins, How do I modify the code.
Also I want like 0-39 in a line and the next set in the next line

jremington

#21
Feb 25, 2016, 08:10 pm Last Edit: Feb 25, 2016, 08:11 pm by jremington
If you have to ask questions like this, you are in way over your head. Forum members aren't interested in writing code for complete beginners. That has already been done many times.

Please start with the simple example projects that come with the IDE and learn the programming language before tackling something as sophisticated as FFT analysis.

funfrancis

Hi

With some help, I modified the code as such
Code: [Select]
/*
fft_adc.pde
guest openmusiclabs.com 8.18.12
example sketch for testing the fft library.
it takes in data on ADC0 (Analog0) and processes them
with the fft. the data is sent out over the serial
port at 115.2kb.  there is a pure data patch for
visualizing the data.
*/

#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft

#include <FFT.h> // include the library

void setup() {
  Serial.begin(9600); // use the serial port
  TIMSK0 = 0; // turn off timer0 for lower jitter
  ADCSRA = 0xe5; // set the adc to free running mode
  ADMUX = 0x40; // use adc0
  DIDR0 = 0x01; // turn off the digital input for adc0
}

void loop() {
  while(1) { // reduces jitter
    cli();  // UDRE interrupt slows this way down on arduino1.0
    for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
      while(!(ADCSRA & 0x10)); // wait for adc to be ready
      ADCSRA = 0xf5; // restart adc
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int k = (j << 8) | m; // form into an int
      k -= 0x0200; // form into a signed int
      k <<= 6; // form into a 16b signed int
      fft_input[i] = k; // put real data into even bins
      fft_input[i+1] = 0; // set odd bins to 0
    //Serial.println(k);
    }
//   
//    for(int i=0;i<512;i += 2)
//    {
//      fft_input[i] = sin(i/(2*3.14*30));
//      fft_input[i+1] = 0;
//    }
   
   
    fft_window(); // window the data for better frequency response
    fft_reorder(); // reorder the data before doing the fft
    fft_run(); // process the data in the fft
    fft_mag_log(); // take the output of the fft
    sei();
      for (uint8_t j = 0; j < FFT_N/8; j++) {
      Serial.print(j);
      Serial.print(" ");
     }
    Serial.println("");
    for (uint8_t j=0; j<FFT_N/8; j++){
      Serial.print(fft_log_out[j]);
      Serial.print(" ");
    }
    Serial.println(" ");
    Serial.println(); 
  }
}


The output
https://www.dropbox.com/s/g41qjfzzxr7h4dz/Hydrophone_FFT_Output.png?dl=0

First line: FFT sample number
Second line: Magnitude

The connections are modified as well
https://www.dropbox.com/s/8xqu9mx05n426n5/Hydrophone%20-%20PreAmp.png?dl=0


Grumpy_Mike

So have you any idea what those numbers mean?
Why take a 512 point FFT if you only want one eighth of the bins?

funfrancis

I plotted those numbers in Excel and obtained a graph similar to FFT curve
Have you received similar output??

For 1/8th of bins, what do I change 512 to

Grumpy_Mike

But I repeat what do they mean? I can write you a routine that will fill and array with random numbers and it will look like an FFT.

Quote
For 1/8th of bins, what do I change 512 to
well 64 might be good don't you think?

funfrancis

I ran it from the Arduino FFT example
So, It should represent the amplitudes


funfrancis

well 64 might be good don't you think?
So pls check the foll lines
Code: [Select]

/*
fft_adc.pde
guest openmusiclabs.com 8.18.12
example sketch for testing the fft library.
it takes in data on ADC0 (Analog0) and processes them
with the fft. the data is sent out over the serial
port at 115.2kb.  there is a pure data patch for
visualizing the data.
*/

#define LOG_OUT 1 // use the log output function
#define FFT_N 64 // set to 256 point fft
.........
    for (int i = 0 ; i < 128 ; i += 2) ..........


funfrancis

Hi

If you are familiar with the teensy FFT program and its functionality

How do i make my codes similar to that??

pjrc

#29
Feb 29, 2016, 12:34 pm Last Edit: Feb 29, 2016, 12:37 pm by Paul Stoffregen
Buying and using a genuine Teensy would be the obvious way, right?

There's no hope for 8 bit 16 MHz Arduino Uno without DMA or large memory to ever work the easy way Teensy 3.2 can.  Teensy has a 32 bit, 96 MHz processor with DSP extensions and DMA-based streaming data input and 32 times as much RAM.  The Teensy Audio Library leverages all that powerful hardware to make FFT and lots of other audio DSP stuff really easy.  Uno simply doesn't have the powerful hardware resources for windowed and 50% overlapped 1024 point FFTs while simultaneously acquiring 44100 Hz 16 bit samples and giving your sketch more than half of the CPU time.

Go Up