Shop OBEX P1 Docs P2 Docs Learn Events
About FREQOUT and Boe-Bot IR Detection — Parallax Forums

About FREQOUT and Boe-Bot IR Detection

edited 2007-01-26 05:52 in Learn with BlocklyProp
More about the FREQOUT Command for Boe-Bot IR Detection
Robotics with the Boe-Bot (PDF) gives a fairly terse explanation of how the FREQOUT command sends a 38.5 kHz signal via an IR LED near the beginning of Chapter 7.· This post examines the FREQOUT command more closely with a spectrum analyzer, and explains what’s happening with the signal.·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay

Education Department
Parallax, Inc.

Post Edited (Andy Lindsay (Parallax)) : 1/9/2007 6:05:27 AM GMT

Comments

  • edited 2007-01-09 05:44
    About Harmonics - Square Wave Example

    Just about any signal can be synthesized by adding sine waves of various frequencies and amplitudes. For example, a square wave is built up by a DC signal, plus a sine wave of a certain magnitude at the fundamental (the frequency of the square wave), plus a harmonic frequency at 3 times the fundamental (smaller amplitude), plus another harmonic at 5 times the (still smaller amplitude), and so on, 7th harmonic, 9th harmonic, etc. By adding all these odd harmonic sine waves up, it approximates the square wave.

    There’s also an example with a ramp function in the Simple Fourier Series section of this page http://en.wikipedia.org/wiki/Fourier_series. This post isn’t concerned with the math. However, there’s a nice little animated graphic that shows how each sine wave in the Fourier series added in causes the wave form to more closely approximate the ideal sawtooth wave.

    A given signal can be constructed by a bunch of sine waves at different frequencies added together. That’s a Fourier series. The reverse is also possible, a given signal can be broken down into its component sine waves. Here is a 1 Hz square wave program for the BASIC Stamp 2 that can be examined by a device called a spectrum analyzer, which displays the component sine waves that compose a given signal.

    ' 1 Hz Square Wave
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    LOW 8
    
    DO
    
      TOGGLE 8
      PAUSE 497
    
    LOOP
    
    
    


    The Square Wave Oscilloscope.jpg shows what a square wave looks like in time domain, measured on an oscilloscope.

    attachment.php?attachmentid=44934

    If you feed a square wave into a spectrum analyzer, it will show you a graph of the square wave in the frequency domain. So the x-axis is frequency and the y-axis is amplitude. The figure below shows the square wave displayed by a spectrum analyzer. It shows the first seven sine wave components as vertical spikes. The leftmost at 0 Hz, the fundamental at 1 Hz (same as the square wave’s frequency), the 3rd harmonic at 3 Hz, the 5th harmonic at 5 Hz, and so on, up through the 13th harmonic.

    attachment.php?attachmentid=44935

    There’s a little diamond on the second visible peak. (It’s actually the third if you count the half of a peak at zero Hz at the display’s far left.) The diamond shows a frequency/amplitude marker that that follows the graph. There’s a knob on the spectrum analyzer to move this marker left/right. Currently, it’s on the third harmonic, which is 3 Hz since the square wave’s fundamental is at 1 Hz. Above the graph, it reads X: 3 Hz, Y: 107.192 mV. With the spectrum analyzer’s current settings, it indicates that the square wave has a 3 Hz (third harmonic) sine wave component that’s 107.192 mV peak to peak. To the right of the peak with the diamond, the 5th, 7th, 9th and 13th harmonics are also visible.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 1/9/2007 6:05:59 AM GMT
  • edited 2007-01-09 05:54
    DTMF Example – Signals with Two Sine Waves

    Another example, if you press a button on your phone, (or use the BASIC Stamp's DTMFOUT command) you can view the two sine waves that get mixed together to make the tone on a spectrum analyzer. For example, the tone for the 6 digit is a combination of 770 and 1477 (according to http://en.wikipedia.org/wiki/Dual-tone_multi-frequency). Here is a PBASIC program that sends the 6 tone for a nice long time (seconds) to measure with the spectrum analyzer.

    ' 65.5 s DTMF Signal Repeated in Endless Loop
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    LOW 8
    
    DO
    
    DTMFOUT 8, 65535, 0, [noparse][[/noparse]6]
    
    LOOP
    
    


    Here is a picture of the DTMF signal on an oscilloscope (in the time domain). There isn’t really much useful information here. The oscilloscope incorrectly divined the lower of the two frequencies as 749 Hz. You could use the scope’s trace feature to look at the difference between the highest peaks to discern the 1477 Hz signal with better accuracy. The 770 Hz signal would be a little more difficult to nail down, though it could be done. (Note: The signal is digitally synthesized by BASIC Stamp 2, and smoothed out with a low pass RC filter. R = 10 k, C = 0.1 uF on the Board of Education.

    attachment.php?attachmentid=44936

    Below is a picture of the same DTMF signal displayed by a spectrum analyzer. There are two peaks. The diamond marker is sitting on the left peak, which is 776, much better than the Oscilloscope’s guess. The X value for the right Peak is 1.48 KHz. Consider how it breaks this signal down into the signal’s component frequencies; whereas, the oscilloscope shows us a waveform, but doesn’t necessarily make it clear what the signal components are. That’s a job for a Spectrum analyzer.

    attachment.php?attachmentid=44937

    In the next post, we’ll take a closer look at how the FREQOUT signal contains two sine waves similar to the DTMF signal. The difference is that these sine waves are always on opposite sides of 32767 Hz, and they are always the same distance (in Hz) away from this value.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 1/9/2007 6:06:26 AM GMT
    614 x 461 - 75K
    614 x 461 - 68K
  • edited 2007-01-09 05:58
    How FREQOUT Really Transmits Two Frequencies

    The FREQOUT command is most commonly used for synthesizing beeps and musical notes with a speaker. The tones played range from 20 to 20 kHz, and how well you can hear it depends on what the speaker you are using naturally filters for. The piezospeaker in the What’s a Microcontroller (PDF) and Robotics with the Boe-Bot (PDF) kit has a pass frequency of 4.5 kHz, but tones ranging from 1.5 kHz to 7.5 kHz are easily discerned. If the command FREQOUT 8, 2000, 3500 happens to also be digitally synthesizing a second sine wave in the neighborhood of 61.036 kHz, the piezospeaker will filter it out, and even if it is specially designed to transmit tones at that frequency, we still couldn’t hear them.

    When the BASIC Stamp digitally syntheses a sine wave tone in the 1 to 32766 Hz range, there is a corresponding tone in the 32678 to 65535 Hz range. This second frequency is as far above the 32767 Hz mark as the main frequency is below it. That’s why FREQOUT 8, 1, 27036 results in a 27036 Hz signal and a 38500 Hz signal. Much like the DTMF signal, the signal really consists of two sine waves, one at 27036, and the other at 38500. Conveniently, the command FREQOUT 8, 1, 38500 has the same result: a 37036 Hz signal and a 38500 Hz signal. The same applies to FREQOUT 8, 1, 40000 and FREQOUT 8, 1, 25536. Both FREQOUT commands send the same pair of frequencies, 25536 Hz and 40 kHz.

    In Robotics with the Boe-Bot, chapter 7, the command FREQOUT 8, 1, 38500 is used to transmit a 38.5 kHz infrared signal with an infrared LED. If that infrared reflects of an object near the Boe-Bot and is detected by the Boe-Bot’s infrared receiver, which is tuned to 38.5 kHz, the detector will send a signal to the BASIC Stamp which gets interpreted as a detected object. Now, the IR signal that gets transmitted also carries the 27036 Hz signal, but that doesn’t do the IR detector any good since it’s pretty much blind outside the 36 to 40 kHz range. However, the 38.5 kHz signal works just great for IR detection with the Boe-Bot’s 38.5 kHz IR detector.

    Here is a test program that can be examined on the spectrum analyzer. It repeats the 27036 and 38500 Hz signals for a duration of 65.54 s in an infinite loop.

    ' Keep up a 35.5 kHz signal
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    DO
    
    FREQOUT 8, 65535, 38500
    
    LOOP 
    
    


    Here is the FREQOUT 8, 65536, 38500 the signal displayed by the spectrum analyzer. Notice that there are two frequencies. The marker reads X: 27.072 kHz for the picture directly below, and the one below that reads X: 38.592 kHz. Note that the spectrum analyzer’s marker takes some pretty big steps, and it won’t settle on the exact frequencies the BASIC Stamp is transmitting, but this is close enough to demonstrate what’s going on.

    attachment.php?attachmentid=44938


    attachment.php?attachmentid=44939

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 1/9/2007 6:08:13 AM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-10 14:09
    This is partly a fundamental property of square waves, and partly how the BS2 generates them.

    A "pure" sine wave will consist of frequency elements of a single frequency. Meaning, if you have a 2000 Hz sine wave, on an o'scope you'd see a nice smooth sine wave, and on a frequency analyzer you'd see a single spike at 2000 Hz.

    Now, the frequency components of a square wave are more complex. The reason is that nice, sharp, FAST rise-time and fall-time. That's where those 3rd, 5th, 7th etcetera harmonics come in. That sharp rise-time only happens because the square wave signal is really the sum of all those harmonics.

    The other part is in this sentence: "When the BASIC Stamp digitally syntheses a sine wave tone in the 1 to 32766 Hz range, there is a corresponding tone in the 32678 to 65535 Hz range."

    The second frequency 'spike' in this case comes from exactly how the BS2 "digitally synthesizes a sine wave". Now, I don't personally know (or care, really) exactly the code the BS2 uses to achieve this. It's enough that the vendor asserts that the way they achieve this results in a second frequency 'spike' -- because I want to use that second frequency spike to drive my IR-LED, because that frequency of IR light is what will trigger my IR-Detector.

    So, the property you're so curious about is NOT a 'harmonic' -- instead, it's an aspect of exactly how the BS2 generates its signal.
  • LSBLSB Posts: 175
    edited 2007-01-10 16:21
    ...if a guy's not careful he could learn a thing or two around here.

    Thanks!
  • edited 2007-01-10 21:44
    agfa said...

    My confusion now is one your explanations along with other explanations I have read elsewhere that explain·the fundamental frequency will generate a·3rd, 5th, 7th, and so on harmonic frequency.· How does outputing a 27.072Khz get a 38.5Khz harmonic?

    Good question.· The idea behind the square wave example is that you can·to build any signal·by summing up various sine waves.· If you have a signal that's a distorted sine wave, it has other sine wave components, which are also considered harmonics of the signal.·

    The FREQOUT command is designed to make a digital signal that gets passed through a filter.· The filter's output is supposed to be a sine wave in the 1 to 32767 Hz range.· Even after the filter, there will still be a trace amount of the higher frequency sine wave (the harmonic), which can be·measured with·the spectrum analyzer.· This measurement can be used to calculate the signal's total harmonic distortion (THD), which is a measure of the contribution of all the signal's harmonics against the fundamental's contribution.···

    Well, all that said, I had planned to elaborate in harmonics in the next·revision of Robotics with the Boe-Bot, but now that we've gone through it, it's clearly way·off topic in terms of what the chapter should be introducing.··Seems now like the presentation of the higher frequency signal FREQOUT transmits should be more like this:
    • Discuss how FREQOUT works and what it's supposed to do (with filters)
    • Introduce dual tones, and cite DTMF as an example for dual tones
    • Maybe play a dual tone vs a single tone on the piezospeaker
    • Explain·FREQOUT's·undocumented dual tone that occurs in the 32768 to 65535 Hz range
    • Segue·to how filters like the one in the·Boe-Bot's IR·receiver·are designed to·detect·signals that the FREQOUT command can transmit with this higher band·
    • Continue with IR detection example

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 1/10/2007 9:56:43 PM GMT
  • AImanAIman Posts: 531
    edited 2007-01-11 13:53
    Andy,

    Thanks.

    I get bored easily if something is to simple so the more indepth stuff helps hold my attention and increase my knoweldge.
  • SSteveSSteve Posts: 808
    edited 2007-01-13 16:32
    Andy Lindsay (Parallax) said...
    The FREQOUT command is designed to make a digital signal that gets passed through a filter. The filter's output is supposed to be a sine wave in the 1 to 32767 Hz range. Even after the filter, there will still be a trace amount of the higher frequency sine wave (the harmonic)

    Andy, is it correct to call that higher frequency a harmonic? I would expect a harmonic to increase proportionally to the fundamental, not mirror around a set frequency. What you're describing sounds more like an artifact.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • edited 2007-01-13 21:12
    Yeah, I suppose artifact is the correct term.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-01-17 16:53
    This may bring down the level of conversation a little because its mostly beyond my scope but having some unexpected free time yesterday I was browsing the Parallax products and came across the Remote IR kit. I had an old·universal remote kicking around and an IR detector so I worked through the online book. I posted here to say to anyone thats not tried that excersise it's a must. It was so easy to follow through and understand and very rewarding to see those figures pop up in the debug window and know what they represented.

    Jeff T.
  • bgthreebgthree Posts: 14
    edited 2007-01-25 19:53
    Is the USB Stamp-oscilloscope capable of displaying the frequency spectrum of signals, similar to what Andy shows in the pictures above?

    (spectrum analyzer?)

    yeah.gif

    Post Edited (bgthree) : 1/25/2007 7:58:15 PM GMT
  • edited 2007-01-26 05:52
    bgthree said...
    Is the USB Stamp-oscilloscope capable of displaying the frequency spectrum of signals, similar to what Andy shows in the pictures above?

    (spectrum analyzer?)
    Yes, provided you are using the 4.0 version of the software.· Here is a link:

    http://www.parallax.com/html_pages/downloads/software/scope4.asp

    Use the FFT button to see the spectrum analyzer view.··The time units per division have to be adjusted in oscilloscope mode before starting the FFT so that the frequency scale goes out beyond 38 kHz.· It'll take some experimenting, choosing various time/div·values in oscilloscope mode before switching over to FFT mode, then switching back to time mode and trying again with a different time/div.

    Also, the spikes that indicate the signal won't be nearly as pronounced as they are with the desktop unit.··That's also the·way the desktop unit's display looked by default, presumably to analyze noise instead of signal.··The two peaks are slightly higher than the noise floor, and you can use·the·Marker feature to place the marker on the spikes that are higher than the rest and find out what frequencies they are at.·

    If you have not already done so, try out page 9 and pages 44-47 (actually, the ground work starts on page 36) in the Understanding Signals text.· It's available for download here:

    http://www.parallax.com/dl/docs/prod/sic/Signals.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
Sign In or Register to comment.