Shop OBEX P1 Docs P2 Docs Learn Events
Goertzel for Object detection? — Parallax Forums

Goertzel for Object detection?

Christof Eb.Christof Eb. Posts: 1,106
edited 2022-10-07 10:17 in Propeller 2

Hi,
are there ways to use the goertzel mode to detect objects or distance to objects?

  1. Perhaps goertzel could be used to use a modulated light source together with an LDR or photo diode?
  2. Perhaps goertzel could be used with a coil to make an inductive sensor somehow?

I have seen that Goertzel uses LUT. Can I still use this mode together with the FlexProp C compiler?

Are there examples other than the ultrasonic quick byte?

Thanks for any hints!
Christof

Comments

  • Goertzel is good for everything where you need to measure phase and/or amplitude of an HF or Audio signal. Optical time-of-flight (TOF) distance measurements might be hard unless the distance is multiple meters because light travels at ~30cm/ns, so 200MHz gives you only ~1m resolution.

    Some examples (not TOF related, though):
    https://forums.parallax.com/discussion/173758/phase-shift-keying-and-goertzel
    https://forums.parallax.com/discussion/173656/goertzel-example-linear-position-sensor

  • There will be some noise in the circuit and your measurements will all be around some center value, but not quite. If you build a histogram of all samples over - let's say - a 1 second timeframe and further fit a gaussian curve inside the histogram, you have a good chance that your center value is much closer to the real distance. it would be quite interesting to see if that works

  • cgraceycgracey Posts: 14,133
    edited 2022-10-08 01:17

    Here is a video of the Goertzel outputting ultrasound through a transducer and then picking it up on another transducer:

  • cgraceycgracey Posts: 14,133
    edited 2022-10-08 01:18

    Here is a video of the Goertzel outputting four phases of an RF signal and then picking it up on another pin:

  • Thanks for your input!
    Would it be worth trying to drive a LR circuit with a sine or digital frequency voltage and measure the current as the voltage at the R with goertzel to get an inductive sensor?

  • cgraceycgracey Posts: 14,133

    @"Christof Eb." said:
    Thanks for your input!
    Would it be worth trying to drive a LR circuit with a sine or digital frequency voltage and measure the current as the voltage at the R with goertzel to get an inductive sensor?

    I don't know. I'd have to really think about it.

  • Have a sneak peak of my Goertzel library for flexspin. It should be usable from Flexprop C.

     goertzel.set_freq(50_000) 
     repeat 
    
       x,a := goertzel.main(PIN_EXP, PIN_EXN , PIN_ISENSE , -1) 
       i := goertzel.mv_i()
       q := goertzel.mv_q()
    
  • cgraceycgracey Posts: 14,133

    Saucy, do you know if time-of-flight measurements might be possible using the Goertzel, where an output pin drives an LED and an input pin is connected to a photodiode? I am thinking that TOF measurements could show up through small phase changes. What do you think?

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2022-10-09 05:28

    I am thinking that TOF measurements could show up through small phase changes.

    I totally agree. But you don't need Goertzel or sine waves or even a P2 to do this. The P1 is fully capable of resolving phase differences using its counters configured as an I/Q detector. The really tricky part lies in designing the optics and electronics. You need an LED driver that works in the high MHz range and an amplified photodiode with minimal rise and fall times. Next are the lenses required to create a parallel beam from the transmitter and to focus a narrow return to the receiver.

    -Phil

  • cgraceycgracey Posts: 14,133

    Phil, I was looking at some work I believe you did a while back on the P1 for time-domain reflectometry. You used a PLL because it would sweep randomly against the system clock and create slight IN state delays which could be counted over many cycles. On the P2, pins can be made into unclocked oscillators which will have the same kind of behavior for TDR purposes.

  • "...photodiode with minimal rise and fall times..." - The Miller effect is what usually kills the rise and fall times. One trick to greatly reduce this effect is to operate the photo-diode or photo-transistor in reverse bias mode where your actually looking at the component as a capacitor across the reversed PN junction and the "leakage" is proportional to the amount of IR light that falls upon it resulting in a detectable signal.

    Note: The concept is very similar to being able to use a standard LED as a light detector.

    Reference:
    https://circuitcellar.com/resources/quickbits/miller-effect/

  • It's hard enough to run 1MHz through an optocoupler. The ADC works best below 5 MHz and is 10 dB down at 15MHz. If we only care about phase and not amplitude we could use the pin in digital mode. The TOF distance test might be interesting once the library is more complete. It will all depend on how precise the phase can be measured. It will be hard as any nonlinearity in the detector circuit could result in a phase shift proportional to amplitude.

    I'm not sure but I think an inductive sensor will only sense metal or conductive objects.

    It should be able to detect objects as a capacitive sensor.

  • @cgracey said:
    Saucy, do you know if time-of-flight measurements might be possible using the Goertzel, where an output pin drives an LED and an input pin is connected to a photodiode? I am thinking that TOF measurements could show up through small phase changes. What do you think?

    Hi, I was thinking way simpler.
    For a digital sensor input.
    I am using a ir reflection sensor for my current project. When the sun lights the room, the sensor's threshold shifts leading to fault signals. So it would be perhaps a good solution, if a AC amplitude voltage threshold could be used instead of DC threshold. The ir led could be modulated with 100 (???) kHz. I think just a digital 100kHz on off signal should be good enough. Something like the 37kHz remote control sensors.
    Christof

  • First question should always be: What are the requirements? What range and precision do you expect?

    For small distances <1m there are ready-to-use commercial LIDAR or ultrasonic sensors available for little money. If you need more precision there are industrial fluid level sensors. However if you need longer distances thing become expensive and it could be worth it building something on your own.

  • Christof Eb.Christof Eb. Posts: 1,106
    edited 2022-10-13 13:34

    @ManAtWork said:
    First question should always be: What are the requirements? What range and precision do you expect?

    For small distances <1m there are ready-to-use commercial LIDAR or ultrasonic sensors available for little money. If you need more precision there are industrial fluid level sensors. However if you need longer distances thing become expensive and it could be worth it building something on your own.

    In my last post I wrote about a digital yes no object detection with a threshold. Non touching switch. Detect a tooth of a plastic wheel.
    Reflexlichtschranke.
    Distance 5....20mm. Object size 5mm. Speed 10kHz. Repeat lateral 0.3mm.
    Fun project. Low cost.

    As far as I understand, the Goertzel can be used to measure a AC voltage of a selectable frequency, while other controller's adc can only measure DC voltage. Might be useful for all those things with drift?

  • Ok, for this short distance a TOF sensor makes no sense. But I think, the P2 and Goertzel mode cold stil be useful. I'd make an array of capacitive sensors like on this encoder. The teeth of the plastic gear wheel should make a position dependant change in capacitance between the electrodes like the finger does on the Goertzel accessory board.

  • evanhevanh Posts: 15,192

    Time-of-flight using audio will be more conducive to a 20 mm range. We've been successfully using industrial ultrasonic range transducers for measuring hard flat surfaces. Is sensitive to the surface angle though. Works best square on.

  • @"Christof Eb." said:
    Distance 5....20mm. Object size 5mm. Speed 10kHz. Repeat lateral 0.3mm.

    To achieve 10kHz teeth counting speed you need to sample 20,000 times a second, at least. At 100kHz or even 200kHz ultrasonic frequency that would mean the pings (for TOF) have to be extremely short and fast repeating. On the other hand, a capacitive sensor running at 1MHz or higher would have no problems sampling at 20kHz.

    If you want to do it with sound you could try using a lower frequency with a wavelength >20mm, send a continous signal and do only phase measurement instead of discrete pings. But speed of sound = 330m/s divided by 10,000 is only 33mm. 20mm forth and back is 40mm so it's above the physical limit.

    Flood it with water so you have a higher speed of sound. :D

  • I finally used some of the ultrasound transducers I bought 20 years ago to use with the SX microcontroller. I was way in over my head then.

    It's amazing that the P2 can operate ultrasonic transducers with no extra parts. I can't even see the echo on my oscilloscope. There is too much noise there. But with 100x ADC and Goertzel mode, that looks like a strong echo. The 40khz transmit signal is sent for the first 50 cycles on the chart. Then receive continues for 900 more cycles. I use the Goertzel to measure 1 cycle at a time.

    The peak at about 450 suggests that my ceiling is 1.94m away. I can't find my tape measure to verify.

  • @SaucySoliton said:
    Have a sneak peak of my Goertzel library for flexspin. It should be usable from Flexprop C.

    Thank you, for this file, it was very helpful to get to understand all (?) those riddles.
    mov y,0 was one of them....
    Christof

Sign In or Register to comment.