Пример #1
0
 def test_mdev_ci_and_noiseID(self):
     """ ADEV with confidence intervals, including noise-ID """
     change_to_test_dir()
     s32rows = testutils.read_stable32(
         resultfile='stable32_MDEV_octave.txt', datarate=1.0)
     for row in s32rows:
         phase = testutils.read_datafile('gps_1pps_phase_data.txt.gz')
         (taus, devs, errs, ns) = allan.mdev(phase,
                                             rate=rate,
                                             data_type="phase",
                                             taus=[row['tau']])
         dev = devs[0]
         #print(dev/row['dev'])
         assert np.isclose(dev, row['dev'], rtol=1e-2, atol=0)
         try:
             # CI including noise-ID
             (lo2,
              hi2) = allan.confidence_interval_noiseID(phase,
                                                       dev,
                                                       af=int(row['m']),
                                                       dev_type="mdev",
                                                       data_type="phase")
             print(" tau= %f  lo/s32_lo = %f hi/s32_hi = %f " %
                   (row['tau'], lo2 / row['dev_min'], hi2 / row['dev_max']))
             assert np.isclose(lo2, row['dev_min'], rtol=1e-2, atol=0)
             assert np.isclose(hi2, row['dev_max'], rtol=1e-2, atol=0)
         except NotImplementedError:
             print("can't do CI for tau= %f" % row['tau'])
             pass
Пример #2
0
 def test_phasedat_mdev(self):
     s32_rows = testutils.read_stable32( 'phase_dat_mdev_octave.txt' , 1.0 )
     phase = testutils.read_datafile('PHASE.DAT')
     (taus,devs,errs,ns) = allan.mdev(phase, taus=[s32['tau'] for s32 in s32_rows])
     
     # CI computation
     # alhpa= +2,...,-4   noise power
     # d= 1 first-difference variance, 2 allan variance, 3 hadamard variance
     # alpha+2*d >1
     # m = tau/tau0 averaging factor
     # F filter factor, 1 modified variance, m unmodified variance
     # S stride factor, 1 nonoverlapped estimator, m overlapped estimator (estimator stride = tau/S )
     # N number of phase obs
     los=[]
     his=[]
     for (d,t, n) in zip(devs, taus, ns):
         edf2 = allan.edf_greenhall( alpha=0, d=2, m=int(t), N=len(phase), overlapping = True, modified=True  )
         (lo,hi) = allan.confidence_interval( dev=d, edf=edf2 )
         los.append(lo)
         his.append(hi)
     # compare to Stable32
     print("mdev()")
     for (s32, t2, d2, lo2, hi2, n2) in zip(s32_rows, taus, devs, los, his, ns):
         print("s32 %03d %03f %1.6f %1.6f %1.6f" % (s32['n'], s32['tau'], s32['dev_min'], s32['dev'], s32['dev_max']))
         print("at  %03d %03f %1.6f %1.6f %1.6f" % (n2, t2, round(lo2,5), round(d2,5), round(hi2,5) ))
         testutils.check_approx_equal(s32['dev_min'], lo2, tolerance=1e-3)
         testutils.check_approx_equal(s32['dev'], d2, tolerance=1e-4)
         testutils.check_approx_equal(s32['dev_max'], hi2, tolerance=1e-3)
     print("----")
Пример #3
0
def plotallan_mdev(plt, y, rate, taus, style, label=""):
    (t2, ad, ade, adn) = allantools.mdev(y,
                                         data_type='freq',
                                         rate=rate,
                                         taus=taus)
    plt.loglog(t2, ad, style, label=label)
    return t2, ad, ade, adn
Пример #4
0
def plotallan_mdev_phase(plt, y, rate, taus, style, label="", alpha=1.0):
    (t2, ad, ade, adn) = allantools.mdev(y,
                                         data_type='phase',
                                         rate=rate,
                                         taus=taus)
    plt.loglog(t2, ad, style, label=label, alpha=alpha)
    return t2, ad, ade, adn
Пример #5
0
 def test_mdev_ci(self):
     s32rows = testutils.read_stable32(resultfile='mdev_decade.txt',
                                       datarate=1.0)
     for row in s32rows:
         data = testutils.read_datafile(data_file)
         (taus, devs, errs, ns) = allan.mdev(data,
                                             rate=rate,
                                             taus=[row['tau']])
         edf = allan.edf_greenhall(alpha=row['alpha'],
                                   d=2,
                                   m=row['m'],
                                   N=len(data),
                                   overlapping=True,
                                   modified=True,
                                   verbose=True)
         (lo, hi) = allan.confidence_intervals(devs[0],
                                               ci=0.68268949213708585,
                                               edf=edf)
         print("n check: ", testutils.check_equal(ns[0], row['n']))
         print("dev check: ",
               testutils.check_approx_equal(devs[0], row['dev']))
         print(
             "min dev check: ", lo, row['dev_min'],
             testutils.check_approx_equal(lo,
                                          row['dev_min'],
                                          tolerance=1e-3))
         print(
             "max dev check: ", hi, row['dev_max'],
             testutils.check_approx_equal(hi,
                                          row['dev_max'],
                                          tolerance=1e-3))
Пример #6
0
 def test_mdev_ci(self):
     s32rows = testutils.read_stable32(resultfile='mdev_octave.txt',
                                       datarate=1.0)
     for row in s32rows:
         data = testutils.read_datafile(data_file)
         data = allan.frequency2fractional(data, mean_frequency=1.0e7)
         (taus, devs, errs, ns) = allan.mdev(data,
                                             rate=rate,
                                             data_type="freq",
                                             taus=[row['tau']])
         # NOTE! Here we use alhpa from Stable32-results for the allantools edf computation!
         edf = allan.edf_greenhall(alpha=row['alpha'],
                                   d=2,
                                   m=row['m'],
                                   N=len(data),
                                   overlapping=True,
                                   modified=True,
                                   verbose=True)
         (lo, hi) = allan.confidence_interval(devs[0], edf=edf)
         print("n check: ", testutils.check_equal(ns[0], row['n']))
         print(
             "dev check: ", devs[0], row['dev'],
             testutils.check_approx_equal(devs[0],
                                          row['dev'],
                                          tolerance=2e-3))
         print(
             "min dev check: ", lo, row['dev_min'],
             testutils.check_approx_equal(lo,
                                          row['dev_min'],
                                          tolerance=2e-3))
         print(
             "max dev check: ", hi, row['dev_max'],
             testutils.check_approx_equal(hi,
                                          row['dev_max'],
                                          tolerance=2e-3))
Пример #7
0
def rn_noise_id(x, af, rate):
    """ R(n) ratio for noise identification
    
    """
    #print "len(x) ", len(x), "oadev",af*rate
    (taus,devs,errs,ns) = at.adev(x,taus=[af*rate], data_type='phase', rate=rate) 
    #print devs
    oadev_x = devs[0]
    (mtaus,mdevs,errs,ns) = at.mdev(x,taus=[af*rate], data_type='phase', rate=rate)
    mdev_x = mdevs[0]
    rn = pow(mdev_x/oadev_x,2)
    return rn
Пример #8
0
def rn_noise_id(x, af, rate):
    """ R(n) ratio for noise identification
    
    """
    #print "len(x) ", len(x), "oadev",af*rate
    (taus,devs,errs,ns) = at.adev(x,taus=[af*rate], data_type='phase', rate=rate) 
    #print devs
    oadev_x = devs[0]
    (mtaus,mdevs,errs,ns) = at.mdev(x,taus=[af*rate], data_type='phase', rate=rate)
    mdev_x = mdevs[0]
    rn = pow(mdev_x/oadev_x,2)
    return rn
Пример #9
0
 def test_mdev_ci(self):
     s32rows = testutils.read_stable32(resultfile='mdev_decade.txt', datarate=1.0)
     for row in s32rows:
         data = testutils.read_datafile(data_file)
         (taus, devs, errs, ns) = allan.mdev(data, rate=rate,
                                               taus=[ row['tau'] ])
         edf = allan.edf_greenhall(alpha=row['alpha'],d=2,m=row['m'],N=len(data),overlapping=True, modified = True, verbose=True)
         (lo,hi) =allan.confidence_intervals(devs[0],ci=0.68268949213708585, edf=edf)
         print("n check: ", testutils.check_equal( ns[0], row['n'] ) )
         print("dev check: ", testutils.check_approx_equal( devs[0], row['dev'] ) )
         print("min dev check: ",  lo, row['dev_min'], testutils.check_approx_equal( lo, row['dev_min'], tolerance=1e-3 ) )
         print("max dev check: ", hi, row['dev_max'], testutils.check_approx_equal( hi, row['dev_max'], tolerance=1e-3 ) )
Пример #10
0
def test_mdev(noisegen, b, tau, qd):
    """
        check that time-series has the MDEV that we expect
    """
    noisegen.set_input(nr=pow(2,16), qd=qd , b=b)
    noisegen.generateNoise()
    (taus,devs,errs,ns)=at.mdev( noisegen.time_series, taus=[tau], rate=1.0 )
    
    mdev_calculated = devs[0]
    mdev_predicted = noisegen.mdev(tau0=1.0, tau=tau)
    #print( taus,devs )
    print( b, tau, qd, mdev_calculated, mdev_predicted, mdev_calculated/mdev_predicted )
    assert np.isclose( mdev_calculated, mdev_predicted, rtol=2e-1, atol=0)
Пример #11
0
 def test_mdev_ci(self):
     """ Overlapping ADEV with confidence intervals """
     s32rows = testutils.read_stable32(resultfile='mdev_octave.txt', datarate=1.0)
     for row in s32rows:
         data = testutils.read_datafile(data_file)
         data = allan.frequency2fractional(data, mean_frequency=1.0e7)
         (taus, devs, errs, ns) = allan.mdev(data, rate=rate, data_type="freq",
                                               taus=[ row['tau'] ])
         # NOTE! Here we use alhpa from Stable32-results for the allantools edf computation!
         edf = allan.edf_greenhall(alpha=row['alpha'],d=2,m=row['m'],N=len(data),overlapping=True, modified = True, verbose=True)
         (lo,hi) =allan.confidence_interval(devs[0], edf=edf)
         print("n check: ", testutils.check_equal( ns[0], row['n'] ) )
         print("dev check: ", devs[0], row['dev'], testutils.check_approx_equal( devs[0], row['dev'], tolerance=2e-3 ) )
         print("min dev check: ",  lo, row['dev_min'], testutils.check_approx_equal( lo, row['dev_min'], tolerance=2e-3 ) )
         print("max dev check: ", hi, row['dev_max'], testutils.check_approx_equal( hi, row['dev_max'], tolerance=2e-3 ) )
Пример #12
0
    def test_phasedat_mdev(self):
        (s32_taus, s32_devs, s32_devs_lo, s32_devs_hi,
         s32_ns) = read_stable32('phase_dat_mdev_octave.txt', 1.0)
        phase = read_datafile('PHASE.DAT')
        (taus, devs, errs, ns) = allan.mdev(phase, taus=s32_taus)

        # CI computation
        # alhpa= +2,...,-4   noise power
        # d= 1 first-difference variance, 2 allan variance, 3 hadamard variance
        # alpha+2*d >1
        # m = tau/tau0 averaging factor
        # F filter factor, 1 modified variance, m unmodified variance
        # S stride factor, 1 nonoverlapped estimator, m overlapped estimator (estimator stride = tau/S )
        # N number of phase obs
        los = []
        his = []
        for (d, t, n) in zip(devs, taus, ns):
            #edf = greenhall_simple_edf( alpha=0, d=2, m=t, S=1, F=t, N=len(phase) )
            edf2 = allan.edf_greenhall(alpha=0,
                                       d=2,
                                       m=int(t),
                                       N=len(phase),
                                       overlapping=True,
                                       modified=True)
            #print(edf,edf2,edf2/edf)
            (lo,
             hi) = allan.confidence_intervals(dev=d,
                                              ci=0.68268949213708585,
                                              edf=edf2)  # 0.68268949213708585
            #allan.uncertainty_estimate(len(phase), t, d,ci=0.683,noisetype='wf')
            los.append(lo)
            his.append(hi)

        #print greenhall_simple_edf( alpha=0, d=2, m=1, S=1, F=1, N=len(phase) )
        #print confidence_intervals( dev
        #   tau N       edf         chi2    chi2    dev_lo      dev         dev_hi
        #   1   999     782.030     821.358 742.689 2.8515e-01  2.9223e-01  2.9987e-01
        #   2   997     540.681     573.374 507.975 1.9520e-01  2.0102e-01  2.0738e-01

        for (t1, d1, lo1, hi1, n1, t2, d2, lo2, hi2,
             n2) in zip(s32_taus, s32_devs, s32_devs_lo, s32_devs_hi, s32_ns,
                        taus, devs, los, his, ns):
            print("s32 %03d %03f %1.6f %1.6f %1.6f" % (n1, t1, lo1, d1, hi1))
            print("at  %03d %03f %1.6f %1.6f %1.6f" %
                  (n2, t2, round(lo2, 5), round(d2, 5), round(hi2, 5)))
            approx_equal(lo1, lo2, tolerance=1e-3)
            approx_equal(hi1, hi2, tolerance=1e-3)
            print("----")
Пример #13
0
def rn(x, af, rate):
    """ R(n) ratio for noise identification

        ratio of MVAR to AVAR
    """
    (taus, devs, errs, ns) = at.adev(x,
                                     taus=[af * rate],
                                     data_type='phase',
                                     rate=rate)
    oadev_x = devs[0]
    (mtaus, mdevs, errs, ns) = at.mdev(x,
                                       taus=[af * rate],
                                       data_type='phase',
                                       rate=rate)
    mdev_x = mdevs[0]
    return pow(mdev_x / oadev_x, 2)
Пример #14
0
def test_mdev(noisegen, b, tau, qd):
    """
        check that time-series has the MDEV that we expect
    """
    noisegen.set_input(nr=pow(2, 16), qd=qd, b=b)
    noisegen.generateNoise()
    (taus, devs, errs, ns) = at.mdev(noisegen.time_series,
                                     taus=[tau],
                                     rate=1.0)

    mdev_calculated = devs[0]
    mdev_predicted = noisegen.mdev(tau0=1.0, tau=tau)
    #print( taus,devs )
    print(b, tau, qd, mdev_calculated, mdev_predicted,
          mdev_calculated / mdev_predicted)
    assert np.isclose(mdev_calculated, mdev_predicted, rtol=2e-1, atol=0)
Пример #15
0
 def test_mdev_ci(self):
     s32rows = testutils.read_stable32(resultfile="mdev_octave.txt", datarate=1.0)
     for row in s32rows:
         data = testutils.read_datafile(data_file)
         data = allan.frequency2fractional(data, mean_frequency=1.0e7)
         (taus, devs, errs, ns) = allan.mdev(data, rate=rate, data_type="freq", taus=[row["tau"]])
         edf = allan.edf_greenhall(
             alpha=row["alpha"], d=2, m=row["m"], N=len(data), overlapping=True, modified=True, verbose=True
         )
         (lo, hi) = allan.confidence_intervals(devs[0], ci=0.68268949213708585, edf=edf)
         print("n check: ", testutils.check_equal(ns[0], row["n"]))
         print("dev check: ", devs[0], row["dev"], testutils.check_approx_equal(devs[0], row["dev"], tolerance=2e-3))
         print(
             "min dev check: ", lo, row["dev_min"], testutils.check_approx_equal(lo, row["dev_min"], tolerance=2e-3)
         )
         print(
             "max dev check: ", hi, row["dev_max"], testutils.check_approx_equal(hi, row["dev_max"], tolerance=2e-3)
         )
Пример #16
0
    def test_phasedat_mdev(self):
        s32_rows = testutils.read_stable32('phase_dat_mdev_octave.txt', 1.0)
        phase = testutils.read_datafile('PHASE.DAT')
        (taus, devs, errs,
         ns) = allan.mdev(phase, taus=[s32['tau'] for s32 in s32_rows])

        # CI computation
        # alhpa= +2,...,-4   noise power
        # d= 1 first-difference variance, 2 allan variance, 3 hadamard variance
        # alpha+2*d >1
        # m = tau/tau0 averaging factor
        # F filter factor, 1 modified variance, m unmodified variance
        # S stride factor, 1 nonoverlapped estimator, m overlapped estimator (estimator stride = tau/S )
        # N number of phase obs
        los = []
        his = []
        for (d, t, n) in zip(devs, taus, ns):
            #edf = greenhall_simple_edf( alpha=0, d=2, m=t, S=1, F=t, N=len(phase) )
            edf2 = allan.edf_greenhall(alpha=0,
                                       d=2,
                                       m=int(t),
                                       N=len(phase),
                                       overlapping=True,
                                       modified=True)
            #print(edf,edf2,edf2/edf)
            (lo,
             hi) = allan.confidence_intervals(dev=d,
                                              ci=0.68268949213708585,
                                              edf=edf2)  # 0.68268949213708585
            #allan.uncertainty_estimate(len(phase), t, d,ci=0.683,noisetype='wf')
            los.append(lo)
            his.append(hi)

        for (s32, t2, d2, lo2, hi2, n2) in zip(s32_rows, taus, devs, los, his,
                                               ns):
            print("s32 %03d %03f %1.6f %1.6f %1.6f" %
                  (s32['n'], s32['tau'], s32['dev_min'], s32['dev'],
                   s32['dev_max']))
            print("at  %03d %03f %1.6f %1.6f %1.6f" %
                  (n2, t2, round(lo2, 5), round(d2, 5), round(hi2, 5)))
            testutils.check_approx_equal(s32['dev_min'], lo2, tolerance=1e-3)
            testutils.check_approx_equal(s32['dev_max'], hi2, tolerance=1e-3)
            print("----")
Пример #17
0
 def test_mdev_ci_and_noiseID(self):
     """ ADEV with confidence intervals, including noise-ID """
     change_to_test_dir()
     s32rows = testutils.read_stable32(resultfile='stable32_MDEV_octave.txt', datarate=1.0)
     for row in s32rows:
         phase = testutils.read_datafile('gps_1pps_phase_data.txt.gz')
         (taus, devs, errs, ns) = allan.mdev(phase, rate=rate, data_type="phase",
                                             taus=[row['tau']])
         dev = devs[0]
         #print(dev/row['dev'])
         assert np.isclose(dev, row['dev'], rtol=1e-2, atol=0)
         try:
             # CI including noise-ID
             (lo2, hi2) = allan.confidence_interval_noiseID(phase, dev, af=int(row['m']), dev_type="mdev", data_type="phase")
             print(" tau= %f  lo/s32_lo = %f hi/s32_hi = %f "% (row['tau'], lo2/row['dev_min'], hi2/row['dev_max']))
             assert np.isclose(lo2, row['dev_min'], rtol=1e-2, atol=0)
             assert np.isclose(hi2, row['dev_max'], rtol=1e-2, atol=0)
         except NotImplementedError:
             print("can't do CI for tau= %f"%row['tau'])
             pass
Пример #18
0
def nbs14_test():
    taus = [1, 2]
    devs = []
    tol = 1e-4
    
    # first tests that call the _phase functions
    print "nbs14 tests for phase data:"
    
    (taus2,adevs2,aerrs2,ns2) = allan.adev_phase( nbs14_phase, 1.0, taus)
    adevs = nbs14_devs[0]
    assert( check_devs( adevs2[0], adevs[0] ) )
    assert( check_devs( adevs2[1], adevs[1] ) )
    print "nbs14 adev OK"
    
    (taus2,adevs2,aerrs2,ns2) = allan.oadev_phase( nbs14_phase, 1.0, taus)
    oadevs = nbs14_devs[1]
    assert( check_devs( adevs2[0], oadevs[0] ) )
    assert( check_devs( adevs2[1], oadevs[1] ) )
    print "nbs14 oadev OK"
    
    (taus2,adevs2,aerrs2,ns2) = allan.mdev_phase( nbs14_phase, 1.0, taus)
    mdevs = nbs14_devs[2]
    assert( check_devs( adevs2[0], mdevs[0] ) )
    assert( check_devs( adevs2[1], mdevs[1] ) )
    print "nbs14 mdev OK"
    
    (taus2,adevs2,aerrs2,ns2) = allan.totdev_phase( nbs14_phase, 1.0, taus)
    totdevs = nbs14_devs[3]
    assert( check_devs( adevs2[0], totdevs[0] ) )
    assert( check_devs( adevs2[1], totdevs[1] ) )
    print "nbs14 totdev OK"
    
    (taus2,adevs2,aerrs2,ns2) = allan.hdev_phase( nbs14_phase, 1.0, taus)
    hdevs = nbs14_devs[4]
    assert( check_devs( adevs2[0], hdevs[0] ) )
    assert( check_devs( adevs2[1], hdevs[1] ) )
    print "nbs14 hdev OK"
    
    (taus2,adevs2,aerrs2,ns2) = allan.tdev_phase( nbs14_phase, 1.0, taus)
    tdevs = nbs14_devs[5]
    assert( check_devs( adevs2[0], tdevs[0] ) )
    assert( check_devs( adevs2[1], tdevs[1] ) )
    print "nbs14 tdev OK"

    (taus2,adevs2,aerrs2,ns2) = allan.ohdev_phase( nbs14_phase, 1.0, taus)
    ohdevs = nbs14_devs[6]
    assert( check_devs( adevs2[0], ohdevs[0] ) )
    assert( check_devs( adevs2[1], ohdevs[1] ) )
    print "nbs14 ohdev OK"


    # then the same tests for frequency data
    print "nbs14 tests for frequency data:"

    f_fract = [ float(f) for f in nbs14_f]
    (taus2,adevs2,aerrs2,ns2) = allan.adev( f_fract, 1.0, taus)
    adevs = nbs14_devs[0]
    assert( check_devs( adevs2[0], adevs[0] ) )
    assert( check_devs( adevs2[1], adevs[1] ) )
    print "nbs14 freqdata adev OK"

    (taus2,adevs2,aerrs2,ns2) = allan.oadev( f_fract, 1.0, taus)
    oadevs = nbs14_devs[1]
    assert( check_devs( adevs2[0], oadevs[0] ) )
    assert( check_devs( adevs2[1], oadevs[1] ) )
    print "nbs14 freqdata oadev OK"

    (taus2,adevs2,aerrs2,ns2) = allan.mdev( f_fract, 1.0, taus)
    mdevs = nbs14_devs[2]
    assert( check_devs( adevs2[0], mdevs[0] ) )
    assert( check_devs( adevs2[1], mdevs[1] ) )
    print "nbs14 freqdata mdev OK"

    (taus2,adevs2,aerrs2,ns2) = allan.totdev( f_fract, 1.0, taus)
    totdevs = nbs14_devs[3]
    assert( check_devs( adevs2[0], totdevs[0] ) )
    assert( check_devs( adevs2[1], totdevs[1] ) )
    print "nbs14 freqdata totdev OK"
    
    (taus2,adevs2,aerrs2,ns2) = allan.hdev( f_fract, 1.0, taus)
    hdevs = nbs14_devs[4]
    assert( check_devs( adevs2[0], hdevs[0] ) )
    assert( check_devs( adevs2[1], hdevs[1] ) )
    print "nbs14 freqdata hdev OK"

    (taus2,adevs2,aerrs2,ns2) = allan.tdev( f_fract, 1.0, taus)
    tdevs = nbs14_devs[5]
    assert( check_devs( adevs2[0], tdevs[0] ) )
    assert( check_devs( adevs2[1], tdevs[1] ) )
    print "nbs14 freqdata tdev OK"

    (taus2,adevs2,aerrs2,ns2) = allan.ohdev( f_fract, 1.0, taus)
    ohdevs = nbs14_devs[6]
    assert( check_devs( adevs2[0], ohdevs[0] ) )
    assert( check_devs( adevs2[1], ohdevs[1] ) )
    print "nbs14 freqdata ohdev OK"


    print "nbs14 all test OK"
Пример #19
0
                                                   rate=rate,
                                                   taus=my_taus)

(oadev_taus, oadev_devs, oadev_errs, ns) = allan.oadev(phase=phase,
                                                       rate=rate,
                                                       taus=my_taus)

(hdev_taus, hdev_devs, hdev_errs, ns) = allan.hdev(phase=phase,
                                                   rate=rate,
                                                   taus=my_taus)
(ohdev_taus, ohdev_devs, ohdev_errs, ns) = allan.ohdev(phase=phase,
                                                       rate=rate,
                                                       taus=my_taus)

(mdev_taus, mdev_devs, mdev_errs, ns) = allan.mdev(phase=phase,
                                                   rate=rate,
                                                   taus=my_taus)

(totdev_taus, totdev_devs, totdev_errs, ns) = allan.totdev(phase=phase,
                                                           rate=rate,
                                                           taus=my_taus)

(tie_taus, tie_devs, tie_errs, ns) = allan.tierms(phase=phase,
                                                  rate=rate,
                                                  taus=my_taus)
#(mtie_taus,mtie_devs,mtie_errs,ns)  = allan.mtie(phase=phase, rate=rate, taus=my_taus)

(tdev_taus, tdev_devs, tdev_errs, ns) = allan.tdev(phase=phase,
                                                   rate=rate,
                                                   taus=my_taus)
(tdev2_taus, tdev2_devs, tdev2_errs,
Пример #20
0
    return out


fname = "ocxo_frequency.txt"
f10MHz = read_datafile(fname, column=0)

f = to_fractional(f10MHz, 10e6)  # convert to fractional frequency
my_taus = numpy.logspace(1, 5,
                         40)  # log-spaced tau values from 10s and upwards
rate = 1 / float(10)  # data collected with 10s gate time

(oadev_taus, oadev_devs, oadev_errs, ns) = allan.oadev(frequency=f,
                                                       rate=rate,
                                                       taus=my_taus)
(mdev_taus, mdev_devs, mdev_errs, ns) = allan.mdev(frequency=f,
                                                   rate=rate,
                                                   taus=my_taus)
(hdev_taus, hdev_devs, hdev_errs, ns) = allan.hdev(frequency=f,
                                                   rate=rate,
                                                   taus=my_taus)
(ohdev_taus, ohdev_devs, ohdev_errs, ns) = allan.ohdev(frequency=f,
                                                       rate=rate,
                                                       taus=my_taus)

plt.subplot(111, xscale="log", yscale="log")

plt.errorbar(oadev_taus, oadev_devs, yerr=oadev_errs, label='OADEV')
plt.errorbar(mdev_taus, mdev_devs, yerr=mdev_errs, label='MDEV')
plt.errorbar(hdev_taus, hdev_devs, yerr=hdev_errs, label='HDEV')
plt.errorbar(ohdev_taus, ohdev_devs, yerr=ohdev_errs, label='OHDEV')
Пример #21
0
def main():

    nr = 2**14  # number of datapoints in time-series
    adev0 = 1.0e-11

    #
    # for each noise type generated with cn.noiseGen()
    # compute
    #   - phase PSD and coefficient g_b
    #   - frequency PSD and coefficient h_a
    #   - ADEV
    #   - MDEV
    #
    tau0 = 0.1  # sample interval for simulated time-series
    sample_rate = 1.0 / tau0

    qd0 = qd1 = qd2 = qd3 = qd4 = pow(adev0,
                                      2)  # discrete variance for noiseGen()
    # This scaling makes all g_i coefficients equal
    # -> PSDs cross at 1 Hz.
    qd1 = qd0 * 2 * np.pi / sample_rate
    qd2 = qd1 * 2 * np.pi / sample_rate
    qd3 = qd2 * 2 * np.pi / sample_rate
    qd4 = qd3 * 2 * np.pi / sample_rate

    print("generating timeseries..."),
    x0 = cn.noiseGen(nr, qd0, 0)  # white phase noise (WPM)
    x1 = cn.noiseGen(nr, qd1, -1)  # flicker phase noise (FPM)
    x2 = cn.noiseGen(nr, qd2, -2)  # white frequency noise (WFM)
    x3 = cn.noiseGen(nr, qd3, -3)  # flicker frequency noise (FFM)
    x4 = cn.noiseGen(nr, qd4, -4)  # random walk frequency noise (RWFM)

    # compute frequency time-series
    y0 = at.phase2frequency(x0, sample_rate)
    y1 = at.phase2frequency(x1, sample_rate)
    y2 = at.phase2frequency(x2, sample_rate)
    y3 = at.phase2frequency(x3, sample_rate)
    y4 = at.phase2frequency(x4, sample_rate)
    print("done.")

    print("computing PSDs..."),
    # compute phase PSD
    (f0, psd0) = at.noise.scipy_psd(x0, f_sample=sample_rate, nr_segments=4)
    (f1, psd1) = at.noise.scipy_psd(x1, f_sample=sample_rate, nr_segments=4)
    (f2, psd2) = at.noise.scipy_psd(x2, f_sample=sample_rate, nr_segments=4)
    (f3, psd3) = at.noise.scipy_psd(x3, f_sample=sample_rate, nr_segments=4)
    (f4, psd4) = at.noise.scipy_psd(x4, f_sample=sample_rate, nr_segments=4)
    # compute phase PSD prefactor g_b
    g0 = cn.phase_psd_from_qd(qd0, 0, tau0)
    g1 = cn.phase_psd_from_qd(qd1, -1, tau0)
    g2 = cn.phase_psd_from_qd(qd2, -2, tau0)
    g3 = cn.phase_psd_from_qd(qd3, -3, tau0)
    g4 = cn.phase_psd_from_qd(qd4, -4, tau0)
    print g0
    print g1
    print g2
    print g3
    print g4

    # compute frequency PSD
    (ff0, fpsd0) = at.noise.scipy_psd(y0, f_sample=sample_rate, nr_segments=4)
    (ff1, fpsd1) = at.noise.scipy_psd(y1, f_sample=sample_rate, nr_segments=4)
    (ff2, fpsd2) = at.noise.scipy_psd(y2, f_sample=sample_rate, nr_segments=4)
    (ff3, fpsd3) = at.noise.scipy_psd(y3, f_sample=sample_rate, nr_segments=4)
    (ff4, fpsd4) = at.noise.scipy_psd(y4, f_sample=sample_rate, nr_segments=4)
    # compute frequency PSD prefactor h_a
    a0 = cn.frequency_psd_from_qd(qd0, 0, tau0)
    a1 = cn.frequency_psd_from_qd(qd1, -1, tau0)
    a2 = cn.frequency_psd_from_qd(qd2, -2, tau0)
    a3 = cn.frequency_psd_from_qd(qd3, -3, tau0)
    a4 = cn.frequency_psd_from_qd(qd4, -4, tau0)
    print "a_i == g_i*(4pi^2)"
    print a0, g0 * pow(2 * np.pi, 2)
    print a1, g1 * pow(2 * np.pi, 2)
    print a2, g2 * pow(2 * np.pi, 2)
    print a3, g3 * pow(2 * np.pi, 2)
    print a4, g4 * pow(2 * np.pi, 2)

    print("done.")

    print("computing ADEV/MDEV..."),
    # compute ADEV
    (t0, d0, e, n) = at.oadev(x0, rate=sample_rate)
    (t1, d1, e, n) = at.oadev(x1, rate=sample_rate)
    (t2, d2, e, n) = at.oadev(x2, rate=sample_rate)
    (t3, d3, e, n) = at.oadev(x3, rate=sample_rate)
    (t4, d4, e, n) = at.oadev(x4, rate=sample_rate)

    # compute MDEV
    (mt0, md0, e, n) = at.mdev(x0, rate=sample_rate)
    (mt1, md1, e, n) = at.mdev(x1, rate=sample_rate)
    (mt2, md2, e, n) = at.mdev(x2, rate=sample_rate)
    (mt3, md3, e, n) = at.mdev(x3, rate=sample_rate)
    (mt4, md4, e, n) = at.mdev(x4, rate=sample_rate)
    print("done.")

    plt.figure()
    # Phase PSD figure
    plt.subplot(2, 2, 1)
    plt.loglog(f0, [g0 * pow(xx, 0.0) for xx in f0],
               '--',
               label=r'$g_0f^0 = {h_2\over4\pi^2}f^0$',
               color='black')
    plt.loglog(f0, psd0, '.', color='black')

    plt.loglog(f1[1:], [g1 * pow(xx, -1.0) for xx in f1[1:]],
               '--',
               label=r'$g_{-1}f^{-1}  = {h_1\over4\pi^2}f^{-1} $',
               color='red')
    plt.loglog(f1, psd1, '.', color='red')

    plt.loglog(f2[1:], [g2 * pow(xx, -2.0) for xx in f2[1:]],
               '--',
               label=r'$g_{-2}f^{-2}   = {h_0\over4\pi^2}f^{-2} $',
               color='green')
    plt.loglog(f2, psd2, '.', color='green')

    plt.loglog(f3[1:], [g3 * pow(xx, -3.0) for xx in f3[1:]],
               '--',
               label=r'$g_{-3}f^{-3}   = {h_{-1}\over4\pi^2}f^{-3} $',
               color='pink')
    plt.loglog(f3, psd3, '.', color='pink')

    plt.loglog(f4[1:], [g4 * pow(xx, -4.0) for xx in f4[1:]],
               '--',
               label=r'$g_{-4}f^{-4}   = {h_{-2}\over4\pi^2}f^{-4}$',
               color='blue')
    plt.loglog(f4, psd4, '.', color='blue')
    plt.grid()
    plt.legend(framealpha=0.9, fontsize=22)
    plt.title(r'Phase Power Spectral Density')
    plt.xlabel(r'Frequency (Hz)')
    plt.ylabel(r' $S_x(f)$ $(s^2/Hz)$')

    # frequency PSD figure
    plt.subplot(2, 2, 2)
    plt.loglog(ff0[1:], [a0 * pow(xx, 2) for xx in ff0[1:]],
               '--',
               label=r'$h_{2}f^{2}$',
               color='black')
    plt.loglog(ff0, fpsd0, '.', color='black')

    plt.loglog(ff1[1:], [a1 * pow(xx, 1) for xx in ff1[1:]],
               '--',
               label=r'$h_{1}f^{1}$',
               color='red')
    plt.loglog(ff1, fpsd1, '.', color='red')

    plt.loglog(ff2[1:], [a2 * pow(xx, 0) for xx in ff2[1:]],
               '--',
               label=r'$h_{0}f^{0}$',
               color='green')
    plt.loglog(ff2, fpsd2, '.', color='green')

    plt.loglog(ff3[1:], [a3 * pow(xx, -1) for xx in ff3[1:]],
               '--',
               label=r'$h_{-1}f^{-1}$',
               color='pink')
    plt.loglog(ff3, fpsd3, '.', color='pink')

    plt.loglog(ff4[1:], [a4 * pow(xx, -2) for xx in ff4[1:]],
               '--',
               label=r'$h_{-2}f^{-2}$',
               color='blue')
    plt.loglog(ff4, fpsd4, '.', color='blue')
    plt.grid()
    plt.legend(framealpha=0.9, fontsize=22)
    plt.title(r'Frequency Power Spectral Density')
    plt.xlabel(r'Frequency (Hz)')
    plt.ylabel(r' $S_y(f)$ $(1/Hz)$')

    # ADEV figure
    plt.subplot(2, 2, 3)
    f_h = 0.5 / tau0
    K0 = 3.0 * f_h / (4.0 * pow(np.pi, 2))
    plt.loglog(t0, [np.sqrt(K0 * a0) / xx for xx in t0],
               '--',
               label=r'$\sqrt{3f_H\over4\pi^2} \sqrt{h_{2}}\tau^{-3/2}$',
               color='black')
    plt.loglog(t0, d0, 'o', color='black')

    # IEEE 1139-2008, table B.2
    def K1(f_H, tau):
        gamma = 1.038 / 2
        return ((3.0 / 2.0) * np.log(2.0 * np.pi * f_h * tau) +
                gamma) / (2.0 * pow(np.pi, 2))

    plt.loglog(
        t1, [np.sqrt(K1(f_h, xx) * a1) / xx for xx in t1],
        '--',
        label=
        r'$\sqrt{ 3\ln{(2 \pi f_H \tau)} + \gamma \over 4\pi^2 }\sqrt{h_{1}}\tau^{-1}$',
        color='red')
    plt.loglog(t1, d1, 'o', color='red')

    K2 = 0.5
    plt.loglog(t2, [np.sqrt(K2 * a2) / math.sqrt(xx) for xx in t2],
               '--',
               label=r'$\sqrt{1\over2} \sqrt{h_{0}}\tau^{-1/2}$',
               color='green')
    plt.loglog(t2, d2, 'o', color='green')

    K3 = 2 * np.log(2)
    plt.loglog(t3, [np.sqrt(K3 * a3) for xx in t3],
               '--',
               label=r'$ \sqrt{2\ln{2}}\sqrt{h_{-1}}\tau^0$',
               color='pink')
    plt.loglog(t3, d3, 'o', color='pink')

    K4 = (2 * np.pi**2.0) / 3.0
    plt.loglog(t4, [np.sqrt(K4 * a4) * math.sqrt(xx) for xx in t4],
               '--',
               label=r'$\sqrt{2\pi^2\over3}\sqrt{h_{-2}}\tau^{+1/2}$',
               color='blue')
    plt.loglog(t4, d4, 'o', color='blue')

    plt.legend(framealpha=0.9, loc='lower left', fontsize=22)
    plt.grid()
    plt.title(r'Allan Deviation')
    plt.xlabel(r'$\tau$ (s)')
    plt.ylabel(r'ADEV')

    # MDEV
    plt.subplot(2, 2, 4)
    M0 = 3.0 / (8.0 * pow(np.pi, 2))
    plt.loglog(t0, [np.sqrt(M0 * a0) / pow(xx, 3.0 / 2.0) for xx in t0],
               '--',
               label=r'$\sqrt{ 3\over 8\pi^2 } \sqrt{h_{2}}\tau^{-3/2}$',
               color='black')
    plt.loglog(mt0, md0, 'o', color='black')

    M1 = (24.0 * np.log(2) - 9.0 * np.log(3)) / (8.0 * pow(np.pi, 2))

    plt.loglog(
        t1, [np.sqrt(M1 * a1) / xx for xx in t1],
        '--',
        label=r'$\sqrt{ 24\ln(2)-9\ln(3) \over 8\pi^2 } \sqrt{h_{1}}\tau^{-1}$',
        color='red')
    plt.loglog(mt1, md1, 'o', color='red')

    M2 = 0.25
    plt.loglog(t2, [np.sqrt(M2 * a2) / math.sqrt(xx) for xx in t2],
               '--',
               label=r'$ \sqrt{1\over4}\sqrt{h_{0}}\tau^{-1/2}$',
               color='green')
    plt.loglog(mt2, md2, 'o', color='green')

    M3 = 27.0 / 20.0 * np.log(2)
    plt.loglog(t3, [np.sqrt(M3 * a3) for xx in t3],
               '--',
               label=r'$\sqrt{ {27\over20}\ln(2) } \sqrt{h_{-1}}\tau^0$',
               color='pink')
    plt.loglog(mt3, md3, 'o', color='pink')

    M4 = 11.0 / 20.0 * pow(np.pi, 2)
    plt.loglog(t4, [np.sqrt(M4 * a4) * math.sqrt(xx) for xx in t4],
               '--',
               label=r'$ \sqrt{ {11\over20}\pi^2  } \sqrt{h_{-2}}\tau^{+1/2}$',
               color='blue')
    plt.loglog(mt4, md4, 'o', color='blue')

    plt.legend(framealpha=0.9, loc='lower left', fontsize=22)
    plt.grid()
    plt.title(r'Modified Allan Deviation')
    plt.xlabel(r'$\tau$ (s)')
    plt.ylabel(r'MDEV')
    plt.show()
def plotallan_phase(plt, y, rate, taus, style, label):
    (t2, ad, ade, adn) = allantools.mdev(y,
                                         data_type='phase',
                                         rate=rate,
                                         taus=taus)
    plt.loglog(t2, ad, style, label=label)
Пример #23
0
def plotallan(plt, y, rate, taus, style, label=""):
    (t2, ad, ade, adn) = allantools.mdev(y, data_type='freq', rate=rate, taus=taus)
    plt.loglog(t2, ad, style,label=label)
Пример #24
0
def plotallan(plt, y, rate, taus, style, label=""):
    (t2, ad, ade, adn) = allantools.mdev(frequency=y, rate=rate, taus=taus)
    plt.loglog(t2, ad, style,label=label)
Пример #25
0
fname = "gps_1pps_phase_data.txt.gz"
phase = read_datafile(fname,column=0)
print len(phase), " values read: ", len(phase)/3600.0 , " hours"

#f = to_fractional(f10MHz, 10e6 ) # convert to fractional frequency
my_taus = numpy.logspace(1,6,60) # log-spaced tau values from 10s and upwards
rate = 1/float(1.0)

(adev_taus,adev_devs,adev_errs,ns)  = allan.adev(phase=phase, rate=rate, taus=my_taus)
 
(oadev_taus,oadev_devs,oadev_errs,ns)  = allan.oadev(phase=phase, rate=rate, taus=my_taus)

(hdev_taus,hdev_devs,hdev_errs,ns)  = allan.hdev(phase=phase, rate=rate, taus=my_taus)
(ohdev_taus,ohdev_devs,ohdev_errs,ns)  = allan.ohdev(phase=phase, rate=rate, taus=my_taus)

(mdev_taus,mdev_devs,mdev_errs,ns)  = allan.mdev(phase=phase, rate=rate, taus=my_taus)

(totdev_taus,totdev_devs,totdev_errs,ns)  = allan.totdev(phase=phase, rate=rate, taus=my_taus)

(tie_taus,tie_devs,tie_errs,ns)  = allan.tierms(phase=phase, rate=rate, taus=my_taus)
#(mtie_taus,mtie_devs,mtie_errs,ns)  = allan.mtie(phase=phase, rate=rate, taus=my_taus)

(tdev_taus,tdev_devs,tdev_errs,ns)  = allan.tdev(phase=phase, rate=rate, taus=my_taus)
(tdev2_taus,tdev2_devs,tdev2_errs,ns2)  = allan.tdev(frequency=allan.phase2frequency(phase,1.0), rate=rate, taus=my_taus)

plt.subplot(111, xscale="log", yscale="log") 


plt.errorbar(adev_taus, adev_devs, yerr=adev_errs, label='ADEV') 
plt.errorbar(oadev_taus, oadev_devs, yerr=oadev_errs, label='OADEV') 
plt.errorbar(mdev_taus, mdev_devs, yerr=mdev_errs, label='MDEV') 
Пример #26
0
def plotallan_phase(plt,y,rate,taus, style, label):
    (t2, ad, ade,adn) = allantools.mdev(y,data_type='phase',rate=rate,taus=taus)
    plt.loglog(t2, ad, style, label=label)
Пример #27
0
def plotallan_phase(plt,y,rate,taus, style):
	(t2, ad, ade,adn) = allantools.mdev(phase=y,rate=rate,taus=taus)
	plt.loglog(t2, ad, style)
Пример #28
0
def main():

    nr = 2**14  # number of datapoints in time-series
    adev0 = 1.0e-11

    #
    # for each noise type generated Noise class
    # compute
    #   - phase PSD and coefficient g_b
    #   - frequency PSD and coefficient h_a
    #   - ADEV
    #   - MDEV
    #
    # discrete variance for noiseGen()
    qd0 = qd1 = qd2 = qd3 = qd4 = pow(adev0, 2)
    tau0 = 1.0  # sample interval
    sample_rate = 1.0 / tau0

    x0 = at.Noise(nr, qd0, 0)  # white phase noise (WPM)
    x0.generateNoise()
    x1 = at.Noise(nr, qd1, -1)  # flicker phase noise (FPM)
    x1.generateNoise()
    x2 = at.Noise(nr, qd2, -2)  # white frequency noise (WFM)
    x2.generateNoise()
    x3 = at.Noise(nr, qd3, -3)  # flicker frequency noise (FFM)
    x3.generateNoise()
    x4 = at.Noise(nr, qd4, -4)  # random walk frequency noise (RWFM)
    x4.generateNoise()

    # compute frequency time-series
    y0 = at.phase2frequency(x0.time_series, sample_rate)
    y1 = at.phase2frequency(x1.time_series, sample_rate)
    y2 = at.phase2frequency(x2.time_series, sample_rate)
    y3 = at.phase2frequency(x3.time_series, sample_rate)
    y4 = at.phase2frequency(x4.time_series, sample_rate)

    # compute phase PSD
    (f0, psd0) = at.noise.scipy_psd(x0.time_series,
                                    f_sample=sample_rate,
                                    nr_segments=4)
    (f1, psd1) = at.noise.scipy_psd(x1.time_series,
                                    f_sample=sample_rate,
                                    nr_segments=4)
    (f2, psd2) = at.noise.scipy_psd(x2.time_series,
                                    f_sample=sample_rate,
                                    nr_segments=4)
    (f3, psd3) = at.noise.scipy_psd(x3.time_series,
                                    f_sample=sample_rate,
                                    nr_segments=4)
    (f4, psd4) = at.noise.scipy_psd(x4.time_series,
                                    f_sample=sample_rate,
                                    nr_segments=4)

    # compute phase PSD prefactor g_b
    g0 = x0.phase_psd_from_qd(tau0)
    g1 = x1.phase_psd_from_qd(tau0)
    g2 = x2.phase_psd_from_qd(tau0)
    g3 = x3.phase_psd_from_qd(tau0)
    g4 = x4.phase_psd_from_qd(tau0)

    # compute frequency PSD
    (ff0, fpsd0) = at.noise.scipy_psd(y0, f_sample=sample_rate, nr_segments=4)
    (ff1, fpsd1) = at.noise.scipy_psd(y1, f_sample=sample_rate, nr_segments=4)
    (ff2, fpsd2) = at.noise.scipy_psd(y2, f_sample=sample_rate, nr_segments=4)
    (ff3, fpsd3) = at.noise.scipy_psd(y3, f_sample=sample_rate, nr_segments=4)
    (ff4, fpsd4) = at.noise.scipy_psd(y4, f_sample=sample_rate, nr_segments=4)

    # compute frequency PSD prefactor h_a
    a0 = x0.frequency_psd_from_qd(tau0)
    a1 = x1.frequency_psd_from_qd(tau0)
    a2 = x2.frequency_psd_from_qd(tau0)
    a3 = x3.frequency_psd_from_qd(tau0)
    a4 = x4.frequency_psd_from_qd(tau0)

    # compute ADEV
    (t0, d0, e, n) = at.oadev(x0.time_series, rate=sample_rate)
    (t1, d1, e, n) = at.oadev(x1.time_series, rate=sample_rate)
    (t2, d2, e, n) = at.oadev(x2.time_series, rate=sample_rate)
    (t3, d3, e, n) = at.oadev(x3.time_series, rate=sample_rate)
    (t4, d4, e, n) = at.oadev(x4.time_series, rate=sample_rate)

    # compute MDEV
    (mt0, md0, e, n) = at.mdev(x0.time_series, rate=sample_rate)
    (mt1, md1, e, n) = at.mdev(x1.time_series, rate=sample_rate)
    (mt2, md2, e, n) = at.mdev(x2.time_series, rate=sample_rate)
    (mt3, md3, e, n) = at.mdev(x3.time_series, rate=sample_rate)
    (mt4, md4, e, n) = at.mdev(x4.time_series, rate=sample_rate)

    plt.figure()
    # Phase PSD figure
    plt.subplot(2, 2, 1)
    plt.loglog(f0, [g0 * pow(xx, 0.0) for xx in f0],
               '--',
               label=r'$g_0f^0$',
               color='black')
    plt.loglog(f0, psd0, '.', color='black')

    plt.loglog(f1[1:], [g1 * pow(xx, -1.0) for xx in f1[1:]],
               '--',
               label=r'$g_{-1}f^{-1}$',
               color='red')
    plt.loglog(f1, psd1, '.', color='red')

    plt.loglog(f2[1:], [g2 * pow(xx, -2.0) for xx in f2[1:]],
               '--',
               label=r'$g_{-2}f^{-2}$',
               color='green')
    plt.loglog(f2, psd2, '.', color='green')

    plt.loglog(f3[1:], [g3 * pow(xx, -3.0) for xx in f3[1:]],
               '--',
               label=r'$g_{-3}f^{-3}$',
               color='pink')
    plt.loglog(f3, psd3, '.', color='pink')

    plt.loglog(f4[1:], [g4 * pow(xx, -4.0) for xx in f4[1:]],
               '--',
               label=r'$g_{-4}f^{-4}$',
               color='blue')
    plt.loglog(f4, psd4, '.', color='blue')
    plt.grid()
    plt.legend(framealpha=0.9)
    plt.title(r'Phase Power Spectral Density')
    plt.xlabel(r'Frequency (Hz)')
    plt.ylabel(r' $S_x(f)$ $(s^2/Hz)$')

    # frequency PSD figure
    plt.subplot(2, 2, 2)
    plt.loglog(ff0[1:], [a0 * pow(xx, 2) for xx in ff0[1:]],
               '--',
               label=r'$h_{2}f^{2}$',
               color='black')
    plt.loglog(ff0, fpsd0, '.', color='black')

    plt.loglog(ff1[1:], [a1 * pow(xx, 1) for xx in ff1[1:]],
               '--',
               label=r'$h_{1}f^{1}$',
               color='red')
    plt.loglog(ff1, fpsd1, '.', color='red')

    plt.loglog(ff2[1:], [a2 * pow(xx, 0) for xx in ff2[1:]],
               '--',
               label=r'$h_{0}f^{0}$',
               color='green')
    plt.loglog(ff2, fpsd2, '.', color='green')

    plt.loglog(ff3[1:], [a3 * pow(xx, -1) for xx in ff3[1:]],
               '--',
               label=r'$h_{-1}f^{-1}$',
               color='pink')
    plt.loglog(ff3, fpsd3, '.', color='pink')

    plt.loglog(ff4[1:], [a4 * pow(xx, -2) for xx in ff4[1:]],
               '--',
               label=r'$h_{-2}f^{-2}$',
               color='blue')
    plt.loglog(ff4, fpsd4, '.', color='blue')
    plt.grid()
    plt.legend(framealpha=0.9)
    plt.title(r'Frequency Power Spectral Density')
    plt.xlabel(r'Frequency (Hz)')
    plt.ylabel(r' $S_y(f)$ $(1/Hz)$')

    # ADEV figure
    plt.subplot(2, 2, 3)

    plt.loglog(t0, [x0.adev_from_qd(tau0, xx) / xx for xx in t0],
               '--',
               label=r'$\propto\sqrt{h_{2}}\tau^{-1}$',
               color='black')
    plt.loglog(t0, d0, 'o', color='black')

    plt.loglog(t1, [x1.adev_from_qd(tau0, xx) / xx for xx in t1],
               '--',
               label=r'$\propto\sqrt{h_{1}}\tau^{-1}$',
               color='red')
    plt.loglog(t1, d1, 'o', color='red')

    plt.loglog(t2, [x2.adev_from_qd(tau0, xx) / math.sqrt(xx) for xx in t2],
               '--',
               label=r'$\propto\sqrt{h_{0}}\tau^{-1/2}$',
               color='green')
    plt.loglog(t2, d2, 'o', color='green')

    plt.loglog(t3, [x3.adev_from_qd(tau0, xx) * 1 for xx in t3],
               '--',
               label=r'$\propto\sqrt{h_{-1}}\tau^0$',
               color='pink')
    plt.loglog(t3, d3, 'o', color='pink')

    plt.loglog(t4, [x4.adev_from_qd(tau0, xx) * math.sqrt(xx) for xx in t4],
               '--',
               label=r'$\propto\sqrt{h_{-2}}\tau^{+1/2}$',
               color='blue')
    plt.loglog(t4, d4, 'o', color='blue')

    plt.legend(framealpha=0.9, loc='lower left')
    plt.grid()
    plt.title(r'Allan Deviation')
    plt.xlabel(r'$\tau$ (s)')
    plt.ylabel(r'ADEV')

    # MDEV
    plt.subplot(2, 2, 4)

    plt.loglog(t0,
               [x0.mdev_from_qd(tau0, xx) / pow(xx, 3.0 / 2.0) for xx in t0],
               '--',
               label=r'$\propto\sqrt{h_{2}}\tau^{-3/2}$',
               color='black')
    plt.loglog(mt0, md0, 'o', color='black')

    plt.loglog(t1, [x1.mdev_from_qd(tau0, xx) / xx for xx in t1],
               '--',
               label=r'$\propto\sqrt{h_{1}}\tau^{-1}$',
               color='red')
    plt.loglog(mt1, md1, 'o', color='red')

    plt.loglog(t2, [x2.mdev_from_qd(tau0, xx) / math.sqrt(xx) for xx in t2],
               '--',
               label=r'$\propto\sqrt{h_{0}}\tau^{-1/2}$',
               color='green')
    plt.loglog(mt2, md2, 'o', color='green')

    plt.loglog(t3, [x3.mdev_from_qd(tau0, xx)**1 for xx in t3],
               '--',
               label=r'$\propto\sqrt{h_{-1}}\tau^0$',
               color='pink')
    plt.loglog(mt3, md3, 'o', color='pink')

    plt.loglog(t4, [x4.mdev_from_qd(tau0, xx) * math.sqrt(xx) for xx in t4],
               '--',
               label=r'$\propto\sqrt{h_{-2}}\tau^{+1/2}$',
               color='blue')
    plt.loglog(mt4, md4, 'o', color='blue')

    plt.legend(framealpha=0.9, loc='lower left')
    plt.grid()
    plt.title(r'Modified Allan Deviation')
    plt.xlabel(r'$\tau$ (s)')
    plt.ylabel(r'MDEV')
    plt.show()
Пример #29
0
def main():

    nr = 2**14 # number of datapoints in time-series
    tau0=1.0 # sampling interval, sets nyquist frequency to 0.5/tau0
    adev0 = 1.0e-11
    
    #
    # for each noise type generated with cn.noiseGen()
    # compute 
    #   - phase PSD and coefficient g_b
    #   - frequency PSD and coefficient h_a
    #   - ADEV
    #   - MDEV
    #
    qd0 = qd1 = qd2 = qd3 = qd4 = pow(adev0, 2) # discrete variance for noiseGen()
    tau0 = 1.0 # sample interval
    sample_rate = 1/tau0
    
    x0 = cn.noiseGen(nr, qd0, 0)   # white phase noise (WPM)
    x1 = cn.noiseGen(nr, qd1, -1)  # flicker phase noise (FPM)
    x2 = cn.noiseGen(nr, qd2, -2)  # white frequency noise (WFM)
    x3 = cn.noiseGen(nr, qd3 , -3) # flicker frequency noise (FFM)
    x4 = cn.noiseGen(nr, qd4 , -4) # random walk frequency noise (RWFM)
    
    # compute frequency time-series
    y0 = at.phase2frequency(x0, sample_rate)
    y1 = at.phase2frequency(x1, sample_rate)
    y2 = at.phase2frequency(x2, sample_rate)
    y3 = at.phase2frequency(x3, sample_rate)
    y4 = at.phase2frequency(x4, sample_rate)
    
    # compute phase PSD
    (f0, psd0) = at.noise.scipy_psd(x0, fs=sample_rate, nr_segments=4)
    (f1, psd1) = at.noise.scipy_psd(x1, fs=sample_rate, nr_segments=4)
    (f2, psd2) = at.noise.scipy_psd(x2, fs=sample_rate, nr_segments=4)
    (f3, psd3) = at.noise.scipy_psd(x3, fs=sample_rate, nr_segments=4)
    (f4, psd4) = at.noise.scipy_psd(x4, fs=sample_rate, nr_segments=4)
    # compute phase PSD prefactor g_b
    g0 = cn.phase_psd_from_qd( qd0, 0, tau0 )
    g1 = cn.phase_psd_from_qd( qd0, -1, tau0 )
    g2 = cn.phase_psd_from_qd( qd0, -2, tau0 )
    g3 = cn.phase_psd_from_qd( qd0, -3, tau0 )
    g4 = cn.phase_psd_from_qd( qd0, -4, tau0 )

    # compute frequency PSD
    (ff0, fpsd0) = at.noise.scipy_psd(y0, fs=sample_rate, nr_segments=4)
    (ff1, fpsd1) = at.noise.scipy_psd(y1, fs=sample_rate, nr_segments=4)
    (ff2, fpsd2) = at.noise.scipy_psd(y2, fs=sample_rate, nr_segments=4)
    (ff3, fpsd3) = at.noise.scipy_psd(y3, fs=sample_rate, nr_segments=4)
    (ff4, fpsd4) = at.noise.scipy_psd(y4, fs=sample_rate, nr_segments=4)
    # compute frequency PSD prefactor h_a
    a0 = cn.frequency_psd_from_qd( qd0, 0, tau0 )
    a1 = cn.frequency_psd_from_qd( qd1, -1, tau0 )
    a2 = cn.frequency_psd_from_qd( qd2, -2, tau0 )
    a3 = cn.frequency_psd_from_qd( qd3, -3, tau0 )
    a4 = cn.frequency_psd_from_qd( qd4, -4, tau0 )

    # compute ADEV
    (t0,d0,e,n) = at.oadev(x0, rate=sample_rate)
    (t1,d1,e,n) = at.oadev(x1, rate=sample_rate)
    (t2,d2,e,n) = at.oadev(x2, rate=sample_rate)
    (t3,d3,e,n) = at.oadev(x3, rate=sample_rate)
    (t4,d4,e,n) = at.oadev(x4, rate=sample_rate)
    
    # compute MDEV
    (mt0,md0,e,n) = at.mdev(x0, rate=sample_rate)
    (mt1,md1,e,n) = at.mdev(x1, rate=sample_rate)
    (mt2,md2,e,n) = at.mdev(x2, rate=sample_rate)
    (mt3,md3,e,n) = at.mdev(x3, rate=sample_rate)
    (mt4,md4,e,n) = at.mdev(x4, rate=sample_rate)
    

    plt.figure()
    # Phase PSD figure
    plt.subplot(2,2,1)
    plt.loglog(f0,[ g0*pow(xx, 0.0) for xx in f0],'--',label=r'$g_0f^0$', color='black')
    plt.loglog(f0,psd0,'.', color='black')
    
    plt.loglog(f1[1:],[ g1*pow(xx, -1.0) for xx in f1[1:]],'--',label=r'$g_{-1}f^{-1}$', color='red')
    plt.loglog(f1,psd1,'.' ,color='red')
    
    plt.loglog(f2[1:],[ g2*pow(xx,-2.0) for xx in f2[1:]],'--',label=r'$g_{-2}f^{-2}$', color='green')
    plt.loglog(f2,psd2,'.',  color='green')
    
    plt.loglog(f3[1:], [ g3*pow(xx,-3.0) for xx in f3[1:]],'--',label=r'$g_{-3}f^{-3}$', color='pink')
    plt.loglog(f3, psd3, '.', color='pink')
    
    plt.loglog(f4[1:], [ g4*pow(xx,-4.0) for xx in f4[1:]],'--',label=r'$g_{-4}f^{-4}$', color='blue')
    plt.loglog(f4, psd4, '.', color='blue')
    plt.grid()
    plt.legend(framealpha=0.9)
    plt.title(r'Phase Power Spectral Density')
    plt.xlabel(r'Frequency (Hz)')
    plt.ylabel(r' $S_x(f)$ $(s^2/Hz)$')
    
    # frequency PSD figure
    plt.subplot(2,2,2)
    plt.loglog(ff0[1:], [ a0*pow(xx,2) for xx in ff0[1:]],'--',label=r'$h_{2}f^{2}$', color='black')
    plt.loglog(ff0,fpsd0,'.',  color='black')
    
    plt.loglog(ff1[1:], [ a1*pow(xx,1) for xx in ff1[1:]],'--',label=r'$h_{1}f^{1}$', color='red')
    plt.loglog(ff1,fpsd1,'.',  color='red')

    plt.loglog(ff2[1:], [ a2*pow(xx,0) for xx in ff2[1:]],'--',label=r'$h_{0}f^{0}$', color='green')
    plt.loglog(ff2,fpsd2,'.', color='green')
    
    plt.loglog(ff3[1:], [ a3*pow(xx,-1) for xx in ff3[1:]],'--',label=r'$h_{-1}f^{-1}$', color='pink')
    plt.loglog(ff3,fpsd3,'.', color='pink')

    plt.loglog(ff4[1:], [ a4*pow(xx,-2) for xx in ff4[1:]],'--',label=r'$h_{-2}f^{-2}$', color='blue')
    plt.loglog(ff4,fpsd4,'.', color='blue')
    plt.grid()
    plt.legend(framealpha=0.9)
    plt.title(r'Frequency Power Spectral Density')
    plt.xlabel(r'Frequency (Hz)')
    plt.ylabel(r' $S_y(f)$ $(1/Hz)$')
    
    # ADEV figure
    plt.subplot(2,2,3)

    plt.loglog(t0, [ cn.adev_from_qd(qd0, 0, tau0)/xx for xx in t0],'--', label=r'$\sqrt{Eh_{2}}\tau^{-1}$', color='black')
    plt.loglog(t0,d0,'o', color='black')

    plt.loglog(t1, [ cn.adev_from_qd(qd1, -1, tau0)/xx for xx in t1],'--', label=r'$\sqrt{Dh_{1}}\tau^{-1}$', color='red')
    plt.loglog(t1,d1,'o', color='red')

    plt.loglog(t2, [ cn.adev_from_qd(qd2, -2, tau0)/math.sqrt(xx) for xx in t2],'--', label=r'$\sqrt{Ch_{0}}\tau^{-1/2}$', color='green')
    plt.loglog(t2,d2,'o', color='green')

    plt.loglog(t3, [ cn.adev_from_qd(qd3, -3, tau0)*1 for xx in t3],'--', label=r'$\sqrt{Bh_{-1}}\tau^0$', color='pink')
    plt.loglog(t3,d3,'o', color='pink')

    plt.loglog(t4, [ cn.adev_from_qd(qd4, -4, tau0)*math.sqrt(xx) for xx in t4],'--', label=r'$\sqrt{Ah_{-2}}\tau^{+1/2}$', color='blue')
    plt.loglog(t4,d4,'o', color='blue')

    plt.legend(framealpha=0.9, loc='lower left')
    plt.grid()
    plt.title(r'Allan Deviation')
    plt.xlabel(r'$\tau$ (s)')
    plt.ylabel(r'ADEV')
    
    # MDEV
    plt.subplot(2, 2, 4)

    plt.loglog(t0, [ cn.adev_from_qd(qd0, 0, tau0)/pow(xx,3.0/2.0) for xx in t0],'--', label=r'$\sqrt{Eh_{2}}\tau^{-3/2}$', color='black')
    plt.loglog(mt0,md0,'o', color='black')

    plt.loglog(t1, [ cn.adev_from_qd(qd1, -1, tau0)/xx for xx in t1],'--', label=r'$\sqrt{Dh_{1}}\tau^{-1}$', color='red')
    plt.loglog(mt1,md1,'o', color='red')

    plt.loglog(t2, [ cn.adev_from_qd(qd2, -2, tau0)/math.sqrt(xx) for xx in t2],'--', label=r'$\sqrt{Ch_{0}}\tau^{-1/2}$', color='green')
    plt.loglog(mt2,md2,'o', color='green')

    plt.loglog(t3, [ cn.adev_from_qd(qd3, -3, tau0)**1 for xx in t3],'--', label=r'$\sqrt{Bh_{-1}}\tau^0$', color='pink')
    plt.loglog(mt3,md3,'o', color='pink')

    plt.loglog(t4, [ cn.adev_from_qd(qd4, -4, tau0)*math.sqrt(xx) for xx in t4],'--', label=r'$\sqrt{Ah_{-2}}\tau^{+1/2}$', color='blue')
    plt.loglog(mt4,md4,'o', color='blue')

    plt.legend(framealpha=0.9, loc='lower left')
    plt.grid()
    plt.title(r'Modified Allan Deviation')
    plt.xlabel(r'$\tau$ (s)')
    plt.ylabel(r'MDEV')
    plt.show()
Пример #30
0
    for f in flist:
        out.append(f/float(f0) - 1.0)
    return out


fname = "ocxo_frequency.txt"
f10MHz = read_datafile(fname, column=0)

f = to_fractional(f10MHz, 10e6)  # convert to fractional frequency
# log-spaced tau values from 10s and upwards
my_taus = numpy.logspace(1, 5, 40)
rate = 1/float(10)  # data collected with 10s gate time

(oadev_taus, oadev_devs, oadev_errs, ns) = allan.oadev(
    f, data_type='freq', rate=rate, taus=my_taus)
(mdev_taus, mdev_devs, mdev_errs, ns) = allan.mdev(
    f, data_type='freq', rate=rate, taus=my_taus)
(hdev_taus, hdev_devs, hdev_errs, ns) = allan.hdev(
    f, data_type='freq', rate=rate, taus=my_taus)
(ohdev_taus, ohdev_devs, ohdev_errs, ns) = allan.ohdev(
    f, data_type='freq', rate=rate, taus=my_taus)

plt.subplot(111, xscale="log", yscale="log")

plt.errorbar(oadev_taus, oadev_devs, yerr=oadev_errs, label='OADEV')
plt.errorbar(mdev_taus, mdev_devs, yerr=mdev_errs, label='MDEV')
plt.errorbar(hdev_taus, hdev_devs, yerr=hdev_errs, label='HDEV')
plt.errorbar(ohdev_taus, ohdev_devs, yerr=ohdev_errs, label='OHDEV')

plt.xlabel('Taus (s)')
plt.ylabel('ADEV')
Пример #31
0
def plotallan_phase(plt, y, rate, taus, style, label="",alpha=1.0):
    (t2, ad, ade, adn) = allantools.mdev(phase=y, rate=rate, taus=taus)
    plt.loglog(t2, ad, style, label=label,alpha=alpha)
Пример #32
0
def to_fractional(flist,f0):
    out=[]
    for f in flist:
        out.append( f/float(f0) - 1.0 )
    return out

fname = "ocxo_frequency.txt"
f10MHz = read_datafile(fname,column=0)

f = to_fractional(f10MHz, 10e6 ) # convert to fractional frequency
my_taus = numpy.logspace(1,5,40) # log-spaced tau values from 10s and upwards
rate = 1/float(10) # data collected with 10s gate time

(oadev_taus,oadev_devs,oadev_errs,ns)  = allan.oadev(frequency=f, rate=rate, taus=my_taus)
(mdev_taus,mdev_devs,mdev_errs,ns)  = allan.mdev(frequency=f, rate=rate, taus=my_taus)
(hdev_taus,hdev_devs,hdev_errs,ns)  = allan.hdev(frequency=f, rate=rate, taus=my_taus)
(ohdev_taus,ohdev_devs,ohdev_errs,ns)  = allan.ohdev(frequency=f, rate=rate, taus=my_taus)

plt.subplot(111, xscale="log", yscale="log") 

plt.errorbar(oadev_taus, oadev_devs, yerr=oadev_errs, label='OADEV') 
plt.errorbar(mdev_taus, mdev_devs, yerr=mdev_errs, label='MDEV') 
plt.errorbar(hdev_taus, hdev_devs, yerr=hdev_errs, label='HDEV') 
plt.errorbar(ohdev_taus, ohdev_devs, yerr=ohdev_errs, label='OHDEV') 

plt.xlabel('Taus (s)')
plt.ylabel('ADEV')


plt.legend()