Gas station without pumps

2016 December 30

Ultrasonic rangefinder with Analog Discovery 2

In Loudspeaker impedance with Analog Discovery 2, I looked at the impedance of  various loudspeakers including an ultrasonic transducer. Today I looked at shaping pulse bursts for driving an ultrasonic transmitter to get shorter received pulses with an ultrasonic receiver.  I’ve done this before using custom programs on a Teensy 3.1 board (see Ultrasonic rangefinders arrived), but I wanted to see what I could do using just the waveform generator on the Analog Discovery 2.

I measured the magnitude of the impedance of the transmitter (using either a 120kΩ resistor or a 1nF capacitor as a known impedance), then looked at the transmitter+receiver characteristics for frequencies around the resonances.  I’ve marked the peak received resonances on the impedance plot.

The impedance is approx 2.2nF, with 3 apparent resonances.

The primary resonance is around 40kHz, and is the frequency that the transmitter is designed to operate at.

There is a secondary resonance around 54kHz, though it is considerably weaker than the 40kHz resonance.

The third resonance, around 330kHz does not provide a very strong signal for the receiver.

I tried two tests using the 40.445kHz resonance. In one, I used the simple waveform generator to produce a 40445Hz square wave, then used an 8ms wait and a 148.3µs run time, to produce bursts of 6 square waves. I set the idle output to the offset (0v) and used a 5V amplitude.

In the other test, I used the same wait and run times, but used the “custom” waveform to set up a signal that inverted the last 3 of the 6 periods (so that the half periods were +-+-+--+-+-+. This was fairly easy to set up by generating the 6 periods, then altering them by multiplying by a single period of a square wave. I could have created much more complicated bursts, but this pattern was enough to see the capabilities of the scope.

By triggering the scope on the signal sent to the transmitter (using channel 1), I could average 1000 sweeps to get a very low-noise view of the signal. (I can trigger on the waveform generator itself, freeing up one of the scope channels, but then I can’t average—I think that the averaging relies on interpolating get precise timing of the trigger.)  For plotting, I subtracted off the DC bias (fitted before time 0), as 60Hz interference caused a moderate offset to the signal even after averaging.

The bursts start out the same, but the simple 6-cycle burst results in the received waveform growing for 14 or 15 cycles, while the 3+,3- burst grows for 6–7 cycles and decays very quickly.

I tried some longer and shorter bursts, with the expected result that longer bursts resulted in stronger signals with a longer received burst width. Doing 8 cycles followed by 8 cancelling cycles seemed to produce a reasonable length burst with a fairly strong signal, but I did not explore variants much.

I still think it might be possible to use the phase information to get higher resolution than the approx 7.9mm wavelength, but identifying which pulse of the return waveform is which remains a problem, particularly if there is a complicated reflecting surface that superimposes several differently delayed pulses.

2016 December 28

Headphone impedance with Analog Discovery 2

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 22:41
Tags: , , ,

In Loudspeaker impedance with Analog Discovery 2, I described measuring the impedance of loudspeakers with the network analyzer function of the Analog Discovery 2. In this post, I looked at some new Panasonic headphones that I got myself for Christmas (Panasonic RP-HJE120-PPK In-Ear Headphone, the best-seller on Amazon and the same model my son has, though in a different color).

I have figured out how to use the Waveforms 2015 software a little better now, so I can compute the magnitude of impedance as an extra column in the output (using the “Custom One” optional calculated channel).  This cuts down slightly on the missing metadata from the data files, though I really wish that they would do a dump of the instrument settings as comments at the beginning of the file.

The headphones had essentially the same curves whether in the ear or not in the ear, so I am just plotting the in-ear electrical characteristics.

The headphones are fairly well fit by a simple model: a resistor in series with an inductor.

Zooming into the audio region shows surprisingly little variation in the impedance over the whole audio range. There is a small resonance peak around 2.6kHz, but it is small and broad, nothing like the resonance peaks of loudspeakers.

I had some problems with repeatability of measurements, with curves jumping 0.5Ω up or down, but preserving their shape. I think that the problem is with poor contacts in the breadboard I was using, as I had the same problems earlier characterizing nFETs. The resonance peak around 2.6kHz corresponds roughly with the peak of information content in speech, so slight enhancement there is probably perceived as improved audio quality over a completely flat spectrum. But the enhancement here is tiny, so it may just be the result of flattening the spectrum as much as feasible.

The noise in the measurements probably reflects the small signal levels—I had an 18Ω resistor in series with the 16Ω headphones, and an amplitude of only 25mV across the pair, which gives me only 8.3mV RMS at the headphones.  That means that only 4.2µW of power is being used to generate the sound.  Panasonic claims a sensitivity of 96dB/mW, so 4.2µW should be about 72dB SPL (remember that dB is $10 \log_{10}$ of a power ratio, and $10 \log_{10}$ of an amplitude ratio). The 72dB seems about right for the loudness.  The headphones can supposedly handle 200mW, which would be 119dB—easily loud enough to cause permanent hearing loss.  Perhaps I should have students test their preamplifiers with earbud headphones instead of loudspeakers—the 24mA limit would give 9mW, which would be quite loud in a headphone.

The R+L model does not fit at high frequencies all that well, and the phase relationships are not what one would expect of a pure R+L model:

The phase only gets to 60°, while a true inductor in series with a resistor would have reached 90° and done so somewhat sooner.

Overall, I’m impressed at how flat the impedance is over the audio range. I don’t know how good the headphones are acoustically (especially as my hearing seems to be really down in the 4kHz–8kHz range—signals seem louder to me at 9kHz than at 5kHz), but I’ve no complaints about them so far.

2016 December 13

Loudspeaker impedance with Analog Discovery 2

Filed under: Data acquisition — gasstationwithoutpumps @ 23:12
Tags: , , , ,

One of the features of the Analog Discovery 2 that convinced me to buy it (rather than, say, a Rigol digital scope) was the ability to couple the waveform generator to the scope to do network analysis.  The basic idea of network analysis is to measure voltages at the output and the input of a 2-port network taking their ratio at different frequencies to get the response of the network.

Here is a generic 2-port network with a shared ground. If a sine wave is applied to the input, then the output will also be a sine wave (for a linear network) of the same frequency, but a different amplitude and phase.

If you model a linear system with complex numbers, then the output of any linear network driven by $e^{j \omega t}$ is $A e^{j \phi} e^{j \omega t}$, and the ratio of the output to the input is $A e^{j \phi}$. A network analyzer drives a network with a succession of different sine waves, recording the amplitude ratio $A$ and the phase shift $\phi$ for each frequency.

I haven’t often needed a network analyzer, but I have many times done something very similar: impedance spectroscopy, which looks at the ratio of the voltage to the current at different frequencies. The loudspeaker and electrode labs in the course both do this, but only recording the amplitude ratio, not the phase change, as hand measurements with voltmeters do not provide a way to determine the phase.

Because the network analyzer just takes the ratio of Channel 2 divided by Channel 1 and both are differential input channels, we can use it as an impedance spectrometer.  We just put the device under test (DUT) in series with a known impedance (comparable to the one to be measured), drive the series chain with the waveform generator, and measure the voltage across the two impedances.  We then have $Z_{DUT} = Z_{known} V_{DUT}/V_{known}$.

For example, here is the result of running the network analyzer for an 8Ω loudspeaker with a 33Ω known impedance:

At frequencies above about 1MHz, I don’t believe that the test setup is really measuring the behavior of the loudspeaker.

For impedance spectroscopy, the default display with the amplitude in dB is not particularly friendly, so I saved the data, fitted a model to it with gnuplot, and plotted it:

Loudspeaker model to fit.

Amplitude data and fitted model. Note that the impedance does not rise as fast as a simple inductor for L1 would imply.

Compare the plot above with the hand-measured ones at Better model for loudspeaker or Loudspeaker analysis.  We can see the limitations of the model even more clearly when we look at the phase change:

At low frequencies, the model and the measurements fit well, but at high frequencies, the phase only goes to 50°, not 90° as would be expected of an inductor.

I also measured a tiny 8Ω loudspeaker that I had bought to experiment with ultrasonics (see Redoing impedance test for tiny loudspeaker):

The main resonance around 1390Hz is clearly visible, but there appear to be some higher resonances as well.  We can do a more focussed sweep to see them clearer:

The secondary resonance peaks are clearly visible when we scan a narrower range.

The model for the tiny loudspeaker fits the phase measurements better than for the larger loudspeaker, but the phase still only gets to 66°, not 90°.

I also tried one of the ultrasonic transmitters (see Ultrasonic transmitter impedance again for hand measurements):

With a 33Ω current-sense resistor, the low frequency end of the impedance spectrum is just noise—there is almost no voltage drop across the 33Ω resistor.

Using 1nF capacitor as a reference impedance, rather than a resistor, results in much more comparable voltages across the whole frequency range, and a cleaner impedance spectrum. But at low frequencies, we’re really seeing the impedance of oscilloscope inputs, rather than the ultrasonic transmitter.

For the piezoelectric ultrasonic transducer, the phase spectrum is easier to see the resonances in.

There are some high frequency resonances as well as the main ones.

I also tried using the network analyzer as a proper network analyzer, where the network consisted of the tiny loudspeaker acoustically coupled to  an electret microphone which had a 10kΩ pullup to 5V:

The 9.5–10kHz peak was distinctly audible (even though I’m rather deaf in that range), so the resonance was in the loudspeaker not the microphone.

I get somewhat different results with the larger 8Ω loudspeaker:

I have a much more uniform response across frequencies, but it looks like I get a fairly strong response even at very high frequencies. I wonder if I’m seeing an electrical rather than acoustic coupling.

Finally, the ultrasonic transmitter:

With a 2V amplitude (instead of 500mV) I get a smaller signal from the ultrasonic transmitter. There does not seem to be a peak at 40kHz, where the transducer is normally used.

There is an antiresonance around 39kHz and a resonance around 54kHz. Perhaps it would be better to use the transmitter at 54kHz than at the normal 40kHz!

2016 August 19

Redoing impedance test for tiny loudspeaker

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

In Ultrasonic rangefinder tests with tiny loudspeaker, I tested the 10mm CDM-10008 loudspeaker and found it ringing around 9.4kHz, but I reported

I don’t see any resonance around 9.4kHz in the impedance plot, though I admit not looking for narrow resonance peaks in that range.

Today I redid the impedance tests using a 10Ω sense resistor, so that I could use the same range for all voltage measurements, resulting in more correct impedance measurements.  I could definitely hear a resonance around 9.5kHz (and given my deafness at high frequencies, it must have been very loud indeed for me to hear it so clearly), so I looked for another peak in that neighborhood.  It is there and measurable, but not very prominent in the plot:

Because the second peak is on the sloping part of the plot and quite small, I had to model the loudspeaker with a j ωα L semi-inductor to get a good fit.

I have not attempted to fit the data points past 200kHz, because I don’t believe that the multimeter I was using is really good at those frequencies.  The “corner frequency” I’m reporting around 100kHz is where the DC resistance is equal in magnitude to the impedance of the semi-inductor.

Given how small the peak is on the |Z| graph, but how loud the sound is around 9.5kHz, I probably need a different way of looking for resonances beyond the main one. I can’t rely on my ears for loudness at high frequencies, but perhaps I could use a microphone and record the amplitude it sees as a function of frequency.

2016 August 18

Ultrasonic rangefinder tests with tiny loudspeaker

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

I’m still working on doing the ultrasonic rangefinder project  (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. In Ultrasonic rangefinder without amplifier, I tried seeing if we could use the transducers without an amplifier. In Ultrasonic rangefinder with loudspeaker, I tried using a midrange loudspeaker to generate the pings (but was limited to about 20kHz.)

For the past couple of days I’ve been working with a tiny (10mm) loudspeaker, to see if I could get to higher frequencies without a resonant transducer, so that I could play with doing spread-spectrum pings that can be deconvolved to get more precise and more accurate measurements of echoes. I expected the 8Ω loudspeaker to be much less efficient than a resonant transmitter, but beyond that I had few preconceived notions of how well it would work.

Here is the front of the CDM-10008 10mm loudspeaker.

Here is the back of the loudspeaker, with the two solder points visible on the bottom.

Soldering the leads on was more difficult than I expected. I started out putting the loudspeaker face down on the bench and approaching it with the wire and soldering iron, but the loudspeaker jumped off the bench and stuck to the iron—I’d forgotten that the soldering iron tip really does contain iron, and that the magnet for the tiny loudspeaker is unshielded. After sticking the loudspeaker into a Panavise board holder, I had no trouble soldering on the leads.

Here is the loudspeaker with wires soldered on, and a female header with some double-ended male header pins to make it easier to attach to a breadboard.

The first thing to do (after checking that the leads weren’t shorted) was to measure the impedance as a function of frequency, using a voltmeter, a 100Ω series resistor, and a function generator. I was working at home, so I used a Fluke 8060A multimeter that I bought used on e-bay (which replaced my old 8060A that had failed). Unfortunately, the “new” meter is not much better, as the different voltage ranges seem to have radically different calibration. I used one range consistently for the loudspeaker voltage, and another consistently for the resistor voltage, so the shape of the curve should be ok (up to 300kHz), but |Z| may need to be shifted up or down by as much as 20%.

The resonant peak at 1340Hz is consistent with the datasheet, which specifies 1200Hz with a range from 960Hz to 1440Hz. They specify the power output for the speaker in the range around the resonant peak, which gives an exaggerated view of the response elsewhere.

I tried driving the loudspeaker directly from pins 16 and 17 of the Teensy LC, which I had configured for high drive, with the setup() routine containing

    CORE_PIN16_CONFIG |= PORT_PCR_DSE;
CORE_PIN17_CONFIG |= PORT_PCR_DSE;


I also put a 10Ω resistor in series with the 8Ω loudspeaker, to limit the current demanded of the I/O pins (though still far more than they are supposed to deliver). With this setup I got about ±1.6V between the pins, ±860mV across the resistor (so ±86mA), and ±670mV across the loudspeaker. The loudspeaker voltages showed spikes, but the resistor voltages were fairly clean square waves, even with 100kHz square waves.

I then made an amplifier for the electret microphone, keeping the gain per stage low to avoid the 1MHz gain-bandwidth limit of the MCP6004 op amps. With a gain of only 10 per stage, I should have a bandwidth close to 100kHz.

Here is the schematic for my test fixture. I looked at the microphone and speaker signals with both my Bitscope oscilloscope and at the microphone signals with the Teensy ADC.

I started out looking a some complicated pulse patterns that I had designed to have high energy in the 20kHz–50kHz range, but a low autocorrelation other than at 0s. These pulse patterns should be good for the spread-spectrum tests I wanted to make. I was disappointed, however, in not being able to see the patterns in the recordings from the microphone, so I switched to a simpler stimulus—a single short pulse.

Short pulses seemed to trigger a resonance in the loudspeaker at about 9.4kHz, though short pulses resulted in an initial higher frequency mode being excited.

Each of the plots were made by averaging about 3 dozen traces recorded by the Teensy, to reduce noise. I found that I had to unplug the power supply from the laptop that was providing the USB power, as I otherwise got a lot of 90kHz noise.

I don’t see any resonance around 9.4kHz in the impedance plot, though I admit not looking for narrow resonance peaks in that range. I was a little worried that it might be related to the high-pass filters in the amplifiers which had a corner frequency near there, so I redid the tests with different filters, changing the 330pF to 680pF, so lowering the corner frequency to 4590Hz. The impulse response is much the same:

The signal is a little stronger with the high-pass having a lower corner frequency, but otherwise not changed much.

Note: the signal visible before the sound arrives is probably due to electrical noise from the loudspeaker coupled through the power supply,as it appears as the pulse is shut off.

Unfortunately, this little loudspeaker does not seem to be usable for the spread-spectrum sound production that I had hoped for, as the 9.4kHz ringing is definitely going to corrupt any high-frequency waveform I try to impose.

The ringing the loudspeaker is larger than for the ultrasonic transducer, so we’re actually getting more sound, but the transducer takes much less current, and I’ve not attempted to compare efficiencies.  Both ring for 1–1.5ms, which is too long for what I wanted to do.

Next Page »

Create a free website or blog at WordPress.com.