Advertisement
_eremec_

Untitled

Mar 4th, 2017
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. from numpy import array, arange, abs as np_abs
  2. from numpy.fft import rfft, rfftfreq, fftshift
  3. from numpy.random import uniform
  4. from math import sin, cos, pi
  5. import pylab
  6. from random import gauss
  7.  
  8.  
  9. def show_spectrum(sig, FD, N):
  10.     spectrum = rfft(sig)
  11.     pylab.plot(rfftfreq(N, 1./FD), np_abs(spectrum)/N)
  12.     pylab.ylabel('voltage, mV')
  13.     pylab.xlabel('frequency, Hz')
  14.     pylab.grid(True)
  15.     pylab.show()
  16.    
  17. FD = 22050
  18. N = 2**10
  19. F = 440.0
  20. noise_g = [gauss(0.5, 0.05) for _ in range(N)]
  21.  
  22. sig1 = array([0.125*sin(2.*pi*F*n/FD + 2) for n in range(N)])
  23. sig2 = array([sin(7.*pi*F*n/FD) for n in range(N)])
  24. sig3 = array([6.*sin(2.*pi*F*n/FD + 2) for n in range(N)])
  25. sig = sig3 + noise_g
  26.  
  27. show_spectrum(sig, FD, N)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement