Andrew B. Wright, Ph. D., SM ’88
The method described below works, up to a point. Although the initial onset of the wave is detectable, the rectification is not going to be useful to allow the signal to be brought into a digital input, without significantly more signal processing. Analog signal processing is too much of a drag for me to continue down that path.
My original plan on this was to use digital signal processing. While DSP is a drag as well, it’s a drag that I’m well-versed in.
The following papers give some insight on how to proceed:
Villadangos, a. M., Urena, J., Garcia, J. J., Mazo, M., Hernandez, A., Jimenez, A., Ruiz, D., De Marziani, C., “Measuring Time-of-Flight in an Ultrasonic LPS System Using Generalized Cross-Correlation,” Sensors, v. 11, pp. 10326-10342, 2011.
Perez, M. C., Urena, J., Hernandez, A., Jimenez, A., Ruiz, D., Alvarez, F. J., de Marziani, C., “Performance comparison of different codes in an ultrasonic positioning system using DS-CDMA,” Proc. IEEE Intl Symposium on Intelligent Signal Proc, WISP ’09, Budapest, Hungary, 2009, pp. 125-130.
I had actually cited the second paper in my Ph. D. as I was reviewing methods for determining the time delay in an active sound cancellation system. I implemented the algorithm as well. So, when I saw this in the paper which is describing a very similar problem to the one I’m working, I was both happy (I know the method) and irritated (I had forgotten that I know the method).
So, the next steps are:
read the analog input on the Beaglebone. Looks like this can be done through DMA from the ADC module without PRU intervention.
implement FFT on the Beaglebone to estimate the PSD functions. There’s a prepackaged FFT algorithm, hooray, so I don’t have to port the algorithm from my Ph. D. work over to the Beaglebone.
design and implement a digital filter bank to bandpass the various frequency bands, allowing multiple
implement Kasami codes for robot identity detection (not sure if I need to do this – see 3rd reference above)
In teams of mobile robots, it is sometimes necessary to know the location (relative to an agent) and identity of the other members of the team.
Two technologies that are used for distance detection are ultrasonic sensors and infrared sensors. Ultrasound seems to be the leading technology, in part because infrared can be made ineffective by transparent materials and bright lights, including sunlight.
Ultrasound can be disrupted by other sources of sound, reflections, and sound absorbent materials. The beam width can cause issues with resolution of the spatial location of the nearest object. Ultrasonic sensors are deliberately designed to receive only from in front of the sensor, so a static ultrasonic sensor has a limited sensing range.
This project intends to use the technologies for ultrasound, but configured differently to resolve both distance and identity of the nearest partner robot in a robot’s vicinity.
Ultrasonic speakers broadcast a burst of sound at a frequency. The receiver is blanked while the speaker broadcasts. It receives the first echo from whatever the sound hits and reflects from. The sound source can be seen as a square pulse of some duration multiplied by a carrier frequency. At the receiver, a demodulating circuit removes the carrier and leaves only the square pulse. By comparing the start of the broadcast pulse with the start of the received pulse, the time of flight of the wave, and therefore the distance between source and receipt of reflection can be determined.
In  (Shoval, S., Borenstein, J., “Measuring the Relative Position and Orientation between Two Mobile Robots with Binaural Sonar,” ANS 9th International Topical Meeting on Robotics and Remote Systems, Seattle, WA, March 4-8, 2001), an attempt was made to use two receivers on a robot with a broadcast from a second robot to determine the angle between the two robots, as well as the distance. However, the narrow beam pattern of the broadcast source made the measurement work well only if the speaker was aligned with the receivers. The math is based on an omni-directional source, so the narrow-band ultrasonic sensor didn’t comply with the assumptions. This limitation was not inherent in an ultrasound broadcast, but rather in the use of commercial, unmodified ultrasonic sensors.
Rather than use ultrasonic sensors, this work will use standard microphones and speakers. Aside from the fact that I have bunches of them around the lab from my active sound cancellation work, they are omnidirectional. The main disadvantage of using audible sound is that it’s audible. This can be annoying in an environment that would otherwise be quiet. However, if the concept works, there’s no reason to avoid ultrasonic sensors; the sensors would have to be redesigned to be omnidirectional (something that I did in my PhD work).
The following circuit will be used to create the broadcast wave. A beaglebone will create a few cycles of square wave on a digital output with frequency, f. This wave will repeat at a period, Tp. The wave will be fed into a Texas Instruments TLC084 op-amp configured as a four-pole low-pass filter (see circuit). The filter is designed using the Sallen-Key topology. This will give a sine wave. The sine wave will be fed into an LM386 audio amplifier and broadcast through a CMS0341KLX speaker.
Each robot will broadcast on a different frequency, e.g. 2000 Hz, 3000 Hz, 4000 Hz. The frequency will serve as the identifier of the robot. This results in extra complexity on the receiver side, as there will be one band-pass filter for each robot in the team. For a prototype proof-of-concept, the relative ease of implementation should justify the added circuit complexity.
The first harmonic for a 2000 Hz square wave occurs at 3 times the fundamental (6000 Hz). The 2000 Hz should pass through and the 6000 Hz and greater should be blocked. The values for resistor and capacitor to achieve a 5000-6000 Hz (35 krad per sec) cut-off are R = 1.3 kOHM and C = .022 uF, which gives an actual cut off as 2.4 kHz. Higher is better, since the actual sine wave needs to pass completely through the filter while the first (and later) harmonic needs to be heavily attenuated. At the cut off frequency, the signal has already been attenuated by 1/2.
The LM386 is a nice amplifier for audio applications, but it has some quirks. The default gain is 20. The output when driven by the + input seems to be limited between 0-Vss. In other words, the signal will not come out negative. If your output from a Beaglebone is a 0-2.5V signal, feeding this directly into the LM386 would result in a 0-50V, which would be clipped to supply voltage. In order to match these two circuits, the 2.5V Beaglebone signal needs to be knocked down, so that it can be amplified again. Figure a gain of 1/10 will be a good start. This can be accomplished with a voltage divider or with an amplifier wired with a sub-1.0 gain (in this case 0.1). For the speaker, 1 Vpp is a nice, loud signal. However, it might be desirable to reduce to more like a 50 mVpp signal to save your ears. In this application, the detection needs to be made about 2 m away, so this value should be adjusted based on that desired outcome. Quieter is better for a lot of reasons, including the removal of unwanted echoes.
From the app note for the LM386, the following circuit is used repeatedly.
The 0.05 uF capacitor in series with the 10 OHM resistor to ground interacts with the 250 uF capacitor to bring the output to an AC signal that can be used with a low impedance speaker load. The large value of the capacitor allows the low impedance speaker to be driven without pulling too much current through the amplifier and dramatically reducing the voltage to the speaker and hence the sound level.
The code to load onto the pru (the header files are here.) to generate a 2 kHz square wave, 5 cycle burst separated by 5 ms intervals is:
The code runs for 2 seconds.
The fragment dts to allocate P8.19 is
I found a nice article from Texas Instruments (John Caldwell, “Single-supply, electret microphone pre-amplifier reference design,” http://www.ti.com/lit/ug/tidu765/tidu765.pdf) which contains design info on how to figure out what resistors and capacitors can be used with a specific microphone.
The microphone, Panasonic WM-64PNT (digikey p/n P11969) – obsolete! – Direct substitute: PUI Audio, Inc. POM-2244P-C3310-2-R (digikey p/n 668-1415) has the following key specs:
dimensions: 6 x 2.2 mm
Impedance: 2.2 kohms
frequency: 20Hz to 16 kHz
Max operating voltage: 10 v
Standard operating voltage: 2 v
current consumption: 0.5 mA maximum
sensitivity reduction: within -3 dB at 1.5 v
S/N ratio: more than 58 dB
sensitivity: -44 +- 3 dB (0dB = 1V/Pa, 1kHz) Vs = 2V, RL=2.2kohm
I spent a lot of time reviewing the various components of a microphone pre-amp. I’m not an expert by any means. But, I thought the results were sufficiently interesting that I’m going to write about them here.
There’s a nice video blog about electret microphones and signal conditioning (https://www.youtube.com/watch?v=UhG83WS51q8).
The membrane is made from a material called an electret. This is similar to a permanent magnet, but with a “permanent” electric field rather than a “permanent” magnetic field. It will generate a potential for a long, long time. The membrane is separated from a plate, which forms a capacitor. When the membrane moves, the capacitance changes. If an electrode is attached to the membrane and another to the plate, the combination appears like a voltage source which changes proportionally to the motion of the membrane, which is proportional to the sound pressure on the membrane. In other words, the voltage changes proportionally with sound pressure.
There is a nice article (Gentex Electro-Acoustic Products, “Apply Electret Microphones to Voice-Input Designs,” http://www.gentexcorp.com/assets/gentex/ea/eapdfs/electretappguide.pdf) that goes into much more detail on electret microphones.
The JFET threw me for a while. Here’s a nice tutorial on JFETs. It appears to be a n-type JFET from the TI article (although this is a different microphone). The electret provides a voltage between the gate and the source, Vgs. The user supplies voltage across the drain to source (which is usually grounded) called Vds. The JFET can be modulated either by Vds or by Vgs. Vgs adjusts the channel width between drain and source (i.e. the resistance in this path). The path can be fully open (Vgs = 0V) or fully closed or pinched (Vgs = Vp).
If the channel is not pinched, then the current flowing from drain to source will vary between 0 amps and a saturation current. The magnitude of the saturation current depends on the gate voltage. If Vds is configured such that the JFET is saturated regardless of gate voltage, then the current flowing through the JFET will be proportional to Vgs. It will be largely invariant to changes in Vds. In other words, if the supply voltage stays above the saturation voltage, the JFET will sink current invariant of the supply voltage. If the JFET is powered by a battery, the performance will not change much until the battery drops below the saturation point.
What is this magic voltage? The datasheet for the WM-64PNT uses a 2V source and 0.5 ma maximum current and a 2.2 kOHM bias resistor. This gives a voltage at the top of the JFET as (2-x) = 2200 * 0.0005, x = 0.9 V. So, the JFET should be in saturation for around 0.9V.
Using a bigger supply allows more head-room for a battery which is below it’s nominal voltage. The first part of the circuit is the supply for the microphone. The supply voltage will be 5 v
The microphone resistor, R1, can be calculated from (desired supply voltage – nominal supply voltage)/max current consumption for microphone:
(5v-2v)/0.5 ma = 6 kOHM, (5v-1v)/0.5 ma = 8 kOHM, (5v-2.5v)/0.5ma = 5 kOHM (using 1/2 5v as the biasing point)
The bigger the resistor, the larger the transconductance (voltage->current) gain. If the current through the JFET is i(t), varying between 0 and 0.5 ma, then the voltage at the JFET drain will be R i(t), varying between supply voltage at 0 ma and R*0.5 ma at maximum conductance.
The smaller the resistor, the more headroom for battery drainage.
The output capacitor is calculated from the desired pole of the high pass filter (circa fc=5 Hz). With R = 8 kOHM,
C3 = 1/2/pi/R1/fc=1/2/pi/8 kOHM/5 Hz = 4 uF -> 4.7 uF -> f = 1/2/pi/R1/C3=1/2/pi/8 kOHM/4.7 uF= 4 Hz (good enough)
The high pass filter threw me for a bit. The amplifier in the TI app note is a transimpedance amplifier, which means that it converts current input into voltage output. So, the high-pass filter described here is blocking the dc current, not the offset voltage introduced by the JFET bias.
The gain on the op-amp is set by the resistor between V- and Vout. The gain of the microphone is 20 log 10 (G ref 1V/Pa) = -44 dB -> G = 6.3 mV/Pa.
Converting this to a current with the 2.2 kOHM impedance, G’ = 2.87 uA/Pa.
If it is desired that 2 Pa will yield an amplified voltage of 1 V, then Imic = 2 Pa * 2.87 uA/Pa = 5.74 uA.
The transimpedance gain of the op-amp is set by R = Vout/Imic = 1 V/5.74 uA = 174 kOHM.
This needs to be offset so that the op-amp output will sit between 0V and the op-amp supply (5V). Using a voltage divider at the V+ terminal of the op-amp, resistor values of 10 kOHM will bias the output to 1/2 supply rail.
Supply noise will be transmitted directly to the output signal, so, the noise floor will be set by the ripple and noise on the supply. The supply I’m using has 50 mV of noise, which is probably not adequate. A big capacitor across the supply seemed to do the trick, though.
The circuit that is recommended with the microphone uses a 2 V supply, a 2.2 kOHM resistor, and a 1 uF capacitor. At .5 ma current, the voltage drop across the resistor is 1.1 V which would leave the drop across the microphone as 0.9 V. The pole of the high pass filter is 1/2/pi/1 uF/2.2 kOHM = 72 Hz. That seems pretty high for audio applications.
Recalculating the resistor for (5v-0.9v)/0.5 ma = 8.2 kohm.
The high pass filter cap is C3 = 1/2/pi/R1/fc=1/2/pi/8.2 kohm/5 Hz = 3.8 uF -> 3.3 uF
The basic mic circuit is shown in this figure. This circuit does not include capacitors to add stability that are described in the TI app note. This circuit is intended to be minimalistic so that it’s easy to see what each bit does.
The signal from the microphone should be band-pass filtered before presenting it to the envelope detector. But, until there are other signals in the area, it’s possible to proceed directly to the envelope detector.
There is an article on using single supply op-amps in a variety of applications, including filtering (Carter, B., “A Single-Supply Op-Amp Circuit Collection,” Texas Instruments Application Report, SLOA058,2000). This document may be reproduced in Carter, B., Mancini, R., ed., Op-Amps for Everyone, Elsevier, Newnes, 2009, ISBN 978-1-85617-505-0, although I do not have a copy.
The amplified microphone signal needs to be filtered so that only the signal around the desired broadcast frequency is passed
to the envelope detector. The TLC084 can be configured with a double pole low-pass filter and a double-pole high pass filter to give a band pass filter.
Using a single-supply op-amp for the high pass filter requires a virtual ground, since the high pass filter will remove a DC offset. Using a virtual ground of Vcc/2 will result in an output that has no frequency content below the cut-off frequency, but which is centered in the time domain around the virtual ground. To generate a Vcc/2 virtual ground with an op-amp, use the following circuit. Normally, a filter cap will be connected between Vcc/2 and ground, although that is not shown in the circuit.
The bandpass will be centered on 2000 Hz. Using a 1200 Hz bandwidth, the high pass filter needs a corner frequency of 1400 Hz and the low pass filter needs a corner frequency of 2600 Hz.
For the high pass filter, RC = 1/2/pi/1400 Hz = 113.6 us. C = .01 uF means R = 11.3 kOHM.
For the low pass filter, RC = 1/2/pi/2600 Hz = 61.2 us. C = .01 uF means R = 6.1 kOHM -> 5.6 kOHM.
An RC high pass filter is used to strip off the DC offset before sending it to the envelope detector. R = 39 MOHM and C = .033 uF works nicely. This has a cutoff frequency of 1/2/pi/39 MOHM/.033 uF = .1 Hz. I used stuff I had lying around, so a better calculation might be worth doing here.
The simple envelope detector uses a diode, a resistor, and a capacitor. The RC network should have a cut-off frequency below the carrier frequency. For a 2000 Hz carrier, start with a 500 Hz cut-off. RC values of 16 kOHM and .02 uF make a good start. NOTE: This doesn’t seem to work too well. Looks like a much lower frequency is called for. Getting peaks that decay rapidly.
A little more fiddling and it becomes obvious that the voltage in my signal is not rising much above the diode’s 0.6 v turn on voltage. So, the peaks that I’m seeing are only those peaks that are getting above that value. So, either I need to amplify the signal more (not really that great a plan, since my total signal range in my amplifier is 5 v, which means my max signal would be about 2.5 V. This means that distant signals would be very hard to detect. So, on to the superdiode, which does not suffer from this problem.
Another issue reported in the literature is that the frequency response of the diode can impact the problem. We’ll see.
Range can be determined by considering the time from broadcast to reception. The speed of sound in air, c, is about 343 meters per second. d = c*t.
However, when did the wave start? The beablebone transmitting and the beaglebone receive would have to synchronize their watches in order to make this work.
If each beaglebone were programmed to broadcast a sound at the conclusion of receiving a sound from another robot, then each robot would be able to calculate the distance to the other robot. This idea is similar to the children’s game, “Marco-Polo,” where one child would say “Marco” and the other “Polo.” As the children got further away, the sound would decrease. As they got closer, the sound would increase.
In this proposed Marco-Polo scheme, the time between sending and receiving is 2d/c+T, allowing the distance to be easily calculated from the measured time of flight, the known speed of sound in air and the known pulse width.
If the default time between a robot sending pulses is more than 2*d/c, then any pulse received in less time would possibly be the result of a robot responding. (NOTE: it would be easy to make the pulse width a function of a response to a robot. E.g. if robot 2 were responding to robot 1, the pulse width could be varied to reflect this. In the prototype, proof-of-concept, this is not necessary, since the experimental configuration will be determined such that robot 1 must be responding to robot 2.)
What if a robot hears multiple robots? In this scheme, the robot may need to respond only to the closest robot or may need to queue up responses (i.e. respond to robot 2 with a specific pulse length and respond to robot 3 with a different pulse length, where the start of the response to robot 3 would follow the completion of the response to robot 2).
This scheme is going to use a “marco-polo” approach to measuring distance. Robot A will broadcast a pulse of a specific length, p1. This pulse will repeat at the period, T. Robot A will listen. If Robot A hear’s a pulse out of one of its detectors, it will add a pulse of length, p2, after it’s pulse of length, p1, with a space of length, Tp-p1, where Tp is the length of the character. T = nTp, where n is the number of possible robots in the swarm. If a robot B hears a response with pulse, p1 (robot A), and pulse, p2 (robot B), then robot B knows that robot A is responding. Robot B can compute the difference between when it sent it’s pulse and when it received the response. This tells Robot B the distance that robot A is away from itself. The difference in arrival times between the two microphones on the robot can be used to determine the relative orientation of the other robot.
Dual-Microphone Ears: 3D Printed Speaker/Microphone Holder
Here is a design for a microphone and speaker holder to allow mounting on a Vex based robot.
In order to reduce the “field of view”, the microphones will be shrouded with a
parabolic shotgun receiver. This will make them more uni-directional, but increase the gain. Here is an article describing analysis of shotgun microphones (Bai, MR, Lo YY, “Refined acoustic modeling and analysis of shotgun microphones,” JASA, 2013, v. 133, n. 4, pp. 2036-2045). Here is an early paper on tube-based microphones (W. P. Mason and R. N. Marshall, “A tubular directional microphone,” J. Acoust. Soc. Am. v 10, n 3, 206–215 (1939).)
A tubular design and a shotgun design are analyzed the same way. In the tubular design, a circular housing contains many tubes of the same diameter and different lengths. In a shotgun design, a tube has holes or slots along the length. The analysis doesn’t care if holes are drilled or slots are milled. I presume that slots are easier to machine or look cooler. For on-axis sound waves, the distance travelled is the same for the sound entering the end and for sound entering the slot/holes. For off-axis sound waves, the distance travelled is different for the sound entering the end and the sound entering the successive holes. When these out-of-phase waves reach the microphone, a complex, frequency dependent interference pattern is established, which usually attenuates the off-axis sound.
The bottom line for these designs is that the longer the tube, the lower the frequency for which directionality is achieved.
SOUND CONCENTRATOR FOR MICROPHONES, JASA, v1, n 3a, pp. 410-417.
Parabolic microphone: O. B. Hanson, MICROPHONE TECHNIQUE IN RADIO BROADCASTING, JASA, v3, n1a, 1931, pp. 81-93.
Here is the beam-pattern for the design.
Difference in arrival time between two microphone receivers can be used to calculate an angle between the microphone holder and the source.
Mounting the speaker and the microphone:
Since I’ve got a nice, dandy 3D printer, I can make a parabolic or shotgun shroud for the microphones easily. I can make baffles for the speaker. I can make a resonant cavity, different for each speaker, that amplifies the desired frequency. I can make a horn. Or a flute. So many possibilities.
The microphones should be mounted in an ear configuration, with a bias towards the front of the robot. The speaker needs to broadcast so that it can be a planar wave front extending from the ground to somewhat above the robot.
The fact that I can finally put all that acoustic knowledge from my PhD to productive use just makes me happy.
Since sound falls off at 1/r-squared, the volume to the speaker can be set so that the detection threshold in the demodulator circuit is insensitive beyond the maximum distance for which detection is desired. Use of resonators should allow the sound to be broadcast with small power consumption. Although an LM386 will be used initially, this is probably an over-kill amplifier for this application, and a lower power amplifier should be considered.
Conceptually, this project is pretty easy. The main worry I have is the demodulator, so I’ll tackle it first. Nonetheless, other than the demodulator, I’ve done all the other bits in some project or other. The sad thing is … all this came to me in a dream last night. —–
This output could be passed to an envelope detector immediately, but it’s a little weak and the impedance might be a bit hinky. So, an amplifier might be good. After the amplifier, there will be a tank circuit to isolate the desired modulator frequency and an envelope detector. For now, an MCP 602 single supply op-amp is used as an amplifier alone: Here’s the envelope detector (to be added later). ——– The Microchip MCP6044 proved to be a problem. It only has bandwidth up to 14 kHz. It seemed to start attenuating at about 500 Hz, so it became unreliable for audio applications.
The first bit in this project is to work out the demodulator. I’m going to start with a cheap and dirty envelope-detector circuit. This circuit uses a diode and a low-pass filter, where the filter is tuned to remove the carrier frequency (ie the cut off is below the carrier frequency. The cheap and dirty circuit can be improved with a super-diode circuit (to give a lower minimum voltage) and an active filter to give a more accurate cut-off frequency.
For each robot, a different frequency would be chosen. This allows many signals to be flying around the space at once. However, band-pass filters will be required so that only the signal in the band of the robot will be passed. For every robot to be detected, two digital inputs (one per microphone) will have to be assigned. So, for eight robots in the swarm, 16 digital inputs will be needed. Some form of multiplexing will likely be required.
The classic bandpass filter for AM transmission is a “tank circuit.” After much research and experimentation, I got the following circuit to function as a bandpass filter.
For this circuit, the bandpass frequency is 2pi/sqrt(LC). I’m not sure about the bandwidth (or Q). But, I’ll worry about that if it becomes a problem.
I’m using a 47 mH inductor (mouser p/n ???). This requires the following capacitors to set the resonant frequency: 12000 Hz (6), 11000 Hz (7), 10000 Hz (8), 9000 Hz (10), 8000 Hz (13), 7000 Hz (18), 6000 Hz (22), 5000 Hz (33).