Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy.signal import hilbert, chirp
  4. from scipy.io.wavfile import read
  5.  
  6.  
  7. duration = 1.0
  8. fs = 400.0
  9. samples = int(fs * duration)
  10. t = np.arange(samples) / fs
  11.  
  12. signal = chirp(t, 20.0, t[-1], 100.0)
  13. signal *= (1.0 + 0.5 * np.sin(2.0 * np.pi * 3.0 * t))
  14.  
  15.  
  16. a = read("hidas.wav")
  17. signal = np.array(a[1], dtype=float)
  18. t = [x for x in range(0, len(a[1]))]
  19.  
  20. #import pdb; pdb.set_trace()
  21.  
  22. analytic_signal = hilbert(signal)
  23. amplitude_envelope = np.abs(analytic_signal)
  24. instantaneous_phase = np.unwrap(np.angle(analytic_signal))
  25. instantaneous_frequency = (np.diff(instantaneous_phase) /
  26. (2.0 * np.pi) * fs)
  27.  
  28. fig = plt.figure()
  29. ax0 = fig.add_subplot(211)
  30. ax0.plot(t, signal, label='signal')
  31. ax0.plot(t, amplitude_envelope, label='envelope')
  32. ax0.set_xlabel("time in seconds")
  33. ax0.legend()
  34. ax1 = fig.add_subplot(212)
  35. ax1.plot(t[1:], instantaneous_frequency)
  36. ax1.set_xlabel("time in seconds")
  37. ax1.set_ylim(0.0, 120.0)
  38.  
  39. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement