Esempio n. 1
0
def qpsk_send_png(noise_strength):
    bit_list = FileIO("computerA\\cloud.png").read_from_file()
    modulator = Modulator()
    demodulator = Demodulator()
    channel = Channel()
    signal = modulator.make_qpsk_mod(bit_list)
    signal.show_signal()

    # With noise=0.1 the image is completely shattered, with noise=0.01 the image is fine
    signal = channel.send_signal(signal, noise_strength)

    result_bits = demodulator.make_qpsk_demod(signal, channel)

    FileIO("computerB\\cloud.png").write_to_file(result_bits)
 def __init__(self,
              start_noise: float,
              end_noise: float,
              psk_type: Psk,
              step=0.01):
     """
     Start benchmarking.
     Parameters
     ----------
     start_noise Starting noise.
     end_noise Ending noise (max to be reached).
     psk_type Type of psk to be tested.
     step Noise increase unit.
     """
     self.start_noise = start_noise
     self.end_noise = end_noise
     self.psk_type = psk_type
     self.distorter = None
     self.step = step
     if psk_type == Psk.Bpsk:
         self.distorter = self.bpsk
     elif psk_type == Psk.Qpsk:
         self.distorter = self.qpsk
     elif psk_type == Psk.Psk8:
         self.distorter = self.psk8
     elif psk_type == Psk.Psk16:
         self.distorter = self.psk16
     self.original_bits = FileIO("computerA\\cloud.png").read_from_file()
     self._start()
Esempio n. 3
0
def test_bpsk_picture(noise_strength):
    # tests sending picture from computerA to computerB with bpsk
    modulator = Modulator()
    demodulator = Demodulator()
    channel = Channel()

    # send signal to modulator
    bits = FileIO("computerA\\cloud.png").read_from_file()
    print(bits)
    signal = modulator.make_bpsk_mod(bits)
    signal.show_signal()

    # send signal to channel
    signal = channel.send_signal(signal, noise_strength)

    # demodulator receives signal
    result_bits = demodulator.make_bpsk_demod(signal, channel)

    FileIO("computerB\\cloud_bpsk.png").write_to_file(result_bits)
Esempio n. 4
0
def test_16psk_picture(noise_strength):
    # tests sending png from computerA to computerB with 16psk
    modulator = Modulator()
    demodulator = Demodulator()
    channel = Channel()

    # send signal to modulator
    bits = FileIO("computerA\\cloud.png").read_from_file()
    signal = modulator.make_16psk_mod(bits)
    signal.show_signal()

    # send signal to channel
    signal = channel.send_signal(signal, noise_strength)

    # demodulator receives signal
    result_bits = demodulator.make_16psk_demod(signal, channel)

    picture_pbm_result = PbmClass()
    picture_pbm_result.read_wireless_signal_from_bits(result_bits)
    FileIO("computerB\\recieved_16psk_cloud.png").write_to_file(result_bits)
Esempio n. 5
0
def qpsk_img_compute_distorsion(noise_strength):
    bit_list = FileIO("computerA\\cloud.png").read_from_file()
    modulator = Modulator()
    demodulator = Demodulator()
    channel = Channel()
    signal = modulator.make_qpsk_mod(bit_list)

    # With noise=0.1 the image is completely shattered, with noise=0.01 the image is fine
    signal = channel.send_signal(signal, noise_strength)

    result_bits = demodulator.make_qpsk_demod(signal, channel)
    print("Number of distorted bits: ",
          utils.compute_distorted_bits(bit_list, result_bits))
Esempio n. 6
0
def wrong_bits_test():
    noise_strength = [0.001, 0.009, 0.01, 0.03, 0.05, 0.1, 0.2, 0.5]
    bpsk = {}
    qpsk = {}
    psk8 = {}
    psk16 = {}

    # tests sending png from computerA to computerB with 16psk
    modulator = Modulator()
    demodulator = Demodulator()
    channel = Channel()

    # send signal to modulator
    bits = FileIO("computerA\\cloud.png").read_from_file()

    for noise in noise_strength:
        # bpsk
        signal1 = modulator.make_bpsk_mod(bits)
        # send signal to channel
        signal1 = channel.send_signal(signal1, noise)
        result_bits1 = demodulator.make_bpsk_demod(signal1, channel)

        # qpsk
        signal2 = modulator.make_qpsk_mod(bits)
        # send signal to channel
        signal2 = channel.send_signal(signal2, noise)
        result_bits2 = demodulator.make_qpsk_demod(signal2, channel)

        # 8psk
        signal3 = modulator.make_8psk_mod(bits)
        # send signal to channel
        signal3 = channel.send_signal(signal3, noise)
        result_bits3 = demodulator.make_8psk_demod(signal3, channel)

        # 16psk
        signal4 = modulator.make_16psk_mod(bits)
        # send signal to channel
        signal4 = channel.send_signal(signal4, noise)
        result_bits4 = demodulator.make_16psk_demod(signal4, channel)

        # wrong bits counters
        wrong_bpsk = 0
        wrong_qpsk = 0
        wrong_8psk = 0
        wrong_16psk = 0

        for i in range(len(result_bits1)):
            # check how many wrong bits
            if bits[i] != result_bits1[i]:
                wrong_bpsk += 1
            if bits[i] != result_bits2[i]:
                wrong_qpsk += 1
            if bits[i] != result_bits3[i]:
                wrong_8psk += 1
            if bits[i] != result_bits4[i]:
                wrong_16psk += 1

        bpsk[noise] = wrong_bpsk
        qpsk[noise] = wrong_qpsk
        psk8[noise] = wrong_8psk
        psk16[noise] = wrong_16psk

    out_file = open('wrong_bits.csv', 'w', newline='')
    headers = ['noise', 'bpsk', 'qpsk', 'psk8', 'psk16', 'oryginal_size']
    writer = csv.DictWriter(out_file,
                            delimiter=';',
                            lineterminator='\n',
                            fieldnames=headers)

    writer.writeheader()

    for i in range(0, 8):
        writer.writerow({
            'noise': noise_strength[i],
            'bpsk': str(list(bpsk.values())[i]).replace('.', ','),
            'qpsk': str(list(qpsk.values())[i]).replace('.', ','),
            'psk8': str(list(psk8.values())[i]).replace('.', ','),
            'psk16': str(list(psk16.values())[i]).replace('.', ','),
            'oryginal_size': len(bits)
        })

    out_file.close()