示例#1
0
 def testPlutoADC(self):
     # See if we can get non-zero data from Pluto
     sdr = Pluto()
     data = sdr.rx()
     s = np.sum(np.abs(data))
     del sdr
     self.assertGreater(s, 0, "check non-zero data")
示例#2
0
 def testPlutoCyclicBuffersException(self):
     sdr = Pluto()
     fs = int(sdr.sample_rate)
     fc = -3000000
     N = 1024
     ts = 1 / float(fs)
     t = np.arange(0, N * ts, ts)
     i = np.cos(2 * np.pi * t * fc) * 2**14
     q = np.sin(2 * np.pi * t * fc) * 2**14
     iq = i + 1j * q
     sdr.tx_cyclic_buffer = True
     try:
         sdr.tx(iq)
         sdr.tx(iq)
     except Exception as e:
         if ("TX buffer has been submitted in cyclic mode. \
             To push more data the tx buffer must be destroyed first."
                 not in str(e)):
             fail = True
             msg = "Wrong exception raised, message was: " + str(e)
         else:
             fail = False
     else:
         fail = True
         msg = "ExpectedException not raised"
     # Cleanly end
     del sdr
     if fail:
         self.fail(msg)
示例#3
0
 def testPlutoCyclicBuffers(self):
     sdr = Pluto()
     fs = int(sdr.sample_rate)
     fc = -3000000
     N = 1024
     ts = 1 / float(fs)
     t = np.arange(0, N * ts, ts)
     i = np.cos(2 * np.pi * t * fc) * 2**14
     q = np.sin(2 * np.pi * t * fc) * 2**14
     iq = i + 1j * q
     sdr.tx_cyclic_buffer = True
     sdr.tx(iq)
     sdr.tx_destroy_buffer()
     sdr.tx(iq)
示例#4
0
    def testPlutoDMA(self):
        # Test DMA
        sdr = Pluto()
        sdr.loopback = 1
        sdr.tx_cyclic_buffer = True
        # Create a ramp signal with different values for I and Q
        start = 0
        tx_data = np.array(range(start, 2**11), dtype=np.int16)
        tx_data = tx_data << 4
        tx_data = tx_data + 1j * (tx_data * -1 - 1)
        sdr.rx_buffer_size = len(tx_data) * 2

        sdr.tx(tx_data)
        # Flush buffers
        for _ in range(100):
            data = sdr.rx()
        # Turn off loopback (for other tests)
        sdr.loopback = 0
        del sdr
        # Check data
        offset = 0
        for i in range(len(data)):
            if np.real(data[i]) == start:
                for d in range(len(tx_data)):
                    # print(str(data[i+offset])+" "+str(d+start))
                    self.assertEqual(
                        np.real(data[i + offset]),
                        d + start,
                        "Loopback validation failed for I",
                    )
                    self.assertEqual(
                        np.imag(data[i + offset]),
                        (d + start) * -1 - 1,
                        "Loopback validation failed for Q",
                    )
                    offset = offset + 1
                break
示例#5
0
    def testPlutoDDS(self):
        # See if we can tone from Pluto using DMAs
        sdr = Pluto()
        sdr.tx_lo = 1000000000
        sdr.rx_lo = 1000000000
        sdr.tx_cyclic_buffer = True
        sdr.tx_hardwaregain = -30
        sdr.gain_control_mode = "slow_attack"
        sdr.rx_buffer_size = 2 ** 20
        sdr.sample_rate = 4000000
        sdr.loopback = 1
        # Create a sinewave waveform
        RXFS = int(sdr.sample_rate)
        sdr.dds_enabled = [1, 1, 1, 1]
        fc = 2000
        sdr.dds_frequencies = [fc, 0, fc, 0]
        sdr.dds_scales = [1, 0, 1, 0]
        sdr.dds_phases = [90000, 0, 0, 0]
        # Pass through SDR
        for _ in range(5):
            data = sdr.rx()
        # Turn off loopback (for other tests)
        sdr.loopback = 0
        tone_freq = self.freq_est(data, RXFS)

        # if self.do_plots:
        # import matplotlib.pyplot as plt
        #
        # reals = np.real(data)
        # plt.plot(reals)
        # imags = np.imag(data)
        # plt.plot(imags)
        # plt.xlabel("Samples")
        # plt.ylabel("Amplitude [dbFS]")
        # plt.show()

        diff = np.abs(tone_freq - fc)
        self.assertGreater(fc * 0.01, diff, "Frequency offset")