Exemple #1
0
def convert_to_freq(num, beamweight=1.0):
    """
    Convert the 100-bit number from the snapshot to the frequency channel
    of that data point.

    This is assuming that the data is in the pol1 position and the beamweight
    being applied is beamweight.

    :param num: the 100-bit number to be converted
    :param beamweight: the f16.9 beamweight being applied to the data
    :return:
    """
    # a = num & ((2**50)-1)
    # a = num >> 50
    p1r = None
    p1i = None
    p1r8 = None
    p1i8 = None
    res = None
    try:
        a = num
        p1r = bin2fp(a >> 25, 25, 16, True) * (1.0 / beamweight)
        p1i = bin2fp(a & ((2**25)-1), 25, 16, True) * (1.0 / beamweight)
        p1r8 = fp2fixed_int(p1r, 8, 7, True)
        p1i8 = fp2fixed_int(p1i, 8, 7, True)
        res = (p1r8 << 8) | p1i8
    except Exception as e:
        print(a, p1r, p1i, p1r8, p1i8, res, end='')
        raise e
    return res
def get_data():
    if 'snap_adc0_ss' not in fpga.snapshots.names():
        fpga.registers.fft_shift.write(cdsnap_arm=0)
        fpga.snapshots.snap_cd0_ss.arm()
        fpga.snapshots.snap_cd1_ss.arm()
        fpga.registers.fft_shift.write(cdsnap_arm=1)
        time.sleep(0.1)
        d0 = fpga.snapshots.snap_cd0_ss.read(arm=False)['data']
        d1 = fpga.snapshots.snap_cd1_ss.read(arm=False)['data']
        fpga.registers.fft_shift.write(cdsnap_arm=0)
        rvp0 = []
        rvp1 = []
        for ctr in range(0, len(d0['d0'])):
            for ctr2 in range(8):
                rvp0.append(d0['d%i' % ctr2][ctr])
            for ctr2 in range(4):
                rvp1.append(d0['p1_d%i' % ctr2][ctr])
            tmp = (d0['p1_d4_u8'][ctr] << 2) | d1['p1_d4_l2'][ctr]
            rvp1.append(caspermem.bin2fp(tmp, 10, 9, True))
            for ctr2 in range(5, 8):
                rvp1.append(d1['p1_d%i' % ctr2][ctr])
        return {'p0': fhost_fpga.AdcData(-1, rvp0),
                'p1': fhost_fpga.AdcData(-1, rvp1)}
    else:
        return fpga.get_adc_snapshots()
Exemple #3
0
 def eighty_to_ten(list_w80):
     """
     Convert a list of 80-bit words to 10-bit adc samples
     :param list_w80: a list of 80-bit words, each with eight 10-bit adc samples
     :return: a list of ten-bit ADC samples
     """
     ten_bit_samples = []
     for word80 in list_w80:
         for ctr in range(70, -1, -10):
             tenbit = (word80 >> ctr) & 1023
             tbsigned = bin2fp(tenbit, 10, 9, True)
             ten_bit_samples.append(tbsigned)
     return ten_bit_samples
Exemple #4
0
    return snapd


def unpack_snapd(snaplist):
    # unpack the snapdata into signed 8.7 words per frequency
    # we get in four parallel frequencies
    _dp0 = [[], [], [], []]
    _dp1 = [[], [], [], []]
    for sctr in range(0, num_snaps):
        for dword in snaplist[sctr]:
            four_words = []
            for fwctr in range(3, -1, -1):
                raw_word = (dword >> (fwctr * 16)) & 0xffff
                raw_real = (raw_word >> 8) & 0xff
                raw_imag = raw_word & 0xff
                real = bin2fp(raw_real, 8, 7, True)
                imag = bin2fp(raw_imag, 8, 7, True)
                cplx = complex(real, imag)
                four_words.append(cplx)
            _dp0[sctr].append(four_words[0])
            _dp1[sctr].append(four_words[1])
            _dp0[sctr].append(four_words[2])
            _dp1[sctr].append(four_words[3])
    return _dp0, _dp1


def pack_freqs(p0d, p1d):
    p0_list = []
    p1_list = []
    for pkt_offset in range(0, len(p0d[0]), 256):
        for snapctr in range(0, num_snaps):
 def eighty_to_ten(eighty):
     samples = []
     for offset in range(70, -1, -10):
         binnum = (eighty >> offset) & 0x3ff
         samples.append(bin2fp(binnum, 10, 9, True))
     return samples
Exemple #6
0
def b2fp(dword):
    r1 = (dword >> 8) & 0xff
    i1 = (dword >> 0) & 0xff
    r1 = bin2fp(r1, 8, 7, True)
    i1 = bin2fp(i1, 8, 7, True)
    return r1**2 + i1**2