# Gas station without pumps

## 2016 March 15

### Ultrasonic transmitter impedance again

Filed under: freshman design seminar — gasstationwithoutpumps @ 23:28
Tags: ,

Today I had to wait several hours in the lab for the freshman design seminar students to finish their designs, demo them, and turn in reports.  Only the two LED cubes demoed their projects: the pulse monitor group had left their hardware in the lab last week by mistake, and it was gone; and the ultrasonic rangefinder group did not have the member with the software present—I’ll have to see if their report tells me how far they got.

Because I had to spend a lot of time in the lab today, I decided to redo the work mentioned in the post  Ultrasonic transmitter impedance. That is, I tried measuring the (magnitude of) impedance of the transmitter at different frequency ranges, by measuring the voltage across the transmitter and across a series 2.2kΩ resistor at different frequencies.  This time I had my laptop with me, and I plotted after every few measurements, so that I was careful to fill in frequencies whenever the impedance deviated from a simple capacitance.

The documented 40kHz resonance is around 39.78kHz, with another large resonance around 55.4kHz. There were also antiresonances and some minor other resonances.

The antiresonances around 42kHz and 56.5kHz are indicative of a coupled system—for the transmitter, the 39.78kHz, 42kHz, 55.4kHz, and 56.5kHz are probably different vibrational modes of the piezoelectric diaphragm.

Zooming in on the interesting region reveals some weird behavior in addition to the major resonances and antiresonances.

One interesting observation was that the weird dip at 59.3kHz had hysteresis—if I approached it from below, I got the dip and it continued to about 59.4kHz, but if I approached it from higher frequencies, I could extend the capacitive line all the way back to 59.3kHz.  I’ve no explanation for that yet.

I could probably do a better job of measuring at the extreme frequencies if my reference impedance were a 1nF or 2.2nF capacitor, since the voltage ratios would then be around 1 for most frequencies, and only being about a factor of 4 off at the resonances and antiresonances.  The 50Ω output impedance of the function generator would not really be a problem until we got over a MHz, since the corner frequency would be 3.8MHz with a 1nF load.  Of course, the capacitors I have are not very high precision, so I get more accurate measurements with resistors, even when the voltage ratios get fairly extreme.

I keep feeling that I should be able to use the magnitudes of the AC voltages to get the phase of the impedance (except for the sign), but all my attempts so far have resulted in mostly nonsense.  At the resonances and anti-resonances the impedance appears to be purely real (that is, the voltages add up to about the same value as the $\sqrt{a^2+b^2}$ for the low and high frequencies, where the transmitter is capacitive).

## 2016 March 13

### Ultrasonic transmitter pulse shaping

Filed under: freshman design seminar — gasstationwithoutpumps @ 18:45
Tags: , ,

In Ultrasonic rangefinder with loudspeaker, I suggested that non-resonant transducers should be able to “get cleaner deconvolution of the echoes” and last week I wrote a program to try to design a ping that would do that.

• I wanted the ping to have limited bandwidth (say 20kH–50kHz), so that I did not have to have a transducer that responded to very high frequencies, and so that the ping would not be audible to humans.
• I wanted the ping to use only {–1, 0, 1} as values, so that it could be easily created with digital outputs from a microcontroller.
• I wanted a fairly short duration for the ping, so that I could send it, then dedicate the microcontroller to listening for the echo.
• I wanted the autocorrelation of the ping to have no large peaks after the maximum at τ=0, so that cross-correlating the sent ping with return echo would have (mostly) a single peak for each echo.  The sampling rate for the transmission should be the same as for the receiving, so that cross-correlation is easily computed.

The standard resonant transmitter/receiver with a 40kHz burst does fine on the bandwidth criterion and on the 3-value excitation, and ok on the ping duration.  That is, the ping can be triggered with a short excitation by the microcontroller, but the acoustic signal actually lasts much longer than the excitation signal. The autocorrelation criterion is completely missed, though, as there are strong autocorrelation peaks every 25µs.

I wrote a simple Python program to test the criteria for different excitation waveforms. The waveforms were expressed as patterns of {+1, –1} at 200kHz, which I know is achievable as a sampling rate.  If I can figure out how to set up DMA transfer from the analog-to-digital converter on the Teensy 3.1, then I should be able to use 240kHz, which would be better for comparison with a 40kHz resonant system, since I could then include a 40kHz symmetric ping (repeating 3 high, 3 low) for comparison.

To limit the duration of the ping, I looked only at ones that were exactly 2n samples long (16, 32, or 64, corresponding to 80µs, 160µs or 320µs).

I also looked at the FFT of the ping, and measured the energy within the passband (20kHz–50kHz).

I took the autocorrelation of the ping (by direct computation, rather than using iFFT(|FFT(ping)|2) ), and looked at the magnitude of the largest peak other than the one at τ=0.  The autocorrelation was scaled so that the 0-peak had magnitude 1.

Simple pings (like 5 periods of a 33.33kHz square wave) perform very well by the band-pass measure, but poorly by the autocorrelation measure (shifting over by one period results in a correlation peak that is 4/5 as big as the peak at 0).

I tried a few hand-designed pings, with very bad autocorrelation results, so I switched to making random pings, starting with +1 and having equal numbers of +1 and –1 (to avoid a DC component to the ping, which would have produced an audible click). I then did iterative improvement by swapping random pairs of values in the ping, checking an objective function that was a linear combination of the autocorrelation peak and the bandpass energy.  I found several good solutions this way, with different tradeoffs of energy outside the desired band and the size of the autocorrelation peak.  Changing the boundaries of the band also results in different solutions.  Here are few examples for 20kHz–50kHz, with a 160µs burst:

 [ 1., 1., 1., 1.,-1.,-1.,-1., 1., 1.,-1.,-1., 1., 1.,-1.,-1., 1., 1., 1.,
-1.,-1.,-1.,-1., 1., 1., 1.,-1.,-1., 1., 1.,-1.,-1.,-1.]
#  bpe= 0.44538406194
#  max autocorrelate= 0.28125

[ 1., 1.,-1.,-1., 1.,-1.,-1., 1., 1., 1.,-1.,-1., 1., 1.,-1.,-1., 1., 1.,
-1.,-1., 1., 1., 1.,-1.,-1.,-1., 1., 1., 1.,-1.,-1.,-1.]
#  bpe= 0.41363760532
#  max autocorrelate= 0.1875

[ 1., 1., 1.,-1.,-1., 1.,-1.,-1., 1., 1., 1.,-1.,-1., 1.,-1.,-1.,-1., 1.,
1., 1.,-1.,-1.,-1., 1., 1., 1.,-1.,-1., 1., 1.,-1.,-1.]
#   bpe= 0.405535884864
#   max autocorrelate= 0.15625


Once I get a speaker that can produce some output up to 50kHz, I’ll try seeing what the signal looks like for these spread-spectrum pings.  I suspect that the low-pass filtering of the speaker and the microphone will result in a ping that looks very little like the excitation waveform, and that I’ll have to work a bit on coming up with a different strategy for producing a ping that I can cheaply deconvolve.

### Ultrasonic transmitter impedance

Filed under: freshman design seminar — gasstationwithoutpumps @ 13:00
Tags: , ,

Continuing the series  Ultrasonic rangefinder project , More testing for ultrasonic rangefinderUltrasonic rangefinders arrivedUltrasonic rangefinder without amplifier, and Ultrasonic rangefinder with loudspeaker I tried measuring the (magnitude of) impedance of the transmitter in the same way that I measured loudspeakers.  That is, I put the transmitter in series with a resistor, and drove the pair from a function generator, measuring the voltages across the transmitter and the resistor simultaneously with a pair of voltmeters.  I did this in the circuits lab, so that I could use the high-quality multimeters and function generators there—I no longer have a multimeter at home that is good at high frequencies.

I did not have my laptop handy while I was making the measurements, so I recorded them on paper and typed them up later.  It would have been good to have plotted the data as I collected it, so that I could get more points in  regions where there was rapid variation in impedance.  I’ll probably have to go back to the lab later this week and collect another data set, with much finer spacing between 30kHz and 70kHz.

The transmitter behaves like a capacitor of 1.76nF at low frequency, and 1.36nF at high frequency. Near the resonance, things get complicated. Unlike the inductive loudspeaker, where impedance goes up at the resonance, the capacitive transmitter has decreased impedance at the resonance. [Update:2016 March 15, fixed the capacitance from µF to nF.]

I used a 100Ω series resistor, arbitrarily chosen.  In retrospect it would have been better to use a 2.2kΩ resistor, to more closely match the impedance of the transmitter in the region of interest between 30kHz and 70kHz.

There isn’t a single resonance at 40kHz, like I expected, but three resonances (maybe more), around 39.2kHz, 42kHz, and 55KHz.  There seems to be an antiresonance around 43 kHz.  The multiple resonant frequencies are probably due to different vibration modes, and may account for some of the difficulty in getting a short burst produced by the transmitter—even if I can cancel one mode, there is another mode still being somewhat excited.

The first resonance is around 39.2kHz, which is probably in spec (not that these cheap transmitters have data sheets that I can access—more expensive ones are generally 40kHz±1kHz for the resonance).  At the resonant frequency, the impedance is about 610Ω, so a ±3.3V swing would require ±5.4mA.  (Note: since my measurements were not very closely spaced here, I may have missed the peak, which could be as low as 500Ω.)

The digital output pins of the Teensy 3.1 board I’m using for the rangefinder are only specified to 2mA (except a couple of high-drive pins, which I’m not using).  Using inverters with 5V power to drive the transmitter would need  8.2mA, but the inverters I have are only specified to 4mA, so I might want to use two or even three in parallel for each pin of the transmitter.

Of course, the measurements I made were for steady-state frequency response, not the response for starting the transmitter moving from being motionless—there may well be a different impedance that is relevant then (I suspect that more current may be needed when the transmitter isn’t already moving at the resonant frequency).

## 2016 February 17

### Ultrasonic rangefinder with loudspeaker

Filed under: Data acquisition,freshman design seminar — gasstationwithoutpumps @ 23:29
Tags: , ,

Continuing the series Ultrasonic rangefinder project , More testing for ultrasonic rangefinderUltrasonic rangefinders arrived, and Ultrasonic rangefinder without amplifier, I tried today to look at creating pings with a non-resonant transmitter: a cheap, mid-range 8Ω loudspeaker that I’d used for the applied electronics class.  It was a buyout special from Parts Express, and so is no longer available.  There is an analysis of this speaker (or another one like it) in Better model for loudspeaker.

I was curious whether I’d be able to get it to produce sound at 40kHz, so I hooked it up to a pair of output pins of the Teensy 3.1 and used the microphone and preamplifier to listen to it with the Teensy, as in Ultrasonic rangefinders arrived.  The results were disappointing (as I expected).  The loudspeaker made an audible click, but the waveform showed no evidence of 40kHz signal, even with 10 cycles of excitation. I got echos, but they were of the click rather than of a ping, and were essentially independent of how many cycles of excitation I provided.

I then tested the loudspeaker and microphone combination with my FG085 function generator, and saw that the amplitude of the response varied enormously with frequency (and that some of the largest responses were ones I couldn’t hear—my deafness does not seem to be uniform in the higher frequencies).  There are zeroes around 21750Hz and 28500Hz, and no signal above 31750Hz.  The microphone and preamp were still working at 40kHz, so the problem is with the loudspeaker, not the mic or preamp.

I should probably get a cheap little speaker that is rated to 20kHz, and see whether it can actually go to 40kHz.  Digikey has some $1 and$2 speakers that look suitable, except that they seem to be designed to be pressed against a PC board with a spring, which might make them hard to connect to a breadboard.  For about \$3, I could get one with pins, but the high-frequency response seems not as good.

I could also try making a pinger at 20kHz, instead of 40kHz, and see whether I can get decent pulse shapes with the existing speaker.

I managed to get a 20kHz ping recorded from the loudspeaker, but I had trouble getting a clean ping, as there was always echo off the floor, my hand, or the tabletop (whatever was supporting the loudspeaker) producing another burst very soon after the first one, interfering with it. I tried separating the mic and loudspeaker to record the direct wave (without much echo), but that was still unclean. I think I need to have a good baffle to make a clean pulse, and a directional mike would be better than the omnidirectional one I currently have.

Here is a sample recording with the loudspeaker putting out 5 cycles (10 half cycles) at 20kHz and a bounce off the bottom of my table.  The messiness of the return echo is partly interference from bounces off the floor behind the mic and speaker, and partly the unevenness of the bottom surface of the table (which is made of aluminum slats).

The burst begins almost exactly when I would expect it to, but it is not as clean as I would like to see.

I think that with non-resonant transducers I could get cleaner deconvolution of the echoes, but first I have to find a way to reduce the multi-path problem (perhaps with a directional mike and a baffled speaker?).

## 2016 February 12

### Ultrasonic rangefinder without amplifier

Filed under: Data acquisition,freshman design seminar — gasstationwithoutpumps @ 21:20
Tags: ,

I’m still working on doing the ultrasonic rangefinder project  myself, though I have already determined that it is feasible for the freshmen in the design seminar. In More testing for ultrasonic rangefinder, I gave a digital filter and showed it working with a non-resonant electret microphone and amplifier and pings from a Maxbotix rangefinder.  In Ultrasonic rangefinders arrived, I looked at generating good 40kHz pings while listening to the direct sound with a microphone and amplifier.

Yesterday and today, I tried setting up a rangefinder without an amplifier, using the resonant piezoelectric receiver, instead of the non-resonant microphone and amplifier.

This rangefinder has no amplifier, just a high-pass RC filter to block 60Hz and audio interference.

I used this circuit in lab today to demonstrate the use of the digital oscilloscopes. We looked at the signal to the transmitter and the signal back from the receiver. I showed them the use of an extra channel (and an extra digital output from the Teensy board—pin 13 to flash the on-board LED) to trigger the sweep when the burst signal started.

If I make the initial burst loud enough (which requires making it last longer, with more cycles to build up the resonance), I can see the return echo even with no amplification:

The signal-to-noise ratio is poor, but the echoes from 1, 2, and 3 round trips are clearly visible at around 4ms, 8ms, and 12 ms.

The delays are a little longer than I would have expected, but I don’t know whether this is because of sloppy measurement of the distance, failure to check the temperature and relative humidity and compute the speed of sound more accurately, or longer ringing than expected and not seeing the beginning of the burst. All probably contribute to the error.

We can zoom in on the raw recorded signal around the first echo:

The zoomed-in raw data shows background noise around ±4mV and the first echo around ±12mV.

It is not entirely clear where the echo starts—I’m guessing around 4020µs, when I would have expected it closer to 3880µs.  That would be about a 2.4cm error in measuring the distance to the table, which is possible, but a larger error than I would have expected (the bottom of the table is not smooth, but the fluctuations in distance are 1cm, not 2.4cm).  The 3.6% difference in time corresponds to a very low temperature—maybe –30°C, and my bedroom is not that cold! (It is probably around 17°C, for a speed of sound around 342 m/s, which would suggest a delay of 3860µs, even earlier than the 3880µs I estimated when using 340m/s as a crude estimate of the speed of sound.

The second bump around 4800–5200µs is probably the vibrations from the mode change that we saw in the transmitter recordings in Ultrasonic rangefinders arrived.

The digital filtering improved the signal-to-noise ratio, from about 3:1 to about 6:1 for the first echo. Amplifying the signal from the receiver before digitizing it should improve the signal-to-noise ratio, since much of the noise we’re seeing is the noise of the analog-to-digital converter—using more of its range should clean the signal up a lot.

« Previous PageNext Page »