Exemple #1
0
 def get_quant_spectra(self, autoflip=False):
     d = self.snap('quant_snap', format='B')
     # The results are 4bit real/imag pairs, so reformat
     if autoflip and self.inv_band:
         return helpers.uint2int(d, 4, 3, complex=True)
     else:
         return helpers.uint2int(d, 4, 3, complex=True)[::-1]
 def get_quant_spectra(self, autoflip=False):
     d = self.snap('quant_snap', format='B')
     # The results are 4bit real/imag pairs, so reformat
     if autoflip and self.inv_band:
         return helpers.uint2int(d, 4, 3, complex=True)
     else:
         return helpers.uint2int(d, 4, 3, complex=True)[::-1]
    def get_spectra_snap(self, autoflip=False):
        d = np.zeros(self.n_chans)
        # arm snap blocks
        # WARNING: we can't gaurantee that they all trigger off the same pulse

        # This loop is a hack to make sure the snaps trigger together. NB: This is important since
        # different bits from the same sample end up in multiple snaps. TODO: fix this in firmware
        sync_ok = False
        while (not sync_ok):
            for i in range(3):
                self.write_int('auto_snap_%d_ctrl' % i, 0)
            for i in range(3):
                self.write_int('auto_snap_%d_ctrl' % i, 1)
            sync_ok = True
            for i in range(3):
                # After arming, check no snaps have started taking data
                # If they have, rearm and start again
                if self.read_int('auto_snap_0_status') & (2**31 - 1) != 0:
                    sync_ok = False

        # wait for data to come.
        # NB: there is no timeout condition
        done = False
        while not done:
            status = self.read_int('auto_snap_0_status')
            done = not bool(status & (1 << 31))
            nbytes = status & (2**31 - 1)
            time.sleep(0.01)

        # grab data
        s0 = np.array(
            struct.unpack('>%dH' % (nbytes / 2),
                          self.read('auto_snap_0_bram', nbytes)))
        s1 = np.array(
            struct.unpack('>%dH' % (nbytes / 2),
                          self.read('auto_snap_1_bram', nbytes)))
        s2 = np.array(
            struct.unpack('>%dH' % (nbytes / 2),
                          self.read('auto_snap_2_bram', nbytes)))
        s = np.array([s0, s1, s2])

        # each snap is 128 bits wide. 3 snaps is 384 bits -> 8 * 48 bit signed integers
        # Do bit manipulations to carve up the snaps into 16 bit chunks and glue them together appropriately
        for i in range(8):
            top16 = s[(i * 3 + 0) // 8, (i * 3 + 0) % 8::8]
            mid16 = s[(i * 3 + 1) // 8, (i * 3 + 1) % 8::8]
            low16 = s[(i * 3 + 2) // 8, (i * 3 + 2) % 8::8]
            d[i::8] = helpers.uint2int((top16 << 32) + (mid16 << 16) + low16,
                                       48,
                                       34,
                                       complex=False)

        d /= float(self.fft_power_acc_len)
        if autoflip and self.inv_band:
            d = d[::-1]
        return d
Exemple #4
0
    def get_spectra_snap(self, autoflip=False):
        d = np.zeros(self.n_chans)
        # arm snap blocks
        # WARNING: we can't gaurantee that they all trigger off the same pulse

        # This loop is a hack to make sure the snaps trigger together. NB: This is important since
        # different bits from the same sample end up in multiple snaps. TODO: fix this in firmware
        sync_ok = False
        while (not sync_ok): 
            for i in range(3):
                self.write_int('auto_snap_%d_ctrl'%i,0)
            for i in range(3):
                self.write_int('auto_snap_%d_ctrl'%i,1)
            sync_ok = True
            for i in range(3):
                # After arming, check no snaps have started taking data
                # If they have, rearm and start again
                if self.read_int('auto_snap_0_status') & (2**31 - 1) != 0:
                    sync_ok = False

        # wait for data to come.
        # NB: there is no timeout condition
        done = False
        while not done:
            status = self.read_int('auto_snap_0_status')
            done = not bool(status & (1<<31))
            nbytes = status & (2**31 - 1)
            time.sleep(0.01)

        # grab data
        s0 = np.array(struct.unpack('>%dH'%(nbytes/2), self.read('auto_snap_0_bram', nbytes)))
        s1 = np.array(struct.unpack('>%dH'%(nbytes/2), self.read('auto_snap_1_bram', nbytes)))
        s2 = np.array(struct.unpack('>%dH'%(nbytes/2), self.read('auto_snap_2_bram', nbytes)))
        s = np.array([s0, s1, s2])

        # each snap is 128 bits wide. 3 snaps is 384 bits -> 8 * 48 bit signed integers
        # Do bit manipulations to carve up the snaps into 16 bit chunks and glue them together appropriately
        for i in range(8):
            top16 = s[(i*3 + 0) // 8, (i*3 + 0) % 8 :: 8]
            mid16 = s[(i*3 + 1) // 8, (i*3 + 1) % 8 :: 8]
            low16 = s[(i*3 + 2) // 8, (i*3 + 2) % 8 :: 8]
            d[i::8] = helpers.uint2int((top16 << 32) + (mid16 << 16) + low16, 48, 34, complex=False)
        
        d /= float(self.fft_power_acc_len)
        if autoflip and self.inv_band:
            d = d[::-1]
        return d