Exemplo n.º 1
0
    def create_bch_codes(m, t):
        """

        Creates BCH binary codes which can correct up to t bit errors
        Parameters
        ----------
        m : positive integer (>=3)
        t : number of bit errors to be corrected
        
        Returns
        -------
        instance of the BCH code
        """
        code = komm.BCHCode(m, t)
        return code
Exemplo n.º 2
0
    def BCH_decode(self, encoded_parts, parameter, correcting_capability):
        """Decoding method for cyclic BCH code
            """
        code = komm.BCHCode(parameter, correcting_capability)
        decoded_parts = []
        for i in range(0, len(encoded_parts)):
            decoded_part = code.decode(encoded_parts[i])
            decoded_parts.append(decoded_part)

        decoded_parts = np.array(decoded_parts)
        decoded_parts = np.concatenate(decoded_parts)
        if (len(self.image_bits) % code.dimension != 0):
            for i in range(
                    0,
                    self.calculate_zeros_addition_BCH(parameter,
                                                      correcting_capability)):
                decoded_parts = np.delete(decoded_parts,
                                          len(decoded_parts) - 1)

        return decoded_parts
Exemplo n.º 3
0
    def BCH_encode(self, parameter, correcting_capability):
        """ BCH code encoding method 
        1 <= correcting_capability < 2^(parameter -1)
        """

        bits = np.array(self.image_bits)
        code = komm.BCHCode(parameter, correcting_capability)

        if (len(bits) % code.dimension > 0):

            bits = np.append(bits, [
                np.zeros(self.calculate_zeros_addition_BCH(
                    parameter, correcting_capability),
                         dtype=np.uint8)
            ])
            number_of_arrays = int(len(bits) / code.dimension)
            parts_to_encode = np.reshape(bits, (number_of_arrays, -1),
                                         order='C')

            encoded_parts = []
            for i in range(0, len(parts_to_encode)):
                encoded_part = code.encode(parts_to_encode[i])
                encoded_parts.append(encoded_part)
            encoded_parts = np.array(encoded_parts)

            return encoded_parts

        elif (len(bits) % code.dimension == 0):
            number_of_arrays = int(len(bits) / code.dimension)
            parts_to_encode = np.reshape(bits, (number_of_arrays, -1),
                                         order='C')

            encoded_parts = []
            for i in range(0, len(parts_to_encode)):
                encoded_part = code.encode(parts_to_encode[i])
                encoded_parts.append(encoded_part)
            encoded_parts = np.array(encoded_parts)

            return encoded_parts
Exemplo n.º 4
0
def main():
    Result = []
    SNR = 3
    modulation = komm.PSKModulation(4)
    tx_bin = np.random.randint(2, size = 1200)

    # convolutional code
    Ccode = komm.ConvolutionalCode(feedforward_polynomials=[[0o7, 0o5]])
    tblen = 18
    method = "soft"
    Cparam = convolution_simulation.sim_param(tx_bin, SNR, modulation, Ccode, tblen, method)
    BER = format(convolution_simulation.CCODE_simulation(Cparam), '.4f')
    Result.append([BER,'1/2'])

    Ccode = komm.ConvolutionalCode(feedforward_polynomials=[[0o155, 0o117]])
    tblen = 36
    method = "soft"
    Cparam = convolution_simulation.sim_param(tx_bin, SNR, modulation, Ccode, tblen, method)
    BER = format(convolution_simulation.CCODE_simulation(Cparam), '.4f')
    Result.append([BER,'1/2'])

    Ccode = komm.ConvolutionalCode(feedforward_polynomials=[[0o155, 0o117, 0o127]])
    tblen = 36
    method = "soft"
    Cparam = convolution_simulation.sim_param(tx_bin, SNR, modulation, Ccode, tblen, method)
    BER = format(convolution_simulation.CCODE_simulation(Cparam), '.4f')
    Result.append([BER,'1/3'])

    # BCH code
    BCH_encoder = komm.BCHCode(3, 1)
    BCH_param = BCH_simulation.sim_param(tx_bin, SNR, modulation, BCH_encoder)
    BER = format(BCH_simulation.sim_BCH(BCH_param), '.4f')
    Result.append([BER,'4/7'])

    BCH_encoder = komm.BCHCode(4, 3)
    BCH_param = BCH_simulation.sim_param(tx_bin, SNR, modulation, BCH_encoder)
    BER = format(BCH_simulation.sim_BCH(BCH_param), '.4f')
    Result.append([BER,'5/15'])

    BCH_encoder = komm.BCHCode(5, 7)
    BCH_param = BCH_simulation.sim_param(tx_bin, SNR, modulation, BCH_encoder)
    BER = format(BCH_simulation.sim_BCH(BCH_param), '.4f')
    Result.append([BER,'6/31'])

    BCH_encoder = komm.BCHCode(6, 13)
    BCH_param = BCH_simulation.sim_param(tx_bin, SNR, modulation, BCH_encoder)
    BER = format(BCH_simulation.sim_BCH(BCH_param), '.4f')
    Result.append([BER,'10/63'])

    # ARQ
    BER = format(ARQ_simulation.ARQ_simulation(tx_bin, modulation, SNR), '.4f')
    Result.append([BER, '7/8'])


    columns = ['BER','Code rate']
    rows = ['(0o7,0o5)','(0o155,0o117)','(0o155,0o117,0o127)','(7,4)BCH','(15,5)BCH','(31,6)BCH','(63,10)BCH','ARQ']

    plt.table(cellText = Result, rowLabels = rows, colLabels = columns, loc='center')
    plt.axis('tight')
    plt.axis('off')
    plt.title("Comparison among different FEC code")
    plt.show()
Exemplo n.º 5
0
def main():
    # param specification
    SNR = 0
    modulation = komm.PSKModulation(4)
    tx_bin = np.random.randint(2, size=1200)
    decision_method = "soft"
    param = []

    # Convolution param (0o7,0o5)
    tblen = 18
    C_code = komm.ConvolutionalCode(feedforward_polynomials=[[0o7, 0o5]])
    BCH_code = komm.BCHCode(3, 1)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))
    BCH_code = komm.BCHCode(4, 3)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))
    BCH_code = komm.BCHCode(5, 7)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))
    BCH_code = komm.BCHCode(6, 13)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))

    # Convolution param (0o155,0o117)
    tblen = 36
    C_code = komm.ConvolutionalCode(feedforward_polynomials=[[0o155, 0o117]])
    BCH_code = komm.BCHCode(3, 1)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))
    BCH_code = komm.BCHCode(4, 3)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))
    BCH_code = komm.BCHCode(5, 7)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))
    BCH_code = komm.BCHCode(6, 13)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))

    # Convolution param (0o155,0o117,0o127)
    tblen = 36
    C_code = komm.ConvolutionalCode(
        feedforward_polynomials=[[0o155, 0o117, 0o127]])
    BCH_code = komm.BCHCode(3, 1)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))
    BCH_code = komm.BCHCode(4, 3)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))
    BCH_code = komm.BCHCode(5, 7)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))
    BCH_code = komm.BCHCode(6, 13)
    param.append(
        con_param(tx_bin, SNR, modulation, BCH_code, C_code, tblen,
                  decision_method))

    BER = []
    for i in range(0, len(param), 4):
        temp = [
            format(sim_CON(param[i]), '.4f'),
            format(sim_CON(param[i + 1]), '.4f'),
            format(sim_CON(param[i + 2]), '.4f'),
            format(sim_CON(param[i + 3]), '.4f')
        ]
        BER.append(temp)

    columns = ['(7,4)BCH', '(15,5)BCH', '(31,6)BCH', '(63,10)BCH']
    rows = ['(0o7,0o5)', '(0o155,0o117)', '(0o155,0o117,0o127)']

    plt.table(cellText=BER, rowLabels=rows, colLabels=columns, loc='center')
    plt.axis('tight')
    plt.axis('off')
    plt.title(
        "Comparison among different combination of BCH code and Conv code")
    plt.show()
Exemplo n.º 6
0
def generateBCHCode(
    mi, tau
):  # n = 2^(mi) - 1, 1<= tau <2^(mi-1), ; dlugosc pakietu (dimension) -> k>= n - mi*tau
    coder = komm.BCHCode(mi, tau)
    return coder
Exemplo n.º 7
0
def main():

    SNR = np.arange(-5, 10, 1)
    modulation = komm.PSKModulation(4)
    tx_bin = np.random.randint(2, size = 1200)
    # new figure
    plt.figure()

    P = multiprocessing.Pool(len(SNR))
    encoder = komm.BCHCode(3, 1)   # (7,4) BCH
    param = []
    for i in range(0,len(SNR)):
        param.append(sim_param(tx_bin, SNR[i], modulation, encoder))
    BER = P.map(sim_BCH, param)
    plt.plot(SNR, BER, label = '(7,4) BCH code')
    P.close()
    P.join()

    P = multiprocessing.Pool(len(SNR))
    encoder = komm.BCHCode(4, 3)   # (15,5) BCH
    param = []
    for i in range(0,len(SNR)):
        param.append(sim_param(tx_bin, SNR[i], modulation, encoder))
    BER = P.map(sim_BCH, param)
    plt.plot(SNR, BER, label = '(15,5) BCH code')
    P.close()
    P.join()

    P = multiprocessing.Pool(len(SNR))
    encoder = komm.BCHCode(5, 7)   # (31,6) BCH
    param = []
    for i in range(0,len(SNR)):
        param.append(sim_param(tx_bin, SNR[i], modulation, encoder))
    BER = P.map(sim_BCH, param)
    plt.plot(SNR, BER, label = '(31,6) BCH code')
    P.close()
    P.join()

    P = multiprocessing.Pool(len(SNR))
    encoder = komm.BCHCode(6, 13)   # (63,10) BCH
    param = []
    for i in range(0,len(SNR)):
        param.append(sim_param(tx_bin, SNR[i], modulation, encoder))
    BER = P.map(sim_BCH, param)
    plt.plot(SNR, BER, label = '(63,10) BCH code')
    P.close()
    P.join()

    P = multiprocessing.Pool(len(SNR))
    encoder = -1
    param = []
    for i in range(0,len(SNR)):
        param.append(sim_param(tx_bin, SNR[i], modulation, encoder))
    BER = P.map(sim_BCH, param)
    plt.plot(SNR, BER, label = 'QPSK without FEC')
    P.close()
    P.join()
    
    plt.xlabel("SNR")
    plt.ylabel("BER")
    plt.yscale('log')
    plt.legend()
    plt.title("Comparison among different BCH codes")
    plt.show()
Exemplo n.º 8
0
 def calculate_zeros_addition_BCH(self, parameter, correcting_capability):
     bits = np.array(self.image_bits)
     code = komm.BCHCode(parameter, correcting_capability)
     additional_zeros = (int(len(bits) / code.dimension + 1) *
                         code.dimension) - len(bits)
     return additional_zeros
Exemplo n.º 9
0
import numpy as np
import komm

code = komm.BCHCode(4, 2)
bpsk = komm.PAModulation(2)
awgn = komm.AWGNChannel(2.0)

print(code)
print((code.length, code.dimension, code.minimum_distance))
print(code._available_decoding_methods())
print(code._default_encoder())
print(code._default_decoder(np.float))
print(code.generator_polynomial)
#print(code.generator_matrix)
print(code.parity_polynomial)
#print(code.parity_check_matrix)

n_words = 1_000

message = np.random.randint(2, size=n_words * code.dimension)
codeword = code.encode(message)

sentword = bpsk.modulate(codeword)
recvword = awgn(sentword)
demodulated_hard = bpsk.demodulate(recvword)
message_hat = code.decode(demodulated_hard)

#print(message)
#print(codeword)
#print(demodulated_hard)
#print((codeword != recvword_hard).astype(np.int))