Audio processing to figure out RPM of motor

In [2]:
import numpy as np;
import matplotlib.pyplot as plt;
plt.rcParams.update({"text.usetex":True});
%config InlineBackend.figure_format = "svg"
import scipy.io.wavfile as sw
In [11]:
sam, d = sw.read("tablefan.wav");
N = np.size(d);
t = np.arange(N)*1.0/sam;
plt.plot(t, d); plt.xlabel("Time"); plt.ylabel("Audio signal near fan");
In [24]:
from scipy.fft import fft, fftfreq
from scipy.signal import find_peaks
In [30]:
dk = fft(d)[:N//2];
xk = fftfreq(N, 1.0/sam)[:N//2];
plt.loglog(xk, np.abs(dk));
peaks, _ = find_peaks(np.abs(dk), height=1e7, distance=200)
plt.loglog(xk[peaks], np.abs(dk[peaks]), 'xr')
Out[30]:
[<matplotlib.lines.Line2D at 0x265d1d45670>]
In [31]:
print(xk[peaks])
[ 25.79365079  51.53769841  77.5297619  103.37301587 128.86904762
 154.61309524 180.35714286 231.89484127]
In [33]:
sam, d = sw.read("benchgrinder.wav");
N = np.size(d);
t = np.arange(N)*1.0/sam;
#plt.plot(t, d); plt.xlabel("Time"); plt.ylabel("Audio signal near bench grinder");
dk = fft(d)[:N//2];
xk = fftfreq(N, 1.0/sam)[:N//2];
plt.loglog(xk, np.abs(dk));
peaks, _ = find_peaks(np.abs(dk), height=1e7, distance=200)
plt.loglog(xk[peaks], np.abs(dk[peaks]), 'xr')
print(xk[peaks])
[  49.85502577   99.62951031  149.72615979  199.33956186  249.19458763
  298.96907216  348.90463918  649.0818299  1009.66494845 1048.08311856
 1215.36726804 1253.86597938 1459.89046392 4212.62886598]
In [ ]: