Teensy 4.0 FFT assistance for non-periodic burst signal

fe7565

Member
Long story short... After a couple of weeks of failures using a nRF52 and Arduino IDE trying to measure a 10us to 800us varying length "non-periodic" radar signal from a nerf/bow chronograph...I decided to buy a Teensy 4.0 and the Teensy Audio Adapter...and got it working on the first try! (only at 2 Khz period so far)

I used the Teensy Example -> Audio > Analysis -> FFT example code. I added rudimentary "dominant frequency" to the results, but I wonder, if there is already another Teensy FFT example out here that has some sort of an averaged dominant frequency? Also, I would like to change the 44100Hz sampling rate to maximum and also the ADC sampling rate to maximum. I think I need to dig into the Teensy Arduino libraries support files (h, cpp) to change those, but wondering what are the maximum FFT sampling rate frequency and sampling bin size settings the CPU and the ADC that still provide stability?

The example code works fine with the Audio Adapter, but would like to use the Teensy 4 pins directly eventually. So far I slightly modified an old beta code I found here posted by Paul...that uses FFT without FFT-Window. Based on my tests in Audacity with an actual radar signal I recorded, a "rectangular" FFT window would work the best and at 4096 samples. For the fastest period of signal length I expect, 10us. So, I would need an ADC setting that is able to sample at 2.5 x 100 Khz = 250 Khz rate.

I read this and watched the video as well: https://forum.pjrc.com/index.php?threads/need-help-understanding-fft-bins.56820/

Signal example:
5-3.3v - Copy.jpg



Code:
//teensy 4.0  gives you FFT of an audio signal on analog pin A2/ pin 16
//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

#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() {
float domfreq;
  float n;
float majorpeak=0;

  if (fft1024_1.available()) {
    for (int i=0; i < 60; i++) {  // print the first 60 bins to 2580 Hz from a max of 22Khz.
    n = (fft1024_1.read(i));
    if (n >= 0.01) {
      if (n > majorpeak) {
        majorpeak= n;
        domfreq = (i*43.0664);

           }
          Serial.print(n); Serial.print("<");Serial.print(i*43.0664);  Serial.print("Hz ");
       }  else {
        Serial.print("     -     ");
       }
    }
    Serial.print(domfreq,2), Serial.println("Hz |");majorpeak=0;domfreq=0;
  }
}
 
Last edited:
Thank you very much! (Just noticed your reply, I did not receive a notification like supposed to automatically)

Let me review your link on the 500 kHz ADC for Teensy.

Zero-crossing is one option that seems doable since the signal is clean and does not exceed more than about 30 wave cycles. But before processing , likely will need to toss out some of the first and last readings (that are far off upon the signal ramping up and settling down). I think zero-crossing (+1.6V on 3.3V scale) or threshold-triggered (+2.5V on 3.3V scale) would make it easier to sample since it uses CPU timers that can run much faster than ADC. Maybe do an FFT on the results of the zero-crossing instead of averaging them? The number of readings (data points) should be between 10 and the max of 30.

I need to research "instantaneous frequency", have not heard of that before. I need to wrap my head around this concept before I can compare its advantages vs FFT and zero-crossing in my particular application. https://www.rp-photonics.com/instantaneous_frequency.html
 
Last edited:
About instantaneous frequency: I was working with it several years ago and only vaguely remember the details. I think in theory it works only under the assumption that you have one frequency component, i.e. one sine signal to analyse. Not sure what happens with less strictly filtered signals. Using a gammatone filterbank is a known method for frequency analysis (and also synthesis) - maybe this keyword helps in addition.
 
Back
Top