SciELO - Scientific Electronic Library Online

 
vol.10 número1Smartphones on the air track. Examples and difficulties índice de autoresíndice de materiabúsqueda de artículos
Home Pagelista alfabética de revistas  

Servicios Personalizados

Revista

Articulo

Indicadores

  • No hay articulos citadosCitado por SciELO

Links relacionados

  • No hay articulos similaresSimilares en SciELO

Compartir


Papers in physics

versión On-line ISSN 1852-4249

Pap. Phys. vol.10 no.1 La Plata jun. 2018

 

Articles

Smartphone audio port data collection cookbook

 

Kyle Forinash,1 Raymond Wisman

E-mail: kforinas@ius.edu
E-mail: rwisman@ius.edu
1 Indiana University Southeast, 4201 Grantline Road, New Albany, Indiana 47150, USA.

DOI: http://dx.doi.org/10.4279/PIP.100006


The audio port of a smartphone is designed to send and receive audio but can be harnessed for portable, economical, and accurate data collection from a variety of sources. While smartphones have internal sensors to measure a number of physical phenomena such as acceleration, magnetism and illumination levels, measurement of other phenomena such as voltage, external temperature, or accurate timing of moving objects are excluded. The audio port cannot be only employed to sense external phenomena. It has the additional advantage of timing precision; because audio is recorded or played at a controlled rate separated from other smartphone activities, timings based on audio can be highly accurate. The following outlines unpublished details of the audio port technical elements for data collection, a general data collection recipe and an example timing application for Android devices.

Mobile device, cell phone, laboratory


 

I. Audio port technical elements for data collection

The audio port physical interface to the smart-phone is a 4-pole jack connecting to some external device. Table 1 presents the American Headset Jack (AHJ) standard used by many smartphones for connections to the 4-pole jack. Figures 1 and 2 present two similar measurement circuits based upon the same resistor-capacitor network, Fig. 1 circuit for temperature measurements [1] and Fig. 2 circuit with a pair of photoresistors acting as gates for timing measurements of a moving object [2].

Although timing and temperature measures are obviously different, the circuits and data collection methods are quite similar. In each circuit, a variable resistor connects the speaker audio output to the microphone input; the speaker output is a wave which peak amplitude at the microphone input varies with the variable resistor, greater resistance resulting in lower peak amplitude. Figure 3 illustrates the effect of a photoresistor on the microphone signal amplitude while a moving object momentarily blocks and reduces the illumination reaching the photoresistor - as the illumination decreases, resistance increases and peak amplitude decreases.

The microphone input amplitude is digitally sampled (44100 samples per second is common) over time as displayed in Fig. 4. Each digital value represents the speaker output amplitude as changed by the circuit, then received and digitized as the microphone input.

A recipe for data collection with Fig. 1 and 2 type circuits generally is:

1.  Choose a variable resistor to measure some phenomena such as force, humidity, etc.

2.  Generate a wave of fixed frequency and peak amplitude through the speaker output and sample it as the microphone input as illustrated in Fig. 4.

3.  Detect the significant elements of the microphone input. Significant for timing applications, wave peaks can be detected by the simple method described in Fig. 4.

4.  Convert the significant elements to corresponding data. For example, by recording a range of peak amplitudes produced by the circuit of Fig. 1 and the corresponding temperatures, an equation fitted to that amplitude vs. temperature data can convert the circuit amplitude output to temperature.

 


Figure 3: Microphone input signal amplitude versus time graph from circuit in Fig. 2 when measuring an object falling from 1 meter. The amplitude of the wave input at the microphone drops as the object entering the first photoresistor (PR1) at time 6.2041 s and again at time 6.6607 s when entering the second photoresistor (PR2). The measured time of 0.456 s compares favorably with the predicted time of 0.451 s.


Figure 4: Speaker output of a 4410 Hz sine wave sampled at 44100 samples per second at the microphone, producing the highlighted 10 samples per wave. Simple peak detection is possible by comparing three consecutive samples (x0, x1, x2) where: 0 < x0 < x1 > x2 > 0 the wave peak occurs at sample x1.

 

II. Timing data collection recipe

For timing of a moving object, some form of gate is needed to detect entry and exit. Ideally, gates are binary, they only open or close with no intermediate states, unfortunately reality does not represent the ideal case. For timing applications, the circuit of Fig. 2 includes one or more photoresistors (gates) connected serially so that when all are illuminated (closed) resistance is at its minimum and the peak signal amplitude input to the microphone is at its maximum; hence, when illumination of any one of the photoresistors is reduced, circuit resistance increases and the signal amplitude reduces.

Because the photoresistor resistance does not change instantaneously when illumination changes, as illustrated in Fig. 3 by the gradual peak ampli-tude drop, and in the case where one photoresistor is illuminated differently than another producing a different amplitude result for each, a peak amplitude threshold must be determined. Above the threshold a gate is considered closed (exited) and below the threshold a gate is considered open (entered). To determine the threshold, the peak amplitude is initially calibrated by illuminating (closing) all gates and incrementally increasing the speaker volume until the microphone peak amplitude approaches its maximum, M. After fixing the volume for M, the microphone peak amplitude for the circuit when any single gate is open (entered), L, is determined by blocking (entering) each gate in turn and recording its lowest peak amplitude. L is set to the greatest peak amplitude of any blocked gate to ensure the threshold is crossed when any gate is blocked. The maximum M and minimum L then set the upper and lower output limits of the circuit peak amplitude. The threshold amplitude, TA, the peak amplitude level that determines when an object enters or exits a gate is: TA=(M+L)/2, the amplitude midpoint between M and L. An amplitude crossing the threshold from above is defined as gate entered, while crossing it from below is defined as gate exited.

With the threshold defined, deriving timing data from the microphone audio is both straightforward and accurate. From the general recipe, the practi-calities of timing a moving object reduces to:

1.  Choose a photoresistor to measure illumina-tion.

2.  Generate a sine wave of 4410 Hz and volume setting at M through the speaker and sample at the microphone at 44100 samples per second which corresponds to 10 samples per wave.

3.  Detect the wave peaks by the method described in Fig. 4.

4.  Convert wave peaks to corresponding timing data by noting the sample number at threshold crossings.

Microphone input sampling occurs at 44100 samples per second or one sample every 0.000023 s (equals 1 sample/44100 samples/second). Accurate timing between events is simply a matter of count-ing samples between threshold crossings. Gates are entered when a wave peak crosses the threshold from above and the sample number of the peak is recorded at this time. Similarly, gates are exited when a wave peak crosses the threshold from be-low. The time between entering two gates is then:

where t=time between Gate 1 and 2, g1 = Gate 1 entry sample number, and g2 = Gate 2 entry sample number.

Figure 3 illustrates the microphone input while timing the one meter free fall of an object when entering two photoresistor gates. The amplitude of the wave input at the microphone drops as the ob-ject entering the first photoresistor (PR1) at time 6.2041 s and again at time 6.6607 s when enter-ing the second photoresistor (PR2). The measured time of 0.456 s = 20110 samples/44100 sam-ples/second compares favorably with the predicted time of 0.451 s.

The prescribed recipe above was followed in the design of the GateTiming [3] timing application that measures times of entry and exit at multiple gates. Figure 5 presents the times recorded during multiple runs through two gates. The Date/UTC.ms column is the clock time on entering the first gate, the Time column is the time between entering the first and second gate; a more detailed display of each gate entry and exit times is a view-ing option. Table 2 lists the times as recorded by the application of a block falling one meter. The variation of measurements is primarily due to slight differences in the height when dropped above the first gate. For example, dropping from 1/2 inch (1.27 cm) above the first gate produced a timing in the range of 0.42 s, the time is lower than the one predicted because the block is traveling a little faster through the gates (about 0.5 mph or 0.80 km/h at the first gate). Other timing variations are likely due to slight changes to the block profile relative to the gates, not always maintaining a stable orientation.

III. Conclusions

Although only timing was closely examined in this paper, a range of audio port data collection ap-plications are possible, including our own Android applications: AudioTime+ [4], a general purpose tool for signal display and analysis that can examine the behavior of a variable resistor in the cir-cuit of Fig. 1 and 2, GateTiming [3], to measure the time an object passes between or through a series of gates, DCVoltmeter [5], measurement of 0-10VDC via voltage-to-frequency conversion of microphone input, then converting the frequency to a corresponding voltage value; a simple, active volt-age controlled oscillator circuit is required for the conversion. Other applications for data collection from a variety of sources using the basic recipe are also possible. By using this method, data can be collected from almost any sensor based on variable resistance.

1. K Forinash, R Wisman, Smartphones - Exper-iments with an Externa! Thermistor Circuit, The Physics Teacher 50, 566 (2012).         [ Links ]

2. K Forinash, R Wisman, Photogate Timing with a Smartphone, The Physics Teacher 53, 234 (2015).         [ Links ]

3. R Wisman, K Forinash, Mobile Science -GateTiming, December 2017. Google Play: https://play.google.com/store/apps/details? id=edu.ius.rwisman.gatetiming        [ Links ]

4. R Wisman, K Forinash, Mobile Science -AudioTime+, November 2013. Google Play: https://play.google.com/store/apps/details? id=edu.ius.audiotimeplus        [ Links ]

5. R Wisman, K Forinash, Mobile Science -DCVoltmeter, January 2016. Google Play: https://play.google.com/store/apps/details? id=edu.ius.dcvoltmeter        [ Links ]

Creative Commons License Todo el contenido de esta revista, excepto dónde está identificado, está bajo una Licencia Creative Commons