Shop OBEX P1 Docs P2 Docs Learn Events
One sensor to discriminate Walsh-modulated IREDs — Parallax Forums

One sensor to discriminate Walsh-modulated IREDs

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2022-10-27 04:03 in Propeller 1
Almost everyone here is aware of the advantages of modulated IREDs for rejection of background IR fluctuations and line-frequency noise from artificial lighting. Typically, the IRED modulation occurs at 38 kHz, to which the integrated detectors are tuned and respond with a digital output. But what if you wanted to respond to more than one IRED at a time and, moreover, know the intensity level of the response from each? Such a question is the theme of this thread.

First, we need to delve into Walsh functions. Walsh functions are the digital equivalent of the Fourier sine and cosine basis functions for decomposing waveforms into constituent parts. Unlike their sine and cosine counterparts, Walsh functions can take on only two values: -1 and +1. Like the Fourier sine and cosine basis functions, the Walsh basis functions are mutually orthogonal. This means that, over one full cycle, the product of any pair of these functions integrates to zero. Also, as with sine and cosine functions, the average duty cycle of Walsh functions (except for W(1, 1)) is 50%, a desirable characteristic for modulating IREDs with them.

By modulating a set of IREDs, each with a different Walsh function, and using a single analog IR detector, it should be possible to sort out which IREDs the return signal came from, along with how much each one contributed to the response. To this end, I purchased six IREDs from RadioShack and mounted them on a QuickStart board, as shown below:

ir_sensor_top.jpg

I replaced the 100K resistor packs in series with the touchpads with 100-ohm resistor packs, in order to drive the IREDs from the Propeller's P2-P7 pins.

For a sensor, I initially thought an IR phototransistor would work well with a sigma-delta input. Although phototransistors are notoriously slow, in the sigma-delta circuit VCE would be held constant at about Vdd / 2, thus eliminating any slowness due to its Miller capacitance. Unfortunately, even in this circuit, the phototransistor was too slow for detecting modulated signals accurately.

In the end, I purchased an AMS (TAOS) TSL262R-LF, which converts incoming IR to a voltage output and has a very fast response (at the expense of sensitivity). I mounted the sensor to the bottom of the board so as to avoid direct illumination form the rear of the IREDs:

96945.jpg

The output of the sensor (powered from 3.3V) is fed into a DC-coupled sigma-delta ADC, populated on the QuickStart board using SMD resistors and caps. Here's a block diagram:

96944.gif

Each IRED is modulated with a different Walsh function, as shown above. With strong reflections coming from all six Walsh-modulated IREDs, here's what the output from the sensor looks like:

96947.gif

Now for some Propeller counter magic! The feedback output from the sigma-delta counter is combined XOR fashion with the outputs to the IREDs in six different counters, spanning three cogs. Remember that the feedback is a pulse train whose duty cycle is inversely proportional to the signal coming into the input pin. So when the input pin is predominantly high (i.e. the output duty cycle is low) and an IRED pin is high, the XOR counter will add to phsx. The same happens when both the input and IRED output are predominantly low. In other words, the XOR counter for any particular IRED is correlating the input signal from the sensor with the Walsh function driving the associated IRED to tell how much that IRED is contributing to it. Because the Walsh functions are orthogonal, the contributions from the other five signals will, ideally, sum to zero. The result is that each counter demodulates the signal only from its associated IRED.

In the attached program, the IREDs are modulated at 950 Hz (i.e. 1.053 ms for each of the 16 increments in a full Walsh waveform cycle). Each counter is sampled every eight full cycles, with the result of each sample poked into an array. These results can be displayed via the serial output, and they are also used to drive the blue LEDs on the QuickStart board with intensity proportional to the log of the response from each IRED. Here's a video that shows the result:

[video=vimeo;62453123]

Some practical applications of this technique might include crude robotic "vision", where obstacles can be roughly located in the field of view and their distances approximated via the return signal strength. Another app might be a light curtain that uses Walsh modulation instead of physical baffling to isolate the different channels. In any event, it scratched an itch for me, wondering if it would actually work. Apparently, it does!

-Phil

Comments

  • skylightskylight Posts: 1,915
    edited 2013-03-22 14:36
    Just a thought phil never thought of using the inputs like that but instead of soldering to the quickstart buttons maybe an edge connector could be devised out of a pcb for future projects (oldbitcollector?) so the quickstart can be used for other things?

    Any reason for doing it that way rather than using the 40 pin header phil?

    Ah I get it because of the resistor pack you replaced
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-03-22 14:41
    Phil, very clever, again, theory, design, build, test, show.
  • ercoerco Posts: 20,244
    edited 2013-03-22 16:26
    PhiPi, you magnificent fiend, you did it!

    Or as Kramer would say, http://www.youtube.com/watch?v=6CAT4gPzIg8&feature=player_detailpage#t=50s
  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-03-22 17:36
    Amazing.

    And to further rub our faces into it, he does it all with a mere QuickStart board and parts from Radio Shack. Geez!
  • skylightskylight Posts: 1,915
    edited 2013-03-22 17:44
    Amazing.

    And to further rub our faces into it, he does it all with a mere QuickStart board and parts from Radio Shack. Geez!
    There's a lot packed into that little board
  • Martin_HMartin_H Posts: 4,051
    edited 2013-03-22 18:09
    First off, neat project. I've read through this twice and mostly followed it, but I think it needs more soak time.

    Over in the robotics forum I've built several compound eyes using IR LED's coupled with 38khz receivers or phototransistors. When I use the 38khz receiver I use a frequency sweeping technique to determine rough distance coupled with zone sweeping to pinpoint the position of obstacles. I can usually do all that for four zones with a single cog.

    Here you are outputting different frequencies to the zones, but I think at the same time. So while I'm using time to separate my zones, you are using the frequencies of the Walsh functions?

    Update : I read it again and I see how the counters are separating you zones.
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-03-22 20:35
    Phil, I looked at that page on Wolfram and thought, my gosh, how did you get from this to that? I figure you must have started somewhere else. Or maybe you re-originated it and will write up a more accessible description of the math and the generating functions? It can't be too hard, can it?! You crammed the signal generation into 23 pasm instructions and decoding into three instances of a 17 line spin program!

    I like to look at origins of ideas, before they get wrapped up in formalisms. The Wolfram page said these functions had been used by "electrical engineers such as Frank Fowle in the 1890s to find transpositions of wires that minimized crosstalk" so I thought maybe there is something there that would, ring a bell. A search for Frank Fowle reveals that he was the editor of the 1920 edition of the Standard Handbook for Electrical Engineers. Oh, drat, not on my bookshelf.
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-03-22 20:46
    Also, Phil, I see that the phototransistor did not work. But did you try connecting a simple reverse biased photodiode to the sigma-delta input? It's a high-impedance current source for direct integration, very fast, very linear. Can be biased down for greater dynamic range.


    photodiode_sigma_delta.png
    596 x 415 - 23K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-03-22 22:09
    Tracy,

    My interest in Walsh functions dates back to the '70s where there was some vague relationship among them, genetic algorithms, and Gray coding. But the details are too fuzzy at this point in time to recount, except that I remembered them as digital, orthogonal basis functions, and that recollection stuck. The Wolfram link was the best I could find via Google on short notice to explain them further to those who might be unfamiliar with them. It wasn't my starting point, however.

    Truth be known, there are probably better basis functions out there for this app. One problem with Walsh functions is that the phase-shifted versions appear not to be orthogonal with each other. This manifests itself in information "leakage" when the detector is slow to respond. Ideally, a set of basis functions for this app would not only be orthogonal, but "left and right orthogonal." IOW, if you shift the phase one period left or right, between any two basis functions, orthogonality would still be preserved.

    That's why a detector with a fast response became so critical and also why I limited the fundamental frequency to 950 Hz. Any faster and even the 7 usec delay from the TSL262R resulted in spillage into the other demodulators, resulting in crosstalk between channels. CDMA RF transmission suffers the same issues, BTW. To demodulate CDMA, three detectors are used: one centered on-phase, one leading, and one trailing. These are used jointly as a phase detector to lock onto the pseudo-random data pattern. Fortunately, in this app, the phase is already known. So a fast detector is all that's necessary to maintain a "lock" on the signal.

    I had thought of using another IRED as the detector in the photodiode circuit you've shown. But I did not have any 100+ meg resistors lying about for the feedback. :)

    -Phil
  • CuriousOneCuriousOne Posts: 931
    edited 2013-03-23 08:28
    Very interesting approach, thanks. I'm doing almost similar task, but I need greater distance, so I put more effort into increasing range and my setup has working range about 5 meters now. So if you need to get higher range, take look at Linear's appnotes, they provide quite useful schematics for high gain, high speed IR photodiode workout.
  • lardomlardom Posts: 1,659
    edited 2013-03-23 08:41
    Isn't Phil great to have around! I had to buy a book on calculus to help me understand his 'Goertzel Algorithm' app. As weird as this sounds it's OK for me not to be a genius because I'm smart enough to learn from people who are!
  • tritoniumtritonium Posts: 539
    edited 2013-03-23 11:22
    As weird as this sounds it's OK for me not to be a genius because I'm smart enough to learn from people who are!

    Boxcar Function, Cal, Fast Walsh Transform, Hadamard Matrix, Heaviside Step Function, Rectangle Function, Sal, Sequency, Square Wave, Walsh Transform, Hadamard matrix, ceiling function, Thue-Morse sequence ,orthogonal, matrix product , "sequency".....

    Sadly......... I'm not....:frown:


    Dave
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-03-23 12:21
    One thing that helped me to understand this was to skip the theory and look at the Walsh sequences as defined in Phil's code:
    Screen shot 2013-03-23 at 11.53.39 AM.png

    One 16 bit string for each of the 6 LEDs, played back repeatedly in parallel at the fixed period per bit. Pick one string and XOR it with itself or one of the others, writing + when there is a match of bits and - when there is no match. For example, here is the first one with itself:
    1010010101011010
    1010101010101010
    ++++++++++++++++
    16 +'s of course. Averages out in the detector to a maximum positive value. Or, if the detection is weak, there are errors and you get an indication of distance.
    Now the first sequence with the second one:
    1010010101011010
    1010101010101010
    ++++
    ++++
    Averages to zero. And the first with the third:
    1010010101011010
    1001011010010110
    ++--++----++--++
    same, averages to zero. And the fifth sequence with the sixth:
    1100001100111100
    1001100101100110
    +-+--+-++-+--+-+
    Again. That is what it means for the signals to be orthogonal.
  • lardomlardom Posts: 1,659
    edited 2013-03-23 21:19
    tritonium wrote: »
    Boxcar Function, Cal, Fast Walsh Transform, Hadamard Matrix, Heaviside Step Function, Rectangle Function, Sal, Sequency, Square Wave, Walsh Transform, Hadamard matrix, ceiling function, Thue-Morse sequence ,orthogonal, matrix product , "sequency".....

    Sadly......... I'm not....:frown:


    Dave
    I didn't say I understood it. This is really advanced stuff. I clicked on the link too. Everything there was a new concept. The point I wanted to make was that I am a 'student' of the knowledge presented in this forum.
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2013-03-24 05:59
    This is extremely cool, I'd be interested to try using three emitters in a triangle and one sensor in the middle to detect the position of point objects in space.

    Could we use the same algorithm with some ultrasonic transducers?

    Graham
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-03-24 08:17
    Could we use the same algorithm with some ultrasonic transducers?
    Not directly, due to their extremely high Q. I guess one advantage of an IR sensor in this app is that it does not resonate. Although you could amplitude modulate an ultrasonic carrier using Walsh functions (maybe that's what you had in mind), the next problem would be phase-locking the demodulated return signals to the three generative Walsh functions. Multi-path returns would complicate this process even further. In the IR app, I was counting on no phase delay for the returning signal, which makes things way easier.

    For returns with a phase delay, you could modulate the ultrasonic carriers with three different audio frequencies and use an I/Q mixer to demodulate the return signal, followed by FIR filters to select each audio channel.

    -Phil
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2013-03-24 08:21
    Ah yes that makes sense!

    Graham
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-03-24 12:21
    Phil, here you go...
    100Mohm.jpg

    FWIW, Digikey has values up to 50GΩ in stock in SMT 0805 or 1206.

    Your TSL262R gain is 2.8V/µA, followed by a sigma-delta gain of x1. An ordinary photodiode (area comparable to the TSL262R, 1mm2?) might work with 3MΩ feedback directly in the sigma-delta to give those signal levels. Are your 'scope signals coming from a tap off of the feedback pin?
    432 x 182 - 25K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-03-24 12:40
    Tracy,

    I pressed my Ohmmeter probes to the leads in the photo you posted but got 120 megs. That's close enough, though. Thanks! :)

    "Are your 'scope signals coming from a tap off of the feedback pin?"

    No, directly from the sensor (i.e. on the sensor side of the series 100K).

    -Phil
  • LawsonLawson Posts: 870
    edited 2013-03-25 08:45
    Looking at the Wolfram page on Walsh functions, I'm wondering if your errors from phase delays would go away if you only used even or odd Walsh functions? I.e. the W(2,2) and W(2,3) images are the same patterns shifted 90 degrees phase wise.

    Maybe a system more resistant to phase delays would be to sample the delta-sigma at the modulation frequency and demodulate each channel in software? That way delays less than one modulation "bit" period could be hidden? (I think this would need an ADC with a sample and hold circuit.) I bet this could all be done in one cog as an added bonus.

    Lawson
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-03-25 08:52
    Lawson wrote:
    Looking at the Wolfram page on Walsh functions, I'm wondering if your errors from phase delays would go away if you only used even or odd Walsh functions?
    That is, in fact, what I've done, for the very reason you point out. The crosstalk was much worse when mixing SAL and CAL functions.

    -Phil
  • IncVoidIncVoid Posts: 40
    edited 2013-03-27 18:34
    One thing that helped me to understand this was to skip the theory and look at the Walsh sequences as defined in Phil's code:
    Screen shot 2013-03-23 at 11.53.39 AM.png

    One 16 bit string for each of the 6 LEDs, played back repeatedly in parallel at the fixed period per bit. Pick one string and XOR it with itself or one of the others, writing + when there is a match of bits and - when there is no match. For example, here is the first one with itself:
    1010010101011010
    1010101010101010
    ++++++++++++++++
    16 +'s of course. Averages out in the detector to a maximum positive value. Or, if the detection is weak, there are errors and you get an indication of distance.
    Now the first sequence with the second one:
    1010010101011010
    1010101010101010
    ++++
    ++++
    Averages to zero. And the first with the third:
    1010010101011010
    1001011010010110
    ++--++----++--++
    same, averages to zero. And the fifth sequence with the sixth:
    1100001100111100
    1001100101100110
    +-+--+-++-+--+-+
    Again. That is what it means for the signals to be orthogonal.
    This made sense! after only reading 5 minutes...and makes me wanna eat the rest of this posting sandwich.
  • MagicianMagician Posts: 1
    edited 2013-04-07 14:56
    Have to admit, very interesting project, especially for someone who knows CDMA. The same time, all could be accomplished via much easier for understanding, and cheaper in hardware - TDMA technology. Simply running IR leds one at a time and finding the strongest response.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-04-07 16:41
    TDMA (i.e. time-division multiple access) is certainly one way to approach it and is the method used with Parallax's S2 Robot, which has two IREDs and one receiver. The advantage of CDMA (i.e. code-division multiple access, the method presented in this thread) increases as the number of IREDs increases, since it's "always on" for each channel without timing gaps. This is especially advantageous when you need to integrate over several periods to reduce the effects of noise.

    -Phil
  • Cluso99Cluso99 Posts: 18,066
    edited 2013-04-07 17:49
    Congratulations! This is featured on Dangerous Prototypes today.
    http://dangerousprototypes.com/2013/04/07/parallax-propeller-discriminates-walsh-modulated-ireds/
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-04-07 17:58
    Cluso99 wrote:
    Congratulations! This is featured on Dangerous Prototypes today.
    Well I'll be! How does that happen? Anyway, thanks for the congrats and for the heads up!

    -Phil
Sign In or Register to comment.