def _loop(self):
        """
        Threaded loop for reading data from the device.
        """
        if not self._connected:
            return False

        self.ser.read(100)
        self.ser.write('r')
        self.ser.write('a')
        self.ser.write('t')
        self.ser.write('\x0d')
        resp = self.ser.read(33)[0:-1].split('_')
        if resp.__len__() is not 6 or resp in self.tags:
            return True

        self.tags.append(resp)
        anbit_bin = utils.dec2bin(int(resp[2]))
        reserved_bin = '00000000000000'
        databit_bin = utils.dec2bin(int(resp[3]))
        country_bin = utils.dec2bin(int(resp[0]))
        while country_bin.__len__() < 10:
            country_bin = '0' + country_bin
        id_bin = utils.dec2bin(int(resp[1]))
        while id_bin.__len__() < 10:
            id_bin = '0' + id_bin

        tag_bin = anbit_bin + reserved_bin + databit_bin + country_bin + id_bin
        data = utils.bin2hex(tag_bin)
        self.emit("tag-read", data)
        self.last_tag = data
        # sleep(1)
        return True
예제 #2
0
    def _loop(self):
        """
        Threaded loop for reading data from the device.
        """
        if not self._connected:
            return False
        
        self.ser.read(100)
        self.ser.write('r')
        self.ser.write('a')
        self.ser.write('t')
        self.ser.write('\x0d')
        resp = self.ser.read(33)[0:-1].split('_')
        if resp.__len__() is not 6 or resp in self.tags:
            return True

        self.tags.append(resp)
        anbit_bin = utils.dec2bin(int(resp[2]))
        reserved_bin = '00000000000000'
        databit_bin = utils.dec2bin(int(resp[3]))
        country_bin = utils.dec2bin(int(resp[0]))
        while country_bin.__len__() < 10:
            country_bin = '0' + country_bin
        id_bin = utils.dec2bin(int(resp[1]))
        while id_bin.__len__() < 10:
            id_bin = '0' + id_bin

        tag_bin = anbit_bin + reserved_bin + databit_bin + country_bin + id_bin
        data = utils.bin2hex(tag_bin)
        self.emit("tag-read", data)
        self.last_tag = data
        #sleep(1)
        return True
예제 #3
0
 def bin_repr_of_value(self, value):
     """
     >>> FixedPoint(4, 4, True).bin_repr_of_value(-6.1875)
     '110011101'
     """
     value *= 2**self.fractional_width
     return dec2bin(int(round(value)), self.width())
예제 #4
0
파일: ofdm.py 프로젝트: wenh81/PAPR-net
    def receive(self,
                sig: np.ndarray,
                shift: int,
                channel: np.ndarray,
                decoder=None,
                papr_net=False):
        ofdm_chunks = self.get_recv_qam(sig,
                                        shift=shift,
                                        channel=channel,
                                        decoder=decoder,
                                        papr_net=papr_net)

        sym_num = ofdm_chunks.shape[0]
        bits_per_symbol = sum(self.BitAllocation)

        bit_stream = np.zeros((sym_num, bits_per_symbol), dtype=np.int)
        for i in range(sym_num):
            k = 0
            for j in range(self.SubCarrierNum):
                if self.BitAllocation[j] > 0:
                    dec_val = qamdemod(ofdm_chunks[i, j],
                                       self.BitAllocation[j])
                    bit_stream[i, k:k + self.BitAllocation[j]] = dec2bin(
                        dec_val, self.BitAllocation[j], 'left-msb')
                    k += self.BitAllocation[j]
        bit_stream = bit_stream.reshape((-1, ))

        return bit_stream
예제 #5
0
 def bin_repr_of_value(self, value):
     """
     >>> FixedPoint(4, 4, True).bin_repr_of_value(-6.1875)
     '110011101'
     """
     value *= 2 ** self.fractional_width
     return dec2bin(int(round(value)), self.width())
예제 #6
0
 def get_dat(self, branch):
     if not self.rsc:
         return [int((branch & (2**(self.K - 1))) > 0)]
     else:
         return list(
             np.mod(
                 np.matmul(self.gen_feedback, (dec2bin(branch, self.K))) +
                 get_bit(branch, self.K - 1), 2))
예제 #7
0
파일: ofdm.py 프로젝트: shahruk10/PAPRnet
    def receive(self, signal):

        # creating chunks corresponding to ofdm symbols
        ofdmChunks = np.reshape(signal, (-1, self.N + self.cyclicPrefix))
        # removing cyclic prefix
        ofdmChunks = ofdmChunks[:, self.cyclicPrefix:]
        # converting OFDM signal to mapped mod symbols
        modSymbolsMapped = np.fft.fft(ofdmChunks, n=self.N, axis=-1)

        if self.usePAPRnet:
            modSymbolsMappedRect = np.concatenate(
                [
                    np.expand_dims(modSymbolsMapped.real, 1),
                    np.expand_dims(modSymbolsMapped.imag, 1)
                ],
                axis=1)  # splitting real and imaginary comp

            modSymbolsMappedNN = self.PAPRnetDecoder.predict(
                modSymbolsMappedRect)
            modSymbolsMapped = modSymbolsMappedNN[:,
                                                  0, :] + 1j * modSymbolsMappedNN[:,
                                                                                  1, :]  # converting to complex vals (a+bj)

        # reversing selective mapping
        if self.useSLM:
            modSymbolsMapped = self.unmapSLM(modSymbolsMapped)

        # downsampling
        if self.upsampleFactor > 1:
            modSymbolsMapped = modSymbolsMapped[:, ::(self.upsampleFactor)]

        # un-mapping mod symbols
        modSymbols = qamdemod(modSymbolsMapped, self.M)

        # converting back to bits
        bitStream = dec2bin(modSymbols.flatten(), int(np.log2(self.M)))

        # convolutional decoding using viterbi algorithm
        if self.useConvCode:
            bitStream = viterbi_decode(bitStream, self.trellis)

        return bitStream[0:len(bitStream) - self.padBits]
예제 #8
0
파일: test.py 프로젝트: shahruk10/PAPRnet
xenc = encoder.predict(xvalrect, batch_size=512)  # getting encoder output
xhidd = xenc[:, 0, :] + 1j * xenc[:, 1, :]  # converting to complex vals (a+bj)

# Decoding
decoder = PAPRnetDecoder(N)
decoder.load_weights('decoder.hdf5')

xdec = decoder.predict(xenc, batch_size=512)
xest = xdec[:, 0, :] + 1j * xdec[:, 1, :]

# Calculating BER and PAPR
papr = []

# getting bits from original signal
xsig = np.fft.ifft(xval, n=512, axis=-1)
bits = dec2bin(qamdemod(xval, 4).flatten(), 2)
papr.append(calcPAPR(xsig))

# calculating PAPR of encoder output
xhiddSig = np.fft.ifft(xhidd, n=512, axis=-1)
papr.append(calcPAPR(xhiddSig))

# getting bits from decoder output
xestSig = np.fft.ifft(xest, n=512, axis=-1)
rxNN = np.fft.fft(xestSig, axis=-1)
rxbits = dec2bin(qamdemod(rxNN, 4).flatten(), 2)

# calculating BER
BER = np.sum(np.logical_xor(rxbits, bits)) / (1.0 * len(bits))
print("BER = {}".format(BER))
예제 #9
0
 def get_enc_bits(self, branch):
     return list(
         np.mod(np.matmul(self.gen_matrix, (dec2bin(branch, self.K))), 2))