FFT on Teesy 4?

An FFT bin width is fs/N, where fs is the sampling rate, and N is the number of points in the FFT.

Thus with 44.1kSPS and 1024 point FFT the bin width is about 43Hz. Thus 0..20 covers 0..860Hz

Note that you will need to choose a suitable FFT window, the Hann window (AudioWindowHanning1024)
is a good default to choose unless you need accurate measurements, which requires a flattop window.
You always seem some spreading of signal to adjacent bins, to an extent depending on properties
of the window, this is unavoidable(*). Without a window you get far worse behaviour if the signal is
not synchronized to the sample clock exactly - basically you must use a window for what you are doing.

(*) Thus that 43 Hz resolution is optimistic...
 
Here is a program which will run on Teensy 4.0 using 1.52-beta4 and gives you FFT of an audio signal on analog pin A2.

...

This will work without the audio shield present, but I2S output (or any other I/O object that causes the library to update) is currently required. Future versions will remove this requirement. Please understand this ADC audio code is very new and still has many minor issues. But at least you can see we're making progress towards ADC input for audio.

One of those many minor issues is the level. A full scale waveform on the ADC pin does not yet map to a full scale signal coming into the audio library. Removal of DC offset also isn't working well yet.

It is now 20 months later - is all the above still the case? It seems to be, as I can't get an FFT audio signal without AudioOutputI2S, and even then what signal I do get seems to be miniscule compared to the same code running on a Teensy 3.2. What can I do to get comparable behaviour to the Teensy 3.2?
 
What other i/o cause the output to be updated

Here is a program which will run on Teensy 4.0 using 1.52-beta4 and gives you FFT of an audio signal on analog pin A2.

Code:
#include <Audio.h>

// GUItool: begin automatically generated code
AudioInputAnalog         adc1;           //xy=197,73
AudioAnalyzeFFT1024      fft1024_1;      //xy=361,47
AudioOutputI2S           i2s1;           //xy=378,99
AudioConnection          patchCord1(adc1, 0, i2s1, 0);
AudioConnection          patchCord2(adc1, 0, i2s1, 1);
AudioConnection          patchCord3(adc1, fft1024_1);
AudioControlSGTL5000     sgtl5000_1;     //xy=265,161
// GUItool: end automatically generated code

void setup() {
  AudioMemory(30);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  while (!Serial) ; // wait for Arduino Serial Monitor
  Serial.println("FFT test");
}

void loop() {
  if (fft1024_1.available()) {
    for (int i=0; i < 20; i++) {  // print the first 20 bins
      Serial.print(fft1024_1.read(i), 3);
      Serial.print(" ");
    }
    Serial.println();
  }
}

This will work without the audio shield present, but I2S output (or any other I/O object that causes the library to update) is currently required. Future versions will remove this requirement. Please understand this ADC audio code is very new and still has many minor issues. But at least you can see we're making progress towards ADC input for audio.

One of those many minor issues is the level. A full scale waveform on the ADC pin does not yet map to a full scale signal coming into the audio library. Removal of DC offset also isn't working well yet.

I am attempting to use this fix on a teensy 4.1 using an OCTOWS2811. That board requires the use of DMA channels 1,2,3. The i2s1 fix above uses DMA channels 1 and 2. Are there any other possible I/O objects that I can use to force the library to update the ADC input that don't use DMA channels 1,2, or 3?

Thank!
 
Back
Top