コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
    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()
コード例 #5
0
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]
コード例 #6
0
class Receiver:
    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 receive(self):
        def rtl_callback(samples, rtlsdr_obj):
            self.rtlSamples.put(samples)

        self.rtl.read_samples_async(rtl_callback, self.sampleRate / 10)

    def findFrame(self):
        currentData = self.rtlSamples.get()
        prevData = self.previousData.get()
        data = np.append(prevData, currentData)

        dataPosition = self.frameSync.synchronizeStartHeader(data)
        dataEndPosition = self.frameSync.synchronizeStopHeader(
            data[dataPosition:])

        if abs(dataEndPosition -
               self.frameSizeInBits) <= self.frameSizeInBits / 10:
            print("Frame found. Size = " + str(dataEndPosition))

            self.previousData.put(data[dataPosition + dataEndPosition:])
            self.frames.put(data[dataPosition:dataPosition + dataEndPosition])
        else:
            self.previousData.put(currentData)

    def processData(self):
        data = self.frames.get()

        data = self.frameSync.correctFreqAndPhase(data)
        data = self.timeRecover.synchronizeTiming(data)
        data = self.demodulator.demodulate(data)

        self.data.put(data)

    def playSound(self):
        dataToPlay = self.data.get()
        #TODO: write func
        return