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

Thread: T3.2 with FFT improves performance of cheap doppler radar

  1. #1

    T3.2 with FFT improves performance of cheap doppler radar

    Here's a use of the audio library for a non-audio purpose.

    You can buy a HB100 doppler radar module for well under $5 at the usual auction sites. This sort of thing is used for automatic door openers with short range, say 10 feet. The HB100 has a mV-level baseband IF output, which I boost with a x660 opamp circuit (OPA209A) and 0.1 uF cap directly into the Teensy 3.2 pin 16 (A2). The output is a frequency proportional to target speed: Frequency (Hz) / 31.37 = Speed (mph). I use the audio library's FFT1024 object to select out just my walking speed which is 2.2 mph, which means a signal near f=70 Hz. That, plus a crude aluminum-foil-and-cardstock horn for directivity, allows a pedestrian-detection range of 80 feet, which is a considerable improvement over the "stock" sensor (esp. given radar signals drop as 1/r^4). Many thanks to Frank B for the code to cut the ADC sample rate x4 for smaller frequency bins, and neutronned for the example code I modified.

    The plot below shows the 2.2 mph frequency channel as I walk directly away from the sensor out to 80 feet, then immediately return the same way.
    Click image for larger version. 

Name:	HB100-Walking.jpg 
Views:	205 
Size:	62.3 KB 
ID:	11178

    Click image for larger version. 

Name:	HB100-horn.jpg 
Views:	94 
Size:	204.2 KB 
ID:	11179

    Code:
    // FFT to select freq. bins from signal on Teensy 3.2 pin A2 (ADC input)
    // Set OUT_ALARM pin high if signal in some freq. bins over threshold
    // Thanks to Teensy forum users: neutronned and Frank B.
    
    #include <Audio.h>
    
    AudioInputAnalog         adc1;       
    AudioAnalyzeFFT1024      myFFT;
    AudioConnection  patchCord1(adc1, myFFT);
    
    #define A_GAIN (5.0)    // gain applied to analog input signal
    #define THRESH (0.5)    // threshold above which "movement" detected  
    #define LED1 (13)       // onboard signal LED
    #define OUT_ALARM (3)   // alarm signal (motion detected)
    #define CPRINT (12)      // frequency bins (columns) to print
    
    float level[16];  // frequency bins
    float alarm;
    static float fa = 0.10;  // smoothing fraction for low-pass filter
    int loops = 0;   // how many times through loop
    boolean motion = false;  // if motion detected
    
    void setDACFreq(int freq) {  // change sampling rate of internal ADC and DAC
    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;    
    }
    
    void setup() {
      AudioMemory(12);
      AudioNoInterrupts();
      setDACFreq(11025);
      myFFT.windowFunction(AudioWindowHanning1024);
      AudioInterrupts();
      
      Serial.begin(115200);
      digitalWrite(LED1, false);
      pinMode(LED1, OUTPUT);
      digitalWrite(OUT_ALARM, false);
      pinMode(OUT_ALARM, OUTPUT);
      digitalWrite(LED1, true);
      digitalWrite(OUT_ALARM, true);
      delay(1000);
    
      Serial.print("min");
      Serial.print(",");
      Serial.print("alm");
      for (int i=0; i<CPRINT; i++) {  // print column headers
          Serial.print(",");
          Serial.print("f");
          Serial.print(i);
      }
      Serial.println();
      Serial.println("# Doppler Microwave FFT on Teensy 3.1  5-AUG-2017");
      digitalWrite(LED1, false);  digitalWrite(OUT_ALARM, false);
      
    } // end setup()
    
    void loop() {
      if (myFFT.available()) {
        level[0] = ((1.0-fa)*level[0]) + fa * myFFT.read(0) * 0.5 * A_GAIN;
        level[1] =  ((1.0-fa)*level[1]) + fa * myFFT.read(1) * 1.5 * A_GAIN;
        level[2] =  ((1.0-fa)*level[2]) + fa * myFFT.read(2) * 2 * A_GAIN;
        level[3] =  ((1.0-fa)*level[3]) + fa * myFFT.read(3) * 3.5 * A_GAIN;
        level[4] =  ((1.0-fa)*level[4]) + fa * myFFT.read(4, 5) * 5 * A_GAIN;
        level[5] =  ((1.0-fa)*level[5]) + fa * myFFT.read(6, 8) * 7 * A_GAIN;
        level[6] =  ((1.0-fa)*level[6]) + fa * myFFT.read(9, 13) * 9 * A_GAIN;
        level[7] =  ((1.0-fa)*level[7]) + fa * myFFT.read(14, 22) * 11.0 * A_GAIN;
        level[8] =  ((1.0-fa)*level[8]) + fa * myFFT.read(23, 40) * 15 * A_GAIN;
        level[9] =  ((1.0-fa)*level[9]) + fa * myFFT.read(41, 66) * 15 * A_GAIN;
        level[10] = ((1.0-fa)*level[10]) + fa * myFFT.read(67, 93) * 18 * A_GAIN;
        level[11] = ((1.0-fa)*level[11]) + fa * myFFT.read(94, 131) * 10 * A_GAIN;
        alarm =  level[1] + level[2] + (2*level[3]) + (2*level[4]);
    
        if (alarm > THRESH) {
          motion = true;
          digitalWrite(OUT_ALARM, true);
        } else {
          motion = false;
          digitalWrite(OUT_ALARM, false);
        }
        
        if ( ((loops++)%10 == 0) ) {
         Serial.print((float)millis()/60000.0);
         Serial.print(",");
         Serial.print(alarm);    
         for (int i=0; i<CPRINT; i++) {
          Serial.print(",");
          Serial.print(level[i]);
         }
         Serial.println();
        }
      }
    } // end main loop()

  2. #2
    Senior Member Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    3,935
    Just bought two..

  3. #3
    Senior Member Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    3,935
    can you show us the schematic ?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    14,869
    The other thread, in case anyone finds only this thread and wants to make the same audio lib sample rate mod...

    https://forum.pjrc.com/threads/45610...n-ADC-slower-)

  5. #5
    Senior Member
    Join Date
    Jul 2014
    Location
    New York
    Posts
    368
    Could never get the one I had working right. Still have it laying around someplace - thankyou. By the way if you don't want to mess with the circuitry - https://www.tindie.com/products/limp...no-compatible/

  6. #6

    opamp preamp circuit for HB100

    Hi Frank, the circuit I used is shown below. You can use any opamp you like. I chose the OPA209A as it works on +5V and is low noise, although comes in SO-8 so I had to use an adaptor for my solderless breadboard. I am running the HB100 + opamp on a separate 4xAA NiMH "5V" supply to reduce noise. The Teensy runs off a noisy USB +5V and you see there is a 2.2k resistor connecting the circuit grounds. I found that if I connect the USB ground direct to the opamp ground I saw much more noise. This is just a quick prototype and I need to think about how to make one +5V power supply clean enough for both circuits.

    I used the TI TLE2426 3-terminal "rail splitter" device just to generate the +2.5V common from the +5V supply. You could also do this with resistors etc.

    EDIT: Schematic not quite right; I first tried a gain of 67.7, but then changed the 1.5k to 150 ohms for a gain of 673.

    EDIT2: I added an actual-size PDF Horn-118x90.pdf of the horn antenna pattern that I used (occupies a full 8.5x11 sheet of paper.) I folded and taped cardstock, then put Al foil on the outside and wrapped fully around the back. This is a truncated pyramid with 118 x 90 mm open end, and just fitting the 45x37 mm HB100 PCB on the smaller end. The angles and dimensions of the horn aren't critical. You don't really need it at all, but if you use a high opamp gain for longer range as I did, without some kind of reflector you'll get a lot of pick up of motion to the side and behind the sensor as well as in front.

    For example, one location I had in mind was on the front porch, to detect people coming up the walkway. In that case you don't want it to trigger on people moving inside. I found the microwave signal does go right through a wood door unless there's some kind of reflector behind it.

    Click image for larger version. 

Name:	Updated-Preamp-Circuit.jpg 
Views:	312 
Size:	110.9 KB 
ID:	11188Click image for larger version. 

Name:	20170806_103458.jpg 
Views:	70 
Size:	186.5 KB 
ID:	11183
    Last edited by JBeale; 08-07-2017 at 04:25 PM. Reason: add PDF of horn antenna

  7. #7
    Member
    Join Date
    Jan 2017
    Location
    Pella, Iowa, USA
    Posts
    64
    I'm going from memory but isn't the gain for a non-inverting op-amp 1 + Rf / Rin = 1 + 100K / 1.5K = 67.66. Can someone check my math??

    I like that little virtual ground part!! Gotta play with that!

    Great project!!

  8. #8
    Your formula is quite right. I actually had two versions of the project, and I confused them. At first I used 1.5k as Rin but decided I could do better with more gain, so boosted the gain 10x with Rin = 150 ohms. So the gain is (about) right, but I mislabeled the resistor. I edited the previous post to show the corrected schematic.

    NOTE
    to anyone trying this out: I also added the PDF of the horn antenna I made. If you don't add something like this, you'll get a fair amount of pickup off the back side of the device, not just the front.
    Last edited by JBeale; 08-07-2017 at 06:00 AM.

  9. #9

    addendum: plots of other frequency bands

    By the way: given the radar range equation says return signal should go as 1/r^4, you may question why my plot looks more linear with distance. I'm wondering that too. If you look at the other frequency bands they are each different, but mostly tend toward a much steeper-than-linear falloff with distance. The upper-left plot "alm" is a linear combination of the first four frequency bins. Might be fun to make an algorithm to look at all the channels, and try to optimize SNR for detecting pedestrians at various distances, cars etc.

    Click image for larger version. 

Name:	FFT-bands-walking.jpg 
Views:	143 
Size:	207.6 KB 
ID:	11189

  10. #10
    Administrator Robin's Avatar
    Join Date
    Oct 2012
    Location
    PJRC Global Headquarters
    Posts
    244
    I just posted about this project on the home page.
    https://www.pjrc.com/low-cost-doppler-radar/

  11. #11
    Thanks Robin! I'm embarrassed by that photo of my crude hack job with the cardboard & foil antenna though :-). I guess it does make the point that "anyone can make a horn antenna"!

    I got some sheets of 0.11" copper-clad PCB thin enough to cut with regular scissors, so I can move the construction at least a small step up. If anyone's interested it's
    http://www.ebay.com/itm/8-pcs-8-x-12...B/311863099295

  12. #12

    horn made out of PCB laminate sheets

    Made a new horn antenna from thin FR4 copper-clad. Was able to tape up the back with copper foil more tightly and the whole assembly is more rigid, so this one doesn't detect a hand waving right behind it, where the aluminum-foil version would. Otherwise performs about the same in the forward direction. Aesthetically looks better I think. The HB100 board is just taped with a few pieces of copper tape flat against the bottom inside the horn.

    Click image for larger version. 

Name:	HB100-horn-T32.jpg 
Views:	299 
Size:	74.4 KB 
ID:	11199
    Last edited by JBeale; 08-08-2017 at 03:35 PM.

  13. #13
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    14,869

  14. #14
    Senior Member
    Join Date
    Jul 2014
    Location
    New York
    Posts
    368
    JBeale. Nice job congratulations. Any guidelines on designing the horn?

  15. #15
    Quote Originally Posted by mjs513 View Post
    JBeale. Nice job congratulations. Any guidelines on designing the horn?
    Here's the horn I made: Horn-118x90.pdf however I think nothing about it is particularly critical. You can choose a different size and different opening angles, and it will still more-or-less work. That particular horn is a scaled-down version from a design I found online for amateur radio astronomy at a longer wavelength: http://www.setileague.org/articles/horn.htm

    I'm no expert on horn theory. I seem to remember the far-field pattern is 20 dB down (?) at the flare angle of the horn, but then you may have any number of sidelobes nearly as large as the main lobe, depending on the horn length in wavelengths, and various other details.

    Usually you have a single feed point at the apex of the horn. In this case with the HB100 board you have two separate dual patch antennas for Tx and Rx, one on each side of the board. So I wasn't sure how the horn would work with this arrangement, but it still does work.

    I don't know what the exact antenna pattern is. I don't have any microwave gear besides the HB100 but I now have a few more parts on order in hopes of being able to measure the antenna pattern at least in a qualitative way.
    Specifically http://www.ebay.com/itm/New-AD8317-1...s/311857360564 although I then found the chip is only intended for use through 8 GHz and only "sort of" works out to 10 GHz. We'll see if 10.525 GHz works at all. Maybe the best test is just recording the response while panning the antenna across a distant spinning or vibrating metal target, I've been thinking how to set that up.
    Last edited by JBeale; 08-10-2017 at 10:59 PM.

  16. #16
    Senior Member
    Join Date
    Jul 2014
    Location
    New York
    Posts
    368
    Thanks for the response. I was playing around with this module a couple of years back and had it breaded board up and then found the breakout board for it on tindie. It worked sort of... Never even dawned on me to run it through a fft. Now I have to break it out again and start fiddling with it again.

    Mike

  17. #17
    Here's a tip, if you want any decent range you cannot use a switching power supply, only a linear regulator or even better a battery. It basically doesn't work at all if you try to use a regular 5 volt USB supply. The super simple HB100 circuit has sub millivolt output and just about no power supply rejection, so switcher noise dooms your signal.

    Also: note both HB100 and CDM324 have some DC bias on the IF output. Neither will survive accidentally connecting +5V to the output pin.
    Last edited by JBeale; 08-11-2017 at 02:12 PM. Reason: cautionary note after I destroyed my CDM324

  18. #18
    Handle with care. In case of interest, after I blew up my CDM324 by applying +5V to the IF Out pin, I had a look inside: https://goo.gl/photos/ZZeaj7dLyfe7ahLo7 I note the PCB is actually marked IDM136
    Last edited by JBeale; 08-11-2017 at 04:20 PM.

Posting Permissions

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