/*
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(115200); // 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
}
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();
Serial.write(255); // send a start byte
Serial.write(fft_log_out, 128); // send out the data
}
}

Your question lacks clarity. Do you intend to sample A0, run an FFT, and then sample A1, and run an FFT on that? Or do you hope to sample A0 and A1 alternately, and run two FFT's?

What will you do with the results of the FFT? What are you doing with this project?

funfrancis:
I intend to connect two Hydrophones on A0 and A1 and wish to see their results simultaneously in the serial monitor

OK. That doesn't tell me whether you intend to interleave the samples or not. You can take the FFT of one input channel, and then the other, and show them simultaneously. Or, you can show them when you get them. Your sampling interval is short, and the openmusiclabs FFT code is fast. You won't notice the delay

So, to you intend to interleave the readings of two channels, and take two FFT's?

The hydrophones and Arduino UNO will be mounted on a Aerial vehicle and the outputs will be transferred to the base computer using the LoRa module.

OK. That still doesn't reveal what you're doing. What are you going to use this gizmo for when it's done?

tmd3:
You can take the FFT of one input channel, and then the other, and show them simultaneously.

That’s what I want to do

Show the results simultaneously

The Hydrophones- Arduino UNO will be mounted on a Aerial vehicle whose purpose is to float on water, capture sound of underwater mammals and transmit them to the base station. Transmission part is easy as I have tried it with other sensors and it works fine

I tried the FFT library but was not sure if the codes were reading it right

I connected the output from the Pre-Amp to A0 and ran the code

The connections

The FFT codes

/*
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
}
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/2; j++) {
Serial.print(j);
Serial.print(" ");
Serial.println(fft_log_out[j]);
}
}
}

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.