On my previous post, we calculated that when a paintball gun fires, the propellant gas used for a shot is predicted to get extremely cold, from room temperature down to something in the vicinity of 167 K. I wondered to myself if it would be possible to actually measure this temperature before the gas absorbed heat from its surroundings and warmed back up. Wondering is always a dangerous thing, because you might end up spending a hundred hours or so trying to solve a problem that has no practical bearing on your everyday life. Nevertheless...
When you measure the temperature of the air outside, you might use a bimetallic strip dial thermometer. If it's a cold day when you put out your thermometer, you might even see the dial turning perceptibly as the strip cools off. However, it takes several minutes for the thermometer equilibrate with the surroundings to accurately measure the temperature. A small volume of very cold gas will warm up much faster than a typical thermometer will cool down. The thermal mass of the gas is tiny. Something like 0.04 grams of gas remains in the chamber after it is depressurized, and it won't take a whole lot of heat transferred from the metal chamber to the gas to warm it significantly.
Fortunately, there are many other gas properties that can be measured very quickly that can be correlated to temperature. As I once heard, "Every sensor is a temperature sensor. Some sensors measure other things as well." One well-understood relation is how the speed of sound in a gas varies with temperature. If we could find some way to rapidly measure the speed of sound of the gas immediately after it is depressurized, we could calculate the temperature of the gas fairly easily.
One way we could measure the speed of sound is to use the fact that certain frequencies should resonate in a tube in a predictable manner that is a function of the air's speed of sound. For a simple case, you can think of it as the sound's pressure pulse bouncing around off of the ends of the tube. The time it takes the pulse to travel down the tube and back is dictated by the speed of sound and the length of the tube. When you blow across a tube (or a wind instrument) you can hear a sound at a frequency that correspond to the tube's resonant frequency. For a fixed length of tube, the resonant frequency should vary only as the speed of sound varies.
A simple formula gives the speed of sound of an ideal gas, which should be quite accurate for air at modest temperatures and pressures.
Combining the two formulas above, we should be able to predict how the resonant frequency will vary as the temperature varies (with a constant characteristic length).
Or, rearranging to solve directly for temperature:
If we can make a device that creates a sound pulse and listens for its echo, all contained within a vessel that can be pressurized to the pressure of a typical paintball gun's operating pressure, we could actually have a shot of measuring the temperature of the gas extremely quickly, on the order of the time it takes for the sound pulse to bounce back and forth a handful of times.
I have a stainless steel pressure vessel which I can use to simulate a paintball gun's pressure chamber. I attached two small piezo buzzers to the inside of a reducing bushing, and I drilled a small hole through a brass plug to feed through wires to connect the piezos to a RP2040 Adalogger microcontroller. I inserted a short section of 1" nominal diameter PVC pipe that is 81 mm long with a 4 mm hole drilled in the end around the piezos to allow the pressurized air to rapidly escape when it is vented.
One of the piezos is triggered on and quickly back off again to make a short chirp, while the second one listens for the echoes from that chirp afterwards. The signal from the sensor piezo is amplified to more closely match the full analog-digital-converter measurement range of the microcontroller. At 15 degrees C ambient temperature and at atmospheric pressure, I recorded the following echo pattern from a single piezo chirp:
Well, there is clearly a repeating pattern there, but it seems to be a pretty complex signal, probably from multiple echoes within the chamber. We might have echoes from wall to wall, or from the slightly raised piezo housing to the wall, or radially within the pipe itself. It ultimately doesn't really matter what is causing the most dominant echo/resonance, so long as we can precisely measure its frequency and so long as the distance the sound wave is traveling doesn't change when the temperature of the gas is sharply reduced.
If we were just to measure the peak-to-peak time difference, we are going to have a couple of problems. First, we aren't going to be able to measure it very precisely. The RP2040 as I have it set up can sample at a maximum rate of about 200,000 samples per second, about 5 microseconds between samples. Clearly there is a signal with peaks about every 140 microseconds, but with 5 microseconds of uncertainty, we can only measure the frequency with an accuracy of about 3% or so. We would also have some trouble picking out the exact peak with what is clearly a complex interference pattern going on. Fortunately we have a bit of math we can do to extract this information - the Fourier Transform, which can take a complex signal and extract the constituent frequencies. Fortunately for me, someone else has done the legwork to implement a Fourier transform algorithm for the Arduino.
Using the library linked above (and after some data processing to amplify the signal as it attenuates over 20 milliseconds or so), the microcontroller performs a fast Fourier transform on the resulting signal to determine which frequencies were present. When this is performed at a known temperature, you can the formula above to solve for the characteristic lengths of those resonant frequencies, which hopefully should remain constant when the temperature of the air inside changes.
Doing this for air at 15 degrees C and atmospheric pressure yields the following spectrum:
There's one especially prominent peak at 7666 Hz and a few other minor ones in the neighborhood. Translating those into characteristic lengths for a speed of sound of 340 m/s at 15 degrees C:
Curiously, the one I expected to be most prominent, corresponding to roughly 0.16 meters round-trip length down and back up the tube, is entirely absent, but its second, third, and fourth overtones are present, corresponding to the peaks at 0.0774 m, 0.0535 m, and 0.0389 m (one half, one third, and one fourth the round trip length). By far the most prominent peak, at 0.0444 m, doesn't seem to obviously correspond to anything, except curiously it is almost exactly 5/3 of the internal diameter of the Schedule 40 1" pipe, so perhaps it corresponds to a complex radial sound reflection within the pipe. Perhaps another thing to spend too much time on later.
But anyways, for our purposes, we really don't care what physical dimension the resonant peaks correspond to, only that they are still resonant when the temperature is rapidly reduced. When the temperature falls, the speed of sound should fall as well, being proportional to the square root of temperature. We expected air at 115 psia and 300K to chill down to 167K when isentropically expanded to 1 atmosphere pressure in our previous study. I ran a test with the chamber at slightly different conditions - air at 110 psia and 288 K initially, which should isentropically cool to 162K when expanded to atmospheric pressure.
I programmed the microcontroller to begin pinging and recording as soon as it heard the loud sound of the gas venting out of the chamber, with pings repeated every 20.48 milliseconds. The RP2040's 256 KB of RAM allows us to record about 1.2 seconds of data with one sample every 20 microseconds (50 kHz sampling rate, a bit better than CD audio quality sample rate). After if fills its RAM, it continues pinging and recording as fast as it can compute the Fourier transform and record the results to the SD card, which works out to about one measurement every 160 milliseconds.
This yielded the following series of spectra (click for animation)
The first 80 milliseconds were extremely noisy, understandably as the air was rapidly rushing out of the chamber. Starting with the measurement at 102 milliseconds (the green spectrum in the animation above), the noise had subsided to the point where clear frequency peaks were visible. These peaks waxed and waned in intensity, but the most prominent ones remained traceable as they shifted to higher frequencies for the entire 30 second duration of sampling. We can see that the most prominent final peak at 7666 Hz originated at about 6080 Hz. We know that this peak corresponded to a wavelength of 0.0444m from the formula earlier, so plugging this frequency into our formula for temperature:
Hey, not bad! We can go a step further and translate the dominant peak directly into temperature and follow the temperature as the peak shifts to the right (click for animation)
If we extrapolate backwards to the trigger time using the rate of change of temperature observed during the first 100 milliseconds of good data (about 182 degrees K per second), we can estimate that the temperature at the trigger time was awfully close to the 162K we calculated it should be. Nice!
There's still a few nagging questions. First, how do we know that the frequency peaks we see are associated with the gas properties and aren't related to the mechanics of the piezo transmitter and sensor? Fortunately, there's a pretty easy way to check for that. If we fill the chamber with a gas with a different but predictable speed of sound, we can check and see if we get peaks at the same characteristic lengths. I repeated the experiment with carbon dioxide in the chamber instead of air. Carbon dioxide and air have different molecular weights and ratios of specific heats. Plugging CO2's properties into the speed of sound formula, we expect a speed of sound of 266 m/s at 15 C (compared to 340 m/s for air). Repeating the experiment at 1 atmosphere and 15 degrees C, we obtain the following characteristic length peaks:
The peaks line right up! Interestingly for some reason the CO2 spectrum also has the tube length divided by 5 (0.031 m) and 6 (0.026 m) peaks also, which were absent in the air spectrum.
I think I've more or less accomplished the goal I set out to in figuring out a way to measure the temperature of a gas right after it is depressurized, and it's satisfying to see how close to the predicted temperature I was able to actually measure. If you see any errors or can think of any interesting applications of this setup, I'd be curious to hear about it.


No comments:
Post a Comment