Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. def ms(x):
  2. return (np.abs(x)**2.0).mean()
  3.  
  4. def normalize(y, x=None):
  5. if x is not None:
  6. x = ms(x)
  7. else:
  8. x = 1.0
  9. return y * np.sqrt( x / ms(y) )
  10.  
  11. def brown(N, state=None):
  12. state = np.random.RandomState() if state is None else state
  13. uneven = N%2
  14. X = state.randn(N//2+1+uneven) + 1j * state.randn(N//2+1+uneven)
  15. S = (np.arange(len(X))+1)# Filter
  16. y = (np.fft.irfft(X/S)).real
  17. if uneven:
  18. y = y[:-1]
  19. return normalize(y)
  20.  
  21. inst_freq = np.cumsum(brown(100))
  22. inst_freq -= inst_freq.min() - 1
  23. inst_freq /= inst_freq.max()
  24. rectified_inst_freq = 1.0 / (np.floor(1.0 / inst_freq))
  25.  
  26. plt.plot(inst_freq)
  27. plt.plot(rectified_inst_freq, 'r')
  28. plt.show()
  29. plt.plot(np.cos(np.cumsum(np.pi * inst_freq)))
  30. plt.show()
  31. plt.plot(np.cos(np.cumsum(np.pi * rectified_inst_freq)))
  32. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement