def test_noise(): N = 500 rate = 1.0 w = noise.white(N) b = noise.brown(N) v = noise.violet(N) p = noise.pink(N) assert len(w) == N assert len(b) == N assert len(v) == N-1 # why? assert len(p) == N
def test_noise(): N = 500 rate = 1.0 w = noise.white(N) b = noise.brown(N) v = noise.violet(N) p = noise.pink(N) assert len(w) == N assert len(b) == N assert len(v) == N - 1 # why? assert len(p) == N
def add_brown_noise(filename): print "Adding Brown Noise..." fps, snd_array = wavfile.read('../audio/transformed/' + filename) noise1 = noise.brown(len(snd_array)) noise1 = map(lambda x: int(x/.01), noise1) noise2 = np.array([noise1,noise1]).T noisy_array = noise2 + snd_array filename, file_extension = os.path.splitext(filename) filename = "../audio/transformed/"+filename+"brownnoise.wav" scaled = np.int16(noisy_array/np.max(np.abs(noisy_array)) * 32767) write(filename, 44100, scaled) return
def test_noise(): N = 500 #rate = 1.0 w = noise.white(N) b = noise.brown(N) v = noise.violet(N) p = noise.pink(N) # check output length assert len(w) == N assert len(b) == N assert len(v) == N assert len(p) == N # check output type for x in [w, b, v, p]: assert type(x) == numpy.ndarray, "%s is not numpy.ndarray" % (type(x))
if __name__ == "__main__": print("allatools tests with various noise types") # we test ADEV etc. by calculations on synthetic data # with known slopes of ADEV t = [tt for tt in numpy.logspace(0, 3, 50)] # tau values from 1 to 1000 plt.subplot(111, xscale="log", yscale="log") N = 100000 # Colors: http://en.wikipedia.org/wiki/Colors_of_noise # Brownian a.k.a random walk frequency => sqrt(tau) ADEV print("Random Walk frequency noise - should have sqrt(tau) ADEV") freq_rw = noise.brown(N) phase_rw_rw = numpy.cumsum(noise.brown(N)) # integrate to get phase plotallan(plt, freq_rw, 1, t, 'm.') plotallan_phase(plt, phase_rw_rw, 1, t, 'mo',label='random walk frequency') plotline(plt, +0.5, t, 'm',label="f^(+1/2)") # pink frequency noise => constant ADEV print("Pink frequency noise - should have constant ADEV") freq_pink = noise.pink(N) phase_p = numpy.cumsum(noise.pink(N)) # integrate to get phase, color?? plotallan_phase(plt, phase_p, 1, t, 'co',label="pink/flicker frequency noise") plotallan(plt, freq_pink, 1, t, 'c.') plotline(plt, 0, t, 'c',label="f^0") # white frequency modulation => 1/sqrt(tau) ADEV print("White frequency noise - should have 1/sqrt(tau) ADEV")
if __name__ == "__main__": print("allatools tests with various noise types") # we test ADEV etc. by calculations on synthetic data # with known slopes of ADEV t = [tt for tt in numpy.logspace(0, 3, 50)] # tau values from 1 to 1000 plt.subplot(111, xscale="log", yscale="log") N = 100000 # Colors: http://en.wikipedia.org/wiki/Colors_of_noise # Brownian a.k.a random walk frequency => sqrt(tau) ADEV print("Random Walk frequency noise - should have sqrt(tau) ADEV") freq_rw = noise.brown(N) phase_rw_rw = numpy.cumsum(noise.brown(N)) # integrate to get phase plotallan(plt, freq_rw, 1, t, 'm.') plotallan_phase(plt, phase_rw_rw, 1, t, 'mo', label='random walk frequency') plotline(plt, +0.5, t, 'm', label="f^(+1/2)") # pink frequency noise => constant ADEV print("Pink frequency noise - should have constant ADEV") freq_pink = noise.pink(N) phase_p = numpy.cumsum(noise.pink(N)) # integrate to get phase, color?? plotallan_phase(plt,
# the predicted S_y, S_fi, S_x, and ADEV given in the table # AW 2015-08-06 # from the ieee1139 table # PSD_y(f) = h2 * f^-2 fractional frequency PSD # PSD_fi(f) = h2 * vo^2 * f^-4 phase (radians) PSD # PSD_x(f) = h2 * (2 pi)^-2 * f^-4 phase (time) PSD # ADEV_y(tau) = sqrt{ 2*pi^2/3 * h2 * tau } Allan deviation fs=12.8 # sampling frequency in Hz (code should work for any non-zero value here) h2=2e-20 # PSD f^-2 coefficient N=10*4096 # number of samples v0 = 1.2345e6 # nominal oscillator frequency y = noise.brown(N=N,b2=h2,fs=fs) # fractional frequency x = allantools.frequency2phase(y,fs) # phase in seconds fi = [2*math.pi*v0*xx for xx in x] # phase in radians t = np.linspace(0, (1.0/fs)*N, len(y)) # time-series time axis # time-series figure plt.figure() plt.plot(t,y,label='y') plt.plot(t,x[1:],label='x') plt.legend() plt.xlabel('Time / s') plt.ylabel('Fractional frequency') # note: calculating the PSD of an 1/f^4 signal using fft seems to be difficult # the welch method returns a correct 1/f^4 shaped PSD, but fft often does not # things that may help
# the predicted S_y, S_fi, S_x, and ADEV given in the table # AW 2015-08-06 # from the ieee1139 table # PSD_y(f) = h2 * f^-2 fractional frequency PSD # PSD_fi(f) = h2 * vo^2 * f^-4 phase (radians) PSD # PSD_x(f) = h2 * (2 pi)^-2 * f^-4 phase (time) PSD # ADEV_y(tau) = sqrt{ 2*pi^2/3 * h2 * tau } Allan deviation fs=12.8 # sampling frequency in Hz (code should work for any non-zero value here) h2=2e-20 # PSD f^-2 coefficient N=10*4096 # number of samples v0 = 1.2345e6 # nominal oscillator frequency y = noise.brown(num_points=N, b2=h2, fs=fs) # fractional frequency x = allantools.frequency2phase(y,fs) # phase in seconds fi = [2*math.pi*v0*xx for xx in x] # phase in radians t = np.linspace(0, (1.0/fs)*N, len(y)) # time-series time axis # time-series figure plt.figure() fig, ax1 = plt.subplots() ax1.plot(t, y, label='y') ax2 = ax1.twinx() ax2.plot(t, x[1:], label='x') plt.legend() plt.xlabel('Time / s') plt.ylabel('Fractional frequency') # note: calculating the PSD of an 1/f^4 signal using fft seems to be difficult