else: channel = ach.AudioChannel(opt.samplerate, opt.chunksize, opt.prefill) # transmit the samples, and retrieve samples back from the channel try: samples_rx = channel.xmit_and_recv(mod_samples) except ZeroDivisionError: # should only happen for audio channel print "I didn't get any samples; is your microphone or speaker OFF?" sys.exit(1) ################################# # process the received samples # make receiver r = Receiver(fc, opt.samplerate, opt.spb) demod_samples = r.demodulate(samples_rx) one, zero, thresh = r.detect_threshold(demod_samples) barker_start = r.detect_preamble(demod_samples, thresh, one) rcdbits = r.demap_and_check(demod_samples, barker_start) decoded_bits = r.decode(rcdbits) # push into sink sink = Sink() rcd_payload = sink.process(databits)#sink.process(decoded_bits) if len(rcd_payload) > 0: hd, err = common_srcsink.hamming(decoded_bits, databits) print 'Hamming distance for payload at frequency', fc,'Hz:', hd, 'BER:', err else: print 'Could not recover transmission.'
else: channel = ach.AudioChannel(opt.samplerate, opt.chunksize, opt.prefill) # transmit the samples, and retrieve samples back from the channel try: samples_rx = channel.xmit_and_recv(mod_samples) except ZeroDivisionError: # should only happen for audio channel print "I didn't get any samples; is your microphone or speaker OFF?" sys.exit(1) ################################# # process the received samples # make receiver r = Receiver(fc, opt.samplerate, opt.spb) demod_samples = r.demodulate(samples_rx) one, zero, thresh = r.detect_threshold(demod_samples) barker_start = r.detect_preamble(demod_samples, thresh, one) rcdbits = r.demap_and_check(demod_samples, barker_start) decoded_bits = r.decode(rcdbits) # push into sink sink = Sink() rcd_payload = sink.process(decoded_bits) if len(rcd_payload) > 0: hd, err = common_srcsink.hamming(decoded_bits, databits) print 'Hamming distance for payload at frequency', fc,'Hz:', hd, 'BER:', err else: print 'Could not recover transmission.'
channel = ach.AudioChannel(opt.samplerate, opt.chunksize, opt.prefill) # transmit the samples, and retrieve samples back from the channel try: samples_rx = channel.xmit_and_recv(mod_samples) except ZeroDivisionError: # should only happen for audio channel print "I didn't get any samples; is your microphone or speaker OFF?" sys.exit(1) ################################# # process the received samples # make receiver r = Receiver(fc, opt.samplerate, opt.spb) #demod_samples = r.demodulate(samples_rx) demod_samples = r.demodulate(mod_samples) one, zero, thresh = r.detect_threshold(demod_samples) barker_start = r.detect_preamble(demod_samples, thresh, one) rcdbits = r.demap_and_check(demod_samples, barker_start) # push into sink sink = Sink() rcd_payload = sink.process(rcdbits) if len(rcd_payload) > 0: hd, err = common_srcsink.hamming(rcd_payload, src_payload) print 'Hamming distance for payload at frequency', fc,'Hz:', hd, 'BER:', err else: print 'Could not recover transmission.' if opt.graph:
def main(): rmkdir(settings.plot_dir) # make/remake plots directory mod = md.Modulator(settings.fs, settings.f) print(dialogs['sig_load']) raw = load_signal(settings.signal_path, settings.signal_length ) # create or load signal array (details in sysfun) a = np.array(raw) # create a numpy array from raw bits ph = phasor.Phasor() channel = Channel() receiverB = Receiver('bpsk') receiverQ = Receiver('qpsk') modulated = {} bers = {} if not settings.only_qpsk: print(dialogs['modulating'] % "BPSK") x, y = mod.modulate_bpsk(a) # modulate the signal modulated['bpsk'] = {'signal': y, 'linspace': x} path = None if settings.save_plots: path = settings.plot_dir + settings.bpsk_filename print(dialogs['plotting'] % settings.bpsk_filename) full_plot(x, y, settings.bpsk_title, path=path) # plot BPSK modulated signal i = 0 if settings.plot_phasors: for bit in raw: # plot phasors for every bit i += 1 print(dialogs['plotting'] % settings.phasor_title_bpsk % (i, bit)) ph.draw(bit, mode='bpsk', title=settings.phasor_title_bpsk % (i, bit)) if not settings.only_realistic: print('Sending BPSK modulated signal to simple receiver') channel.send_simple(modulated['bpsk']['signal'], receiverB) # send signal to simple receiver print('Demodulating received BPSK signal (simple)') receiverB.demodulate_simple( ) # use simple demodulator to demodulate signal err_bits = bit_errors(raw, receiverB.bits) bers['bpsk_raw'] = err_bits ber = BER(err_bits, settings.signal_length) # calculate ber bers['bpsk'] = ber print("BPSK Incorrectly received bits (simple): %d" % err_bits) print("BPSK BER: %g" % ber) if not settings.only_simple: print(dialogs['sending'] % 'BPSK') channel.send(modulated['bpsk']['signal'], receiverB) # send signal to receiver print(dialogs['plotting'] % "received BPSK signal") # plot received signal full_plot(modulated['bpsk']['linspace'], receiverB.received_signal, title='Received %s signal' % 'BPSK') print(dialogs['demodulating'] % "received BPSK") receiverB.demodulate() # demodulate signal # print("Plotting phasor cloud...") # draw phasor cloud # ph.draw_cloud(receiverB.demodulated_signal, 'Received BPSK signal phasor cloud') err_bits = bit_errors(raw, receiverB.bits) bers['bpsk_raw'] = err_bits ber = BER(err_bits, settings.signal_length) # calculate ber bers['bpsk'] = ber print("BPSK Incorrectly received bits: %d" % err_bits) print("BPSK BER: %g" % ber) if not settings.only_bpsk: if len(raw) % 2 is not 0: raw.append(0) # make sure signal can be paired a = np.array(raw) paired = [(raw[i], raw[i + 1]) for i in range(len(raw)) if i % 2 == 0] # pair bits for qpsk modulation print(dialogs['modulating'] % "QPSK") x, y = mod.modulate_qpsk(a) # modulate the signal modulated['qpsk'] = {'signal': y, 'linspace': x} path = None if settings.save_plots: path = settings.plot_dir + settings.qpsk_filename print(dialogs['plotting'] % settings.bpsk_filename) full_plot(x, y, settings.qpsk_title, path=path) i = 0 if settings.plot_phasors: for bit in paired: # plot phasors for every pair i += 1 # print(dialogs['plotting'] % settings.phasor_title_qpsk % (i, bit)) ph.draw(bit, mode='qpsk', title=settings.phasor_title_qpsk % (i, bit[0], bit[1])) if not settings.only_realistic: print('Sending QPSK modulated signal to simple receiver') channel.send_simple(modulated['qpsk']['signal'], receiverQ) # send signal to simple receiver print('Demodulating received QPSK signal (simple)') receiverQ.demodulate_simple( ) # use simple demodulator to demodulate signal err_bits = bit_errors(paired, receiverQ.bits) bers['qpsk_raw'] = err_bits ber = BER(err_bits, settings.signal_length) # calculate ber bers['qpsk'] = ber print("QPSK Incorrectly received bits (simple): %d" % err_bits) print("QPSK BER: %g" % ber) if not settings.only_simple: print(dialogs['sending'] % 'QPSK') channel.send(modulated['qpsk']['signal'], receiverQ) # send signal to receiver print(dialogs['plotting'] % "received QPSK signal") # plot received signal full_plot(modulated['qpsk']['linspace'], receiverQ.received_signal, title='Received %s signal' % 'QPSK') print(dialogs['demodulating'] % "received QPSK") receiverQ.demodulate() # demodulate signal # print("Plotting phasor cloud...") # ph.draw_cloud(receiverQ.demodulated_signal, 'Received QPSK signal phasor cloud') # draw phasor cloud err_bits = bit_errors(paired, receiverQ.bits) bers['qpsk_raw'] = err_bits ber = BER(err_bits, settings.signal_length) # calculate BER bers['qpsk'] = ber print("QPSK Incorrectly received bits: %d" % err_bits) print("QPSK BER: %g" % ber) log_result(bers)
channel = ach.AudioChannel(opt.samplerate, opt.chunksize, opt.prefill) # transmit the samples, and retrieve samples back from the channel try: samples_rx = channel.xmit_and_recv(mod_samples) except ZeroDivisionError: # should only happen for audio channel print "I didn't get any samples; is your microphone or speaker OFF?" sys.exit(1) ################################# # process the received samples # make receiver r = Receiver(fc, opt.samplerate, opt.spb) # demod_samples = r.demodulate(samples_rx) demod_samples = r.demodulate(mod_samples) # no bit errors, feed directly to receiver one, zero, thresh = r.detect_threshold(demod_samples) barker_start = r.detect_preamble(demod_samples, thresh, one) rcdbits = r.demap_and_check(demod_samples, barker_start) # push into sink sink = Sink() rcd_payload = sink.process(rcdbits) if len(rcd_payload) > 0: hd, err = common_srcsink.hamming(rcd_payload, src_payload) print 'Hamming distance for payload at frequency', fc,'Hz:', hd, 'BER:', err else: print 'Could not recover transmission.' if opt.graph:
channel = ach.AudioChannel(opt.samplerate, opt.chunksize, opt.prefill) # transmit the samples, and retrieve samples back from the channel try: samples_rx = channel.xmit_and_recv(mod_samples) except ZeroDivisionError: # should only happen for audio channel print "I didn't get any samples; is your microphone or speaker OFF?" sys.exit(1) ################################# # process the received samples # make receiver r = Receiver(fc, opt.samplerate, opt.spb) # demod_samples = r.demodulate(samples_rx) demod_samples = r.demodulate( mod_samples) # no bit errors, feed directly to receiver one, zero, thresh = r.detect_threshold(demod_samples) barker_start = r.detect_preamble(demod_samples, thresh, one) rcdbits = r.demap_and_check(demod_samples, barker_start) # push into sink sink = Sink() rcd_payload = sink.process(rcdbits) if len(rcd_payload) > 0: hd, err = common_srcsink.hamming(rcd_payload, src_payload) print 'Hamming distance for payload at frequency', fc, 'Hz:', hd, 'BER:', err else: print 'Could not recover transmission.' if opt.graph:
else: channel = ach.AudioChannel(opt.samplerate, opt.chunksize, opt.prefill) # transmit the samples, and retrieve samples back from the channel try: samples_rx = channel.xmit_and_recv(mod_samples) except ZeroDivisionError: # should only happen for audio channel print "I didn't get any samples; is your microphone or speaker OFF?" sys.exit(1) ################################# # process the received samples # make receiver r = Receiver(fc, opt.samplerate, opt.spb) demod_samples = r.demodulate(samples_rx) #NEEDS TO BE SAMPLES_RX one, zero, thresh = r.detect_threshold(demod_samples) barker_start = r.detect_preamble(demod_samples, thresh, one) rcdbits = r.demap_and_check(demod_samples, barker_start) # push into sink sink = Sink() rcd_payload = sink.process(rcdbits) if len(rcd_payload) > 0: hd, err = common_srcsink.hamming(rcd_payload, src_payload) print 'Hamming distance for payload at frequency', fc,'Hz:', hd, 'BER:', err else: print 'Could not recover transmission.'