def __transmitSignal(samplingError, offset, snr, attenuation, freqErr, phaseErr): modulator = Modulator(__CARRIER_FREQ, __SYMBOL_LENGTH_IN_BITS, __FI, __SAMPLING_RATE) demodulator = Demodulator(__CARRIER_FREQ, __SYMBOL_LENGTH_IN_BITS, __FI, __SAMPLING_RATE) channel = RadioChannel(__SAMPLING_RATE) frameSync = FrameSynchronization(modulator.modulate(__HEADER), modulator.modulate(__END_HEADER), __SYMBOL_LENGTH_IN_BITS, __SAMPLING_RATE) timeRecover = TimingRecovery(__SYMBOL_LENGTH_IN_BITS) modulationStart = time.time() modulatedSignal = modulator.modulate(__FRAME) assert(time.time() - modulationStart < 1 / 25) transmittedSignal = channel.transmit(modulatedSignal, signalOffset=offset, adcSamplingErr=samplingError, snr=snr, channelAttenuation=attenuation, freqErr=freqErr, phaseErr=phaseErr) synchronizationStart = time.time() dataPosition = frameSync.synchronizeStartHeader(transmittedSignal) dataEndPosition = frameSync.synchronizeStopHeader(transmittedSignal[dataPosition:]) transmittedSignal = frameSync.correctFreqAndPhase(transmittedSignal[dataPosition:dataPosition + dataEndPosition]) transmittedSignal = timeRecover.synchronizeTiming(transmittedSignal) demodulatedBits = demodulator.demodulate(transmittedSignal) assert (time.time() - synchronizationStart < 1 / 25) return demodulatedBits
def __transmitSignalWithTimingSynchronization(samplingErr): modulator = Modulator(__CARRIER_FREQ, __SYMBOL_LENGTH_IN_BITS, __FI, __SAMPLING_RATE) demodulator = Demodulator(__CARRIER_FREQ, __SYMBOL_LENGTH_IN_BITS, __FI, __SAMPLING_RATE) timeRecover = TimingRecovery(__SYMBOL_LENGTH_IN_BITS) channel = RadioChannel(__SAMPLING_RATE) signal = modulator.modulate(__BITS) transmittedSignal = channel.transmit(signal, adcSamplingErr=samplingErr, snr=10) transmittedSignal = timeRecover.synchronizeTiming(transmittedSignal) demodulatedBits = demodulator.demodulate(transmittedSignal) return demodulatedBits
def __transmitSignalWithFrameSynchronizationAndSamplingError(samplingError, offset, snr=None): modulator = Modulator(__CARRIER_FREQ, __SYMBOL_LENGTH_IN_BITS, __SAMPLING_RATE) demodulator = Demodulator(__CARRIER_FREQ, __SYMBOL_LENGTH_IN_BITS, __SAMPLING_RATE) channel = RadioChannel(__SAMPLING_RATE) frameSync = FrameSynchronization(modulator.modulate(__START_HEADER), modulator.modulate(__END_HEADER), __SYMBOL_LENGTH_IN_BITS, __SAMPLING_RATE) timeRecover = TimingRecovery(__SYMBOL_LENGTH_IN_BITS) modulatedSignal = modulator.modulate(__FRAME) transmittedSignal = channel.transmit(modulatedSignal, signalOffset=offset, adcSamplingErr=samplingError, snr=snr) dataPosition = frameSync.synchronizeStartHeader(transmittedSignal) dataEndPosition = frameSync.synchronizeStopHeader(transmittedSignal) transmittedSignal = transmittedSignal[dataPosition:dataEndPosition] transmittedSignal = timeRecover.synchronizeTiming(transmittedSignal) demodulatedBits = demodulator.demodulate(transmittedSignal) return demodulatedBits
def __init__(self, sampleRate, carrierFreq, symbolLength, frameSize): self.sampleRate = sampleRate self.carrierFreq = carrierFreq self.symbolLength = symbolLength self.frameSizeInBits = frameSize * 8 / 2 self.headerStart = [ 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 ] self.headerEnd = [ 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1 ] self.rtl = RtlSdr() self.rtl.sample_rate = self.sampleRate self.rtl.center_freq = self.carrierFreq self.demodulator = Demodulator(self.carrierFreq, self.symbolLength, self.sampleRate) self.modulator = Modulator(self.carrierFreq, self.symbolLength, self.sampleRate) self.frameSync = FrameSynchronization( self.modulator.modulate(self.headerStart), self.modulator.modulate(self.headerEnd), self.symbolLength, self.sampleRate) self.timeRecover = TimingRecovery(self.symbolLength) self.rtlSamples = Queue() self.frames = Queue() self.previousData = Queue(1) self.previousData.put([0]) self.data = Queue() self.threads = [] self.threads.append(threading.Thread(target=self.receive)) self.threads.append(threading.Thread(target=self.findFrame)) self.threads.append(threading.Thread(target=self.processData)) self.threads.append(threading.Thread(target=self.playSound)) for th in self.threads: th.start()
def shouldRemoveFirstBitFromOtherSymbol(): #TODO: Camcore fix this shit modulator = Modulator(__CARRIER_FREQ, __SYMBOL_LENGTH_IN_BITS, __FI, __SAMPLING_RATE, __NUM_OF_PERIODS_IN_SYMBOL) demodulator = Demodulator(__CARRIER_FREQ, __SYMBOL_LENGTH_IN_BITS, __FI, __SAMPLING_RATE, __NUM_OF_PERIODS_IN_SYMBOL) timeRecover = TimingRecovery(__BUFFER_SIZE, __SYMBOL_LENGTH_IN_BITS) channel = RadioChannel() signal = modulator.modulate(__BITS) transmittedSignal = channel.transmit(signal, snr=3, signalOffset=2) recoveredSignal, rest = timeRecover.recoverTime(transmittedSignal) recoveredSignal.extend(rest) demodulatedBits = demodulator.demodulate(recoveredSignal) properBits = __BITS corruptedBits = 0 for i in range(int(len(demodulatedBits))): if demodulatedBits[i] != properBits[i]: corruptedBits += 2 if int(len(properBits) ) <= i + 2 and demodulatedBits[i] == properBits[i + 2]: del properBits[i] del properBits[i + 1]