# Calculating Wavelength of sound using an Arduino

I'm using an Arduino Uno R3. I need to measure the wavelength of sound of a particular (known) frequency. By substituting in the equation:

Vsound = Frequency * Wavelength

...I wish to calculate the speed of sound in the medium. Since I'm new to Arduinos and electronics, I plan to use a speaker for generating the (known) frequency from the Arduino. I have an ADMP 401 microphone as well. But how do I process/calculate the wavelength of sound on the Arduino and push the output velocity to the serial monitor?

EDIT: Is it possible to simply take the audio recorded by the ADMP 401 microphone and push it to a computer via the serial bus?

• You've got a problem there: you have two unknowns: Vsound and Wavelength. Could you send a pulse from the speaker over a known distance and time how long it takes to get to the microphone? – Andrew Morton Apr 7 '14 at 18:00
• I was initially considering time delay! But I felt this approach might be more accurate (plus I get the opportunity to learn a bit more about EE). If wavelength can be obtained from the arduino (i don't think it's exactly an unknown per se), it should be possible to easily calculate Vsound. – shortstheory Apr 7 '14 at 18:10
• I don't know how accurate this idea would be, but you could set up a tube like the diagram in Standing Waves In An Air Column and have the Arduino control a motor which moves the microphone in the tube to find the first maximum in the amplitude. For 1KHz in air, it would be about 30cm, so in the realms of physically achievable apparatus. Or it might be more accurate to find the first (or maybe second) amplitude minumum. For the ping method, you should be able to get fair accuracy with a large distance. – Andrew Morton Apr 7 '14 at 18:20
• I could give you a nice method to do it (with 2 mics), but please first answer these questions. Would you define only 1 working frequency (like 1kHz)? What precision do you need for the sound velocity? What range of velocity do you want (250 m/s to 350 m/s) ? – RawBean Apr 11 '14 at 14:50
• Yes, I would define only one working frequency. Sound velocity can have an accuracy of +/- 5 m/s. And yeah, a range of velocity from 300 - 400 m/s would be perfect :) – shortstheory Apr 11 '14 at 15:15

Setup input amplifier so that the audio waveform is clipped into a square wave. Then feed this into a pin and use one of the frequency measurement libraries, such as this: http://interface.khm.de/index.php/lab/experiments/frequency-measurement-library/

• Interesting. Could you link the schematics of the aforementioned input amplifier? – shortstheory Apr 10 '14 at 9:57

Andrew Morton said it, I'm just going to say it and expand on it.

Given a single point measurement of instantaneous sound pressure from some kind of transducer, the only thing you can possibly derive from that is frequency. The only way to get the wavelength independently is to double your pleasure, double your fun - you either need to know the exact distance to the sending unit, or you need another receiver. What's more, with only two receivers, you still need to put them in a straight line with the sender, with quite some distance between them so you can get a meaningful lag in frequency between the two. With three, you could establish directionality, but they still have to be far enough apart to create a noticeable time lag to establish velocity. From a single measuring unit, you also have to factor in how long it takes to get the samples. From multiple units, you need very seriously accurate timestamps.

Wavelength calculations almost always depend on using a known value of transmission speed through a given medium. The big-daddy experiments to establish speed of vibration through solid materials are really quite a pain in the butt to set up, but then we get nice tables of known values to play with at our desks.

• Thanks. Could you suggest a way to measure frequency of sound then? – shortstheory Apr 10 '14 at 17:45
• The thing about frequency is that it is a measure of how often a thing happens. Frequency can be measured fairly simply by sampling an audio waveform and processing it using some pretty simple libraries. Single sine wave sources take basically no processing, only needing a short algorithm to roll through the samples, find peaks, compare them with the known sampling rate, and presto! Frequency. But composite sounds, which most are, need a little love from a thing called a Fast Fourier Transform, first. – Sean Boddy Apr 11 '14 at 2:54

## Principle

I propose you to use 2 microphones instead of one. The idea is to acquire the signal at 2 different locations, at the same time (compared to the signal period), and multiply them to extract the wave length.

You will acquire 1 signal per location. The second signal will be delayed of a certain amout of time. We call it delta $\delta$. Let's say at microphone number 1, we have a pure sine wave $mic1(t) = \sin(\omega t + \phi)$ and at microphone number 2 we have $mic2(t) = \sin(\omega t + \phi - \delta)$

Delta only depends on the wavelength because we fixed the distance between the 2 microphones. So, if we get delta, we'll get the velocity.

See for example, if the distance 2 microphones are equal to exactly half a wave length, then you would have such signals:

Note: I consider that the amplitude is the same between the 2 microphones.

Now, consider using this formula

$\sin(a)\sin(b) = 1/2(\cos(a-b) - \cos(a+b))$

1. Do this multiplication on the firmware

$mic1(t)*mic2(t) = 1/2(\cos(\delta) - \cos(2(\omega t + \phi) - \delta))$

1. By low-pass filtering (or averaging) $mic1(t)*mic2(t)$ you would get only the constant part, which is

$1/2\cos(\delta)$

2. Then, compute delta

$\delta = \arccos(2*low-pass(mic1(t)*mic2(t)))$

3. Finally, convert to the radian to meters

$\lambda = \delta / 2\pi * d$

See this picture, where I take a delta of 1 rad, and a butterworth 2nd order low-pass filter.

## Requirements

• They must be set as to be in line with the sound source
• The distance d between them must be measured precisely, it will be your reference in the space domain.
• The distance d between them must be less than 1/2 wavelength. FYI, for a 1kHz signal it would be ~17cm max

## Realization

• Connect the microphone's output to analog inputs on the arduino's board.
• If you could afford it, add a band-pass filter between the microphones and the arduinos. The cut-off frequency is around the source wave frequency.
• Use the AnalogRead() function of the Arduino for mic1 and next instruction call the one for mic2. Because reading takes 100 usec, it is important to take it into account, and use a frequency that is slow enough (like 100 Hz) to minimize the impact of this latency.
• This is actually a really nice idea. But I have doubts with this: δ=arccos(2∗low−pass(mic1(t)∗mic2(t))) What is the low-pass term for? Is low−pass(mic1(t)∗mic2(t) the same as 0.5 cos (delta)? – shortstheory Apr 15 '14 at 17:16
• Also, I can see that there could be a significant error in calculating the delta term (especially without a band filter). I'm not criticising your project (I still think it's a really good idea because 't' is now eliminated), but how would this be superior to merely measuring the time delay? – shortstheory Apr 15 '14 at 17:21
• the low-pass() I used is a function, that is keeping only the constant value (DC if you prefer) of the signal. An averaging would be fine, although not the best. If you have some signal processing skills, you could implement an IIR filter. Yes, computing low-pass(mic1(t)*mic2(t)) would be the same as 0.5 cos(delta). – RawBean Apr 15 '14 at 20:17
• Sorry, but I didn't make the effort to estimate the error. Of course without bandpass filter the error could be huge. It depends on the signal to noise ratio of your setup. About comparing my solution to "merely measuring the time delay", I don't see how it's possible to just measure the time delay. The time delay between what and what? – RawBean Apr 15 '14 at 20:22
• Ah yes. The time delay between the two microphones receiving the sound wave. – shortstheory Apr 16 '14 at 2:05

Speed is also slightly frequency dependant, so for approximations, you can measure echo return time of a pulse for a known distance or use wavelets of various frequencies with higher s/n ratio tuned in Rx to block out noise. Alternatively you can use a mic at each end with one speaker coupled to one end, but you still need distance or some other reference such as speed in air at a known ambient condition.