Problem getting FFT to work (though it worked earlier this week)

Status
Not open for further replies.

Davidelvig

Well-known member
I'm struggling - hopefully with something simple.
I had a more complex FFT implementation going with an analog microphone, but now myFFT.available() is always returning false.
I backed off to the most stripped-down code I can find from File\Examples\Audio\Analysis\FFT.
I opted for the AudioSynthWaveformSine object to eliminate peripherals.

With the following code, I only get "FFT not available" on the console

Thanks in advance.

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioSynthWaveformSine sinewave;
AudioAnalyzeFFT1024 myFFT;
AudioOutputI2S audioOutput; // audio shield: headphones & line-out

// Connect synthesized sine wave
AudioConnection patchCord1(sinewave, 0, myFFT, 0);

void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(12);

// Configure the window algorithm to use
myFFT.windowFunction(AudioWindowHanning1024);

// Create a synthetic sine wave, for testing
// To use this, edit the connections above
sinewave.amplitude(0.8);
sinewave.frequency(1034.007);
}

void loop() {
float n;
int i;

if (myFFT.available()) {
// each time new FFT data is available
// print it all to the Arduino Serial Monitor
Serial.print("FFT: ");
for (i=0; i<40; i++) {
n = myFFT.read(i);
if (n >= 0.01) {
Serial.print(n);
Serial.print(" ");
} else {
Serial.print(" - "); // don't print "0.00"
}
}
Serial.println();
}
else {
Serial.println("FFT not available");
}
}
 
It is printing so fast that you can't see anything except the "FFT not available".
Try changing the end of your code from this:
Code:
Serial.println();
}
else {
Serial.println("FFT not available");
}
}
to this:
Code:
    Serial.println();
    delay(5000);
  }
  else {
//    Serial.println("FFT not available");
  }
}


Pete
 
Same result with this near the top of the code
I used an audioOutputAnalog.


//
AudioSynthWaveformSine sinewave;
AudioAnalyzeFFT1024 myFFT;
AudioOutputAnalog audioOutput; // audio shield: headphones & line-out

// Connect synthesized sine wave
AudioConnection patchCord1(sinewave, 0, myFFT, 0);
AudioConnection patchCord2(sinewave, 0, audioOutput, 0);

Now, I have nothing connected to the DAC
 
I'll try to reconstruct the actual analog microphone app... and doing something with the FFT - and assure that there's a little delay before iterations!
 
Still stuck... though further along.
I've put code that with with the #define OPTION_1 line, and fails without it.
Something with my use of the AudioInputAnalog


#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

// Comment the following line out, and the myFFT.available always returns false
#define OPTION_1

#ifdef OPTION_1
AudioSynthWaveformSine sinewave;
#else
AudioInputAnalog audioInput(A4);
#endif

AudioAnalyzeFFT1024 myFFT;
AudioOutputAnalog audioOutput;

#ifdef OPTION_1
AudioConnection patchCord1(sinewave, 0, myFFT, 0);
AudioConnection patchCord2(sinewave, 0, audioOutput, 0);
#else
AudioConnection patchCord3(audioInput, 0, myFFT, 0);
AudioConnection patchCord4(audioInput, 0, audioOutput, 0);
#endif

void setup() {
Serial.begin(9600);
AudioMemory(12);
#ifdef OPTION_1
sinewave.amplitude(0.8);
sinewave.frequency(1034.007);
#endif
myFFT.windowFunction(AudioWindowHanning1024);
}

void loop() {
float n;
int i;

if (myFFT.available()) {

#ifdef OPTION_1
Serial.print("FFT1: ");
#else
Serial.print("FFT2: ");
#endif

for (i=0; i<40; i++) {
n = myFFT.read(i);
if (n >= 0.001) {
Serial.print(n);
Serial.print(" ");
} else {
Serial.print(" - "); // don't print "0.00"
}
}
Serial.println();
}
else {
Serial.println("FFT not available");
}
delay(100);
}
 
Another piece... and maybe the kicker... I had changed Tools\CPU Speed from 96 to 72.
When I switched is back to 96... it works.
Dang... I thought slower would be safer.
Are there some clock-specific dependencies?
 
I click QUOTE button and change the "QUOT" to "COD" (on both ends) when I add code in normal edit.
 
Last edited:
I click QUOTE button and change the "QUOT" to "COD" (on both ends) when I add code in normal edit.
lol, I spose I type too fast: I just type [code]CODE HERE[/code] and, for anyone interested, I get the PHP to ignore it by wrapping the whole thing with [noparse] pseudo-tags (an unmatched tag will just display but to show the closing tag noparse is required).
 
I can type fast - but prone to errors - and w/highlighted code puts the QUOTE tags in the right place, and writing that parses without explaining wrong case
Code:
 - half dozen of one and sqrt(36) of the other.
 
All appears to be working here.
I have the Audio library working for audio sampling to an FFT, presumably on ADC_0 (it's default settings.)
I'm using the ADC library, e.g.
Code:
adc->analogRead(A2, ADC_1);
to get an analog value in each iteration of loop().
No troubles!

Im converting from Arduino's 10-bit analogRead().
Looks like the adc->analogRead() is a 16 bit value.

This is my first forum foray - is there a need to "close" threads when solved?
 
You can check 'Thread Tools', towards right of light grey bar just under the main thread title, for 'mark thread as solved' (or some similar) and click it if it is there in the installation of this forum
 
No such luck in this thread for me. Thread Tools has three options - show printable version, email, and unsubscribe.
I'll leave it hanging.
 
Status
Not open for further replies.
Back
Top