|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import matplotlib.pyplot as plt
- import mplcursors
- import numpy as np
- from numpy.fft import fft
- from scipy.io import wavfile
-
-
- def PowerSpectrum(y):
- Y = np.abs(fft(y))
- PS = Y[0:len(Y) // 2]
- df = fs / len(Y)
- f = np.arange(0, len(PS)) * df
- return f, PS
-
-
- plt.clf()
-
- fs, data = wavfile.read('dial.wav')
-
- fig, axs = plt.subplots(2, num=1)
-
- y = data[:, 0]
- dt = 1 / fs
- t = np.arange(0, len(y)) * dt
-
- axs[0].plot(t, y)
- axs[0].set_xlabel('t [s]')
- axs[0].set_ylabel('y')
-
- limits = [0.1, 0.45, 0.8, 1.2]
-
- ss = limits[2]
- se = limits[3]
-
- to = t[(t > ss) & (t < se)]
- yo = y[(t > ss) & (t < se)]
-
- axs[0].plot(to, yo)
-
- f, PS = PowerSpectrum(y)
-
- fo, PSo = PowerSpectrum(yo)
-
- axs[1].plot(f, PS)
- axs[1].set_xlabel('f [Hz]')
- axs[1].set_ylabel('Y abs')
- axs[1].set_xlim(0, 1500)
-
- axs[1].plot(fo, PSo)
-
- mplcursors.cursor()
-
- plt.show()
|