fft1024 with smaller delta-F bins (decimate? run ADC slower?)

Status
Not open for further replies.

JBeale

Well-known member
I'm playing with Teensy again after some time away. I'm just getting into the amazing audio library- it's very impressive. I'm using the built-in ADC for the input signal. The AudioAnalyzeFFT1024 is almost, but not quite what I want:

"Compute a 1024 point Fast Fourier Transform (FFT) frequency analysis, with real value (magnitude) output. The frequency resolution is 43 Hz, useful detailed for audio visualization."

The signal I'm interested in (from the ultra-cheap HB100 doppler microwave sensor) has useful output signals down below 10 Hz for slowly moving objects. This particular device runs at 10.525 GHz and the output frequency for a given velocity is (f/31.37) mph. For example a walking speed at 3 mph gives you a 94 Hz output. If your FFT resolution is 43 Hz, that means your speed bins are 1.4 mph wide and it is hard to resolve slower-moving objects as they all fall into the [0] bin (DC term). So I'd like to run the ADC at least 4x more slowly, say 11 kHz instead of 44.1 kHz if that's what it is at now. Is that possible, and if so how? If the ADC sample rate is too linked into the design to change, can I somehow decimate the input 4x before the FFT? (I'm fine with a kludgy hack inside the library, if that's possible.) Thanks for any hints!
 
changing ADC frequency

Thanks Frank B, that looks great! I think I do not understand what to do with it though. For example, would you expect the code below to work?
It works as-is at the standard audio rate, but if I uncomment the setDACFreq(44100) line to change frequency, then it does not work, meaning nothing is printed after the initial header line, so I presume myFFT.available() never becomes true.

Code:
#include <Audio.h>

AudioInputAnalog         adc1;       
AudioAnalyzeFFT1024      myFFT;
AudioConnection  patchCord1(adc1, myFFT);

void setDACFreq(int freq) {
const unsigned config = PDB_SC_TRGSEL(15) | PDB_SC_PDBEN | PDB_SC_CONT | PDB_SC_PDBIE | PDB_SC_DMAEN;
    PDB0_IDLY = 1;
    PDB0_MOD = round((float)F_BUS / freq ) - 1;    
    PDB0_SC = config | PDB_SC_LDOK;
    PDB0_SC = config | PDB_SC_SWTRIG;
    PDB0_CH0C1 = 0x0101;    
}

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.println("# Doppler Microwave FFT on Teensy 3.1  5-AUG-2017");
  AudioMemory(12);
  myFFT.windowFunction(AudioWindowHanning1024);
  //  setDACFreq(44100);  // This line seems to prevent things working
} 

void loop() {
  if (myFFT.available()) {
    Serial.println(myFFT.read(2));
  } 
}
 
Hm, let me take a look tomorrow, it's to late now (0:18 am)
At a first glance it should work, but I suppose I overlook a trifle.
 
Hm, just tried it, because i wanted to know...
Your sketch works for me (with setDACFreq(11025); too), if I set the Teensy-speed to 120MHz.

more tomorrow.
 
forget the 120MHz., tested with my T3.6 ... tired now.. somehow the delay(1000); before setting the frequency is a problem.
not totally sure, why..

good night ;)
 
Last edited:
Thank you very much for testing this. It is a mystery, I tried exactly your code at 120 MHz and 96 MHz on my T3.6 and it works OK if I comment out setDACFreq(11025); but does not work with it (just prints the first line of text and stops). Also tried T3.5 and T3.2 and it is the same. I am using the latest toolchain as far as I know, which is Arduino 1.8.3 and Teensyduino 1.38 beta 2.

EDIT: Aha! It DOES work on T3.6 at 72 MHz. But not T3.5 at 72 MHz, or T3.2 at 48 MHz so as far as I know, only that one device at that one clock speed.
 
Last edited:
Found it.
Code:
void setDACFreq(int freq) {
const unsigned config = PDB_SC_TRGSEL(15) | PDB_SC_PDBEN | PDB_SC_CONT | PDB_SC_PDBIE | PDB_SC_DMAEN;
    PDB0_SC = 0; [COLOR=#ffa500]//<--add this line[/COLOR]
    PDB0_IDLY = 1;
    PDB0_MOD = round((float)F_BUS / freq ) - 1;    
    PDB0_SC = config | PDB_SC_LDOK;
    PDB0_SC = config | PDB_SC_SWTRIG;
    PDB0_CH0C1 = 0x0101;    
}

Simply setting PDB0_MOD might be OK, too.
Please note that PDB0_MOD = round((float)F_BUS / freq ) - 1; can't give you every exact frequency. Play a bit with it.
 
Last edited:
I confirm this new sample-rate change code works on a T3.2 at 96 MHz. Exactly what I wanted; thank you!
 
Status
Not open for further replies.
Back
Top