Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

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

  1. #1
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    593

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

    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!

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,587
    https://forum.pjrc.com/threads/38753...he-sample-rate

    For the ADCs, read post #10 - it is the same as for the DAC

    pretty easy
    Last edited by Frank B; 08-05-2017 at 10:05 PM.

  3. #3
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    593

    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));
      } 
    }

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,587
    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.

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,587
    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.

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,587
    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 by Frank B; 08-06-2017 at 09:21 AM. Reason: removed wrong code

  7. #7
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    593
    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 by JBeale; 08-06-2017 at 04:02 AM.

  8. #8
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,587
    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; //<--add this line
        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 by Frank B; 08-06-2017 at 09:20 AM.

  9. #9
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    593
    I confirm this new sample-rate change code works on a T3.2 at 96 MHz. Exactly what I wanted; thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •