def _decode(self): while 1: if not self.pipeline.empty(): #time.sleep(.01) logging.info('begin decoding') samples = self.pipeline.get() l = [] filtered = butterworth(samples, 'high') logging.info('filtering done') smoothed = savitzkyFilter(samples, 11, 6) logging.info('smoothing done') data_diff = differ(smoothed) logging.info('differing done') #envelope = detectEnvelope(data_diff) #logging.info('detecting done') envelope = np.abs(data_diff) logging.info('detecting done') hanning = windowing(100, 100) logging.info('hanning done') data_out = lowPassFilter(hanning, 1.0, envelope) logging.info('low pass done') mean = np.mean(data_out) sig = data_out[MAX_FREQUENCY / SAMPLE_RATE * 2:len(data_out):MAX_FREQUENCY / SAMPLE_RATE * 4] for bit in sig: l.append(0 if bit > mean else 1) bits = list2string(l) logging.info(bits) try: logging.info('Hamming process') corrected = Hammingcorrector(bits) de = Hammingdecoder(corrected) logging.info(de) return decodeBaudot(de) except IndexError: logging.info('Index Error') else: time.sleep(.01)
from baudot import encodeBaudot from convertions import list2string, binary2array from hamming import Hammingencoder from soundencoder import encodeSound import matplotlib.pyplot as plt text = str(input('input the data: ')) baudot = list2string(encodeBaudot(text)) print('Baudot code - ', baudot) hamming = Hammingencoder(baudot) print('Hamming code - ', hamming) data = binary2array(hamming) print('Final data - ', data) signal = encodeSound(data) plt.plot(signal) plt.show()