Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numpy import array, arange, abs as np_abs
- from numpy.fft import rfft, rfftfreq, fftshift
- from numpy.random import uniform
- from math import sin, cos, pi
- import pylab
- from random import gauss
- def show_spectrum(sig, FD, N):
- spectrum = rfft(sig)
- pylab.plot(rfftfreq(N, 1./FD), np_abs(spectrum)/N)
- pylab.ylabel('voltage, mV')
- pylab.xlabel('frequency, Hz')
- pylab.grid(True)
- pylab.show()
- FD = 22050
- N = 2**10
- F = 440.0
- noise_g = [gauss(0.5, 0.05) for _ in range(N)]
- sig1 = array([0.125*sin(2.*pi*F*n/FD + 2) for n in range(N)])
- sig2 = array([sin(7.*pi*F*n/FD) for n in range(N)])
- sig3 = array([6.*sin(2.*pi*F*n/FD + 2) for n in range(N)])
- sig = sig3 + noise_g
- show_spectrum(sig, FD, N)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement