Exemple #1
0
def dosim(freq=10.070801, name="sim", rpt=1, exact=True):
    """
  Do the same analysis as dosnap, but on simulated data.
  The arguments have the same meaning as dosnap except that freq is not
  coupled to the global variable.  A random phase is generated for each pass
  """

    for i in range(rpt):
        snap = get_sim_data(freq, exact)
        np.savetxt(name, snap, fmt='%d')
        fit_cores.fit_snap(freq, samp_freq, name, i == 0)
Exemple #2
0
def dosim(freq=10.070801, name="sim", rpt = 1, exact=True):
  """
  Do the same analysis as dosnap, but on simulated data.
  The arguments have the same meaning as dosnap except that freq is not
  coupled to the global variable.  A random phase is generated for each pass
  """

  for i in range(rpt):
    snap=get_sim_data(freq, exact)
    np.savetxt(name, snap,fmt='%d')
    fit_cores.fit_snap(freq, samp_freq, name, i == 0)
Exemple #3
0
 def fit_ogp(self, freq):
     '''
     Takes a test tone (works best with low frequencies ~10 MHz) and adjusts OGP
     parameters for each core s.t. the residuals are minimized with a least squares
     fit. 
     '''
     snap = self.snap_time()
     for i in (0, 1):
         ogp_fit, sinad = fit.fit_snap(snap, freq, self._samp_rate, 'calibration/if0', 
                                       clear_avgs = (not i), prnt = i)
     ogp_fit = np.array(ogp_fit)[3:].reshape(4, 3)
     cur_ogp = self.get_ogp()
     new_ogp = cur_ogp + ogp_fit
     new_ogp[:, 2] = (new_ogp[:, 2] - new_ogp[:, 2].min()) * 0.65 # magic multiplier
     self.set_ogp(new_ogp)
Exemple #4
0
def dosnap(fr=0, name=None, rpt=1, donot_clear=False, plot=True):
    """
  Takes a snapshot and uses fit_cores to fit a sine function to each
  core separately assuming a CW signal is connected to the input.  The
  offset, gain and phase differences are reoprted for each core as
  well as the average of all four.

  The parameters are:
    fr   The frequency of the signal generator.  It will default to the last
         frequency set by set_freq()
    name the name of the file into which the snapshot is written.  5 other
         files are written.  Name.c1 .. name.c4 contain themeasurements from
	 cores a, b, c and d.  Note that data is taken from cores in the order
	 a, c, b, d.  A line is appended to the file name.fit containing
	 signal freq, average zero, average amplitude followed by triplets
	 of zero, amplitude and phase differences for cores a, b, c and d
	 name defaults to if0 or if1, depending on the current zdok

    rpt  The number of repeats.  Defaults to 1.  The c1 .. c4 files mentioned
         above are overwritten with each repeat, but new rows of data are added
	 to the .fit file for each pass.
  """
    global freq
    if name == None:
        name = "if%d" % (zdok)
    avg_pwr_sinad = 0
    if fr == 0:
        fr = freq
    for i in range(rpt):
        snap = adc5g.get_snapshot(roach2,
                                  snap_name,
                                  man_trig=True,
                                  wait_period=2)
        if (plot):
            plt.clf()
            plt.plot(snap)
            plt.show(block=False)
            rmsSnap = np.std(snap)
            loadingFactor = -20.0 * math.log10(128 / rmsSnap)
            print "Rms = %f, loading factor = %f" % (rmsSnap, loadingFactor)
        if i == rpt - 1:
            np.savetxt(name, snap, fmt='%d')
        ogp, pwr_sinad = fit_cores.fit_snap(snap, fr, samp_freq, name,\
           clear_avgs = ((i == 0) and not donot_clear), prnt = (i == rpt-1))
        avg_pwr_sinad += pwr_sinad
    return ogp, avg_pwr_sinad / rpt
Exemple #5
0
def dosnap(fr=0, name=None, rpt = 1, donot_clear=False, plot=True):
  """
  Takes a snapshot and uses fit_cores to fit a sine function to each
  core separately assuming a CW signal is connected to the input.  The
  offset, gain and phase differences are reoprted for each core as
  well as the average of all four.

  The parameters are:
    fr   The frequency of the signal generator.  It will default to the last
         frequency set by set_freq()
    name the name of the file into which the snapshot is written.  5 other
         files are written.  Name.c1 .. name.c4 contain themeasurements from
	 cores a, b, c and d.  Note that data is taken from cores in the order
	 a, c, b, d.  A line is appended to the file name.fit containing
	 signal freq, average zero, average amplitude followed by triplets
	 of zero, amplitude and phase differences for cores a, b, c and d
	 name defaults to if0 or if1, depending on the current zdok

    rpt  The number of repeats.  Defaults to 1.  The c1 .. c4 files mentioned
         above are overwritten with each repeat, but new rows of data are added
	 to the .fit file for each pass.
  """
  global freq
  if name == None:
    name = "if%d" % (zdok)
  avg_pwr_sinad = 0
  if fr == 0:
    fr = freq
  for i in range(rpt):
    snap=adc5g.get_snapshot(roach2, snap_name, man_trig=True, wait_period=2)
    if(plot):
      plt.clf()
      plt.plot(snap)
      plt.show(block = False)
      rmsSnap = np.std(snap)
      loadingFactor = -20.0*math.log10(128/rmsSnap)
      print "Rms = %f, loading factor = %f" % (rmsSnap,loadingFactor)
    if i == rpt-1:
      np.savetxt(name, snap,fmt='%d')
    ogp, pwr_sinad = fit_cores.fit_snap(snap, fr, samp_freq, name,\
       clear_avgs = ((i == 0) and not donot_clear), prnt = (i == rpt-1))
    avg_pwr_sinad += pwr_sinad
  return ogp, avg_pwr_sinad/rpt
Exemple #6
0
 def do_snap(self, freq=0, fname="t", repeat=1, donot_clear=False):
     """
     Takes a snapshot and uses fit_cores to fit a sine function to each
     core separately assuming a CW signal is connected to the input.  The
     offset, gain and phase differences are reoprted for each core as
     well as the average of all four.
   
     The parameters are:
       fr   The frequency of the signal generator.  It will default to the last
            frequency set by set_freq()
       name the name of the file into which the snapshot is written.  5 other
            files are written.  Name.c1 .. name.c4 contain themeasurements from
        cores a, b, c and d.  Note that data is taken from cores in the order
        a, c, b, d.  A line is appended to the file name.fit containing
        signal freq, average zero, average amplitude followed by triplets
        of zero, amplitude and phase differences for cores a, b, c and d
   
       rpt  The number of repeats.  Defaults to 1.  The c1 .. c4 files mentioned
            above are overwritten with each repeat, but new rows of data are added
        to the .fit file for each pass.
     """
     avg_pwr_sinad = 0
     for i in range(repeat):
         # We skip this interaction with hardware if this is a test, use
         if not self.test:
             snap = self.adc.get_adc_snapshot(man_trig=True, wait_period=2)
             np.savetxt(fname, snap, fmt='%d')
             fname2 = fname
         else:
             # if we're testing, use the intermediate files
             fname2 = "%s.%d" % (fname, i)
         ogp, pwr_sinad = fit_cores.fit_snap(freq,
                                             self.samp_freq,
                                             fname2,
                                             clear_avgs=i == 0
                                             and not donot_clear,
                                             prnt=i == repeat - 1)
         avg_pwr_sinad += pwr_sinad
     return ogp, avg_pwr_sinad / repeat
Exemple #7
0
 def do_snap(self, freq=0, fname="t", repeat = 1, donot_clear=False):
     """
     Takes a snapshot and uses fit_cores to fit a sine function to each
     core separately assuming a CW signal is connected to the input.  The
     offset, gain and phase differences are reoprted for each core as
     well as the average of all four.
   
     The parameters are:
       fr   The frequency of the signal generator.  It will default to the last
            frequency set by set_freq()
       name the name of the file into which the snapshot is written.  5 other
            files are written.  Name.c1 .. name.c4 contain themeasurements from
        cores a, b, c and d.  Note that data is taken from cores in the order
        a, c, b, d.  A line is appended to the file name.fit containing
        signal freq, average zero, average amplitude followed by triplets
        of zero, amplitude and phase differences for cores a, b, c and d
   
       rpt  The number of repeats.  Defaults to 1.  The c1 .. c4 files mentioned
            above are overwritten with each repeat, but new rows of data are added
        to the .fit file for each pass.
     """
     avg_pwr_sinad = 0
     for i in range(repeat):
       # We skip this interaction with hardware if this is a test, use 
       if not self.test:
           snap = self.adc.get_adc_snapshot(man_trig=True, wait_period=2)
           np.savetxt(fname, snap,fmt='%d')
           fname2 = fname
       else:
           # if we're testing, use the intermediate files
           fname2 = "%s.%d" % (fname, i)
       ogp, pwr_sinad = fit_cores.fit_snap(freq
                                         , self.samp_freq
                                         , fname2
                                         , clear_avgs = i == 0 and not donot_clear
                                         , prnt = i == repeat-1)
       avg_pwr_sinad += pwr_sinad
     return ogp, avg_pwr_sinad/repeat        
    # ogp, sinad = rww_tools.dosnap(fr=opts.testfreq,name=FNAME,rpt=opts.n_trials,donot_clear=False)

    # calibration parameters
    rpt = 30  # repetitions until set of offset, ganancia y fase
    snap_name = "snapshot1"  # ADC snapshot name
    samp_freq = frec_samp  # ADC interleave mode sample rate
    FNAME = "snapshot_adc1_raw.dat"
    avg_pwr_sinad = 0
    fr = opts.testfreq
    donot_clear = False

    for i in range(rpt):
        snap = adc.get_snapshot(fpga, snap_name, man_trig=True, wait_period=2)
        np.savetxt(FNAME, snap, fmt="%d")
        ogp, pwr_sinad = fit_cores.fit_snap(
            fr, samp_freq, FNAME, clear_avgs=i == 0 and not donot_clear, prnt=i == rpt - 1
        )
        avg_pwr_sinad += pwr_sinad

    sinad = avg_pwr_sinad / rpt

    ogp = ogp[3:]

    np.savetxt("ogp", ogp, fmt="%8.4f")

    # print registers
    print "OGP registers:  "
    rww_tools.get_ogp()

    print "Setting ogp"
    print 'Doing OGP calibration...'
    #ogp, sinad = rww_tools.dosnap(fr=opts.testfreq,name=FNAME,rpt=opts.n_trials,donot_clear=False)

    # calibration parameters
    rpt = 30  # repetitions until set of offset, ganancia y fase
    snap_name = 'snapshot1'  # ADC snapshot name
    samp_freq = frec_samp  # ADC interleave mode sample rate
    FNAME = 'snapshot_adc1_raw.dat'
    avg_pwr_sinad = 0
    fr = opts.testfreq
    donot_clear = False

    for i in range(rpt):
        snap = adc.get_snapshot(fpga, snap_name, man_trig=True, wait_period=2)
        np.savetxt(FNAME, snap, fmt='%d')
        ogp, pwr_sinad = fit_cores.fit_snap(fr, samp_freq, FNAME,\
            clear_avgs = i == 0 and not donot_clear, prnt = i == rpt-1)
        avg_pwr_sinad += pwr_sinad

    sinad = avg_pwr_sinad / rpt

    ogp = ogp[3:]

    np.savetxt('ogp', ogp, fmt='%8.4f')

    # print registers
    print 'OGP registers:  '
    rww_tools.get_ogp()

    print 'Setting ogp'

    t = np.genfromtxt('ogp')