# Measuring Car Velocity via Acoustic Doppler Effect

Velocity measurement can be done by fitting a Doppler model to the measured change in frequencies extracted from a sound sample.

Sound sample of a Doppler effect.

 In[2]:= XsampleRate = Quantity[8192, "Hertz"];

Apply a continuous wavelet transformation with a Gabor wavelet.

 In[3]:= Xcwt = ContinuousWaveletTransform[snd, GaborWavelet[24], {6, 24}];
 In[4]:= XWaveletScalogram[cwt, {2 | 3 | 4 | 5 | 6, _}]
 Out[4]=

Antialiased subsampling of the wavelet data to 32Hz.

 In[5]:= XsubsamplingFactor = sampleRate/Quantity[32, "Hertz"];
 In[6]:= XwaveletData2 = ArrayResample[ GaussianFilter[Abs@Map[First, cwt[All, "Values"]], Round[{{0, subsamplingFactor}, {0, subsamplingFactor/4}}]], {All, Scaled[1/subsamplingFactor]} ];

Measure the scale shift via correlation.

 In[7]:= XscaleShifts = Accumulate[Table[ FindPeaks[ ListCorrelate[waveletData2[[All, t]], ArrayPad[waveletData2[[All, t + 1]], 4, 0]], InterpolationOrder -> 3][[1, 1]] - 5, {t, 1, Last@Dimensions[waveletData2] - 2} ]];

Convert shifts in wavelet scale back to change in frequency.

 In[8]:= XscaleToFrequency[cwd_] := Evaluate[cwd["SampleRate"]/ cwd["WaveletScale"] 2^(-(#)/cwd["Voices"])] &;
 In[9]:= XfrequencyFactor = Normalize[scaleToFrequency[cwt][scaleShifts], Mean];
 In[10]:= XListLinePlot[frequencyFactor]
 Out[10]=

Fit Doppler model to measured change in frequency.

 In[11]:= Xnlm = NonlinearModelFit[frequencyFactor, 1 - ((t/32 - t0) v^2)/(343.2 Sqrt[d^2 + (t/32 - t0)^2 v^2]), {A, v, d, t0}, t]
 Out[11]=
 In[12]:= Xnlm["ParameterTable"] // Chop
 Out[12]=

Result: car speed = 19.5 m/s minimum distance = 4.7m

 In[13]:= XUnitConvert[ Quantity[v /. nlm["BestFitParameters"], "Meters per seconds"], "km per hour"]
 Out[13]=

## Mathematica

Questions? Comments? Contact a Wolfram expert »