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
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");
from scipy.fft import fft, fftfreq
from scipy.signal import find_peaks
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])
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])