if j==0:
            psd = tmp
        else:
            psd = psd + tmp
    return f, psd/k


fs=256 # sample rate
b0=0.0002
N=2*4096
x = noise.white(N=2*4096,b0=b0,fs=fs)
t = np.linspace(0, (1.0/fs)*N, len(x))

plt.figure()
plt.plot(t,x)
plt.xlabel('Time / s')
plt.ylabel('Amplitude / V')
print x
f, psd = many_psds(k=50,fs=fs,b0=b0,N=N)

fxx, Pxx_den = noise.scipy_psd(x, fs)

plt.figure()
plt.semilogy(f,psd,label='numpy.fft()')
plt.semilogy(fxx,Pxx_den,label='scipy.signal.welch()')
plt.semilogy(f,[b0]*len(f),label='b_0 = %.3g' % b0 )
plt.legend(framealpha=0.5)
plt.xlabel('Frequeny / Hz')
plt.ylabel('one-sided PSD / V^2/Hz')
plt.show()
Exemple #2
0
phist, pbins = np.histogram([1e9 * yy for yy in x], bins=100, density=True)
plt.plot(pbins[1:], phist, 'ro')
plt.xlabel('Phase / ns')
plt.ylabel('Count')
plt.title('Phase histogram')
rmsphase = 1e12 * np.std(x)
print("RMS phase = ", rmsphase, " ps")
plt.text(0, 0.01, 'RMS = %f ps' % rmsphase)

# plt.show()

f_y, psd_y = noise.numpy_psd(y, fs)
f_fi, psd_fi = noise.numpy_psd(fi, fs)
f_x, psd_x = noise.numpy_psd(x, fs)

fxx, Pxx_den = noise.scipy_psd(y, fs)
f_fi2, psd_fi2 = noise.scipy_psd(fi, fs)
f_x2, psd_x2 = noise.scipy_psd(x, fs)
print("PSD calc done.")

# S_y
plt.figure()
plt.loglog(f_y, psd_y, label='numpy.fft()')
plt.loglog(fxx, Pxx_den, label='scipy.signal.welch()')
plt.loglog(f_y, [h2 * ff * ff for ff in f_y], label='h2 * f^2 ')
plt.legend(framealpha=0.5)
plt.title('PSD of fractional frequency')
plt.xlabel('Frequeny / Hz')
plt.ylabel('one-sided PSD / S_y(f)')
plt.grid()
v0 = 1e6 # nominal oscillator frequency

y = noise.white(N=N,b0=h0,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))

plt.figure()
plt.plot(t,y)
plt.xlabel('Time / s')
plt.ylabel('Fractional frequency')
f_y, psd_y = noise.numpy_psd(y,fs)
f_fi, psd_fi = noise.numpy_psd(fi,fs)
f_x, psd_x = noise.numpy_psd(x,fs)

fxx, Pxx_den = noise.scipy_psd(y, fs)
f_fi2, psd_fi2 = noise.scipy_psd(fi, fs)
f_x2, psd_x2 = noise.scipy_psd(x, fs)

plt.figure()
plt.semilogy(f_y,psd_y,label='numpy.fft()')
plt.semilogy(fxx,Pxx_den,label='scipy.signal.welch()')
plt.semilogy(f_y,[h0]*len(f_y),label='h_0 = %.3g' % h0 )
plt.legend(framealpha=0.5)
plt.title('PSD of fractional frequency')
plt.xlabel('Frequeny / Hz')
plt.ylabel('one-sided PSD / S_y(f)')

plt.figure()
plt.loglog(f_fi,psd_fi,label='numpy.fft()')
plt.loglog(f_fi2,psd_fi2,label='scipy.signal.welch()')
Exemple #4
0
        if j == 0:
            psd = tmp
        else:
            psd = psd + tmp
    return f, psd / k


fs = 256  # sample rate
b0 = 0.0002
N = 2 * 4096
x = noise.white(num_points=2 * 4096, b0=b0, fs=fs)
t = np.linspace(0, (1.0 / fs) * N, len(x))

plt.figure()
plt.plot(t, x)
plt.xlabel('Time / s')
plt.ylabel('Amplitude / V')
print(x)
f, psd = many_psds(k=50, fs=fs, b0=b0, N=N)

fxx, Pxx_den = noise.scipy_psd(x, fs)

plt.figure()
plt.semilogy(f, psd, label='numpy.fft()')
plt.semilogy(fxx, Pxx_den, label='scipy.signal.welch()')
plt.semilogy(f, [b0] * len(f), label='b_0 = %.3g' % b0)
plt.legend(framealpha=0.5)
plt.xlabel('Frequeny / Hz')
plt.ylabel('one-sided PSD / V^2/Hz')
plt.show()