From eb89a48ab517e3813ed2941bacef5f0700f572c4 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Tue, 8 May 2018 16:45:33 +0200 Subject: More talk slides --- talk.slides.html | 223 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 209 insertions(+), 14 deletions(-) (limited to 'talk.slides.html') diff --git a/talk.slides.html b/talk.slides.html index ba87abf..216dade 100644 --- a/talk.slides.html +++ b/talk.slides.html @@ -11905,7 +11905,34 @@ a.anchor-link {
-

Pulling Radio Data out of Thin Air

Pycon Israel 2018

+

Pulling radio data out of thin air

Pycon Israel 2018

+
+
+
+
+
+
+
+

Yuval Adam

    +
  • Full stack developer and systems architecture consultant
  • +
  • But I also like to play with radios
  • +
  • https://yuv.al
  • +
  • @yuvadm
  • +
+ +
+
+
+
+
+
+
+

This talk

    +
  • I never learned physics, RF engineering or signal processing
  • +
  • But radios are pretty cool!
  • +
  • Hopefully in 25 minutes I can show you some neat things
  • +
+
@@ -11915,7 +11942,7 @@ a.anchor-link {

Agenda

  • What are radio waves?
  • -
  • Hardware radios
  • +
  • Hardware vs software radio
@@ -11925,14 +11952,55 @@ a.anchor-link {
-

Radio Waves

static/dipole.gif

+

Radio Waves

static/dipole.gif

+ +
+
+
+
+
+
+
+

RTL-SDR

rtlsdr.jpg

+ +
+
+
+
+
+
+
+

What's it good for

    +
  • Digital TV broadcast ("Idan+", DVB-T)
  • +
  • Airplane tracking (ADS-B)
  • +
  • Weather satellites
  • +
  • FM radio broadcast
  • +
+ +
+
+
+
+
+
+
+

I/Q Sampling

static/cosample.png

+ +
+
+
+
+
+
+
+

Modulations

static/amfm2.gif

-
In [3]:
+
In [ ]:
import numpy as np
@@ -11946,7 +12014,7 @@ a.anchor-link {
 
-
In [4]:
+
In [ ]:
modulator_frequency = 4.0
@@ -11975,7 +12043,7 @@ a.anchor-link {
 
-
In [5]:
+
In [ ]:
plt.subplot(4, 1, 1)
@@ -12005,28 +12073,155 @@ a.anchor-link {
 
-
-
+
+
+
+
In [ ]:
+
+
+
# pyrtlsdr provides us bindings to work with the RTL-SDR driver
+
+from rtlsdr import RtlSdr
+
+sdr = RtlSdr()
+sdr.sample_rate = 1.2e6       # 1,200,000 samples per second
+sdr.center_freq = 91.8e6      # 91,800,00 Hz frequency for the radio station
+sdr.gain = 'auto'             # tune the gain (AKA "volume") automatically
+
+samples = sdr.read_samples(8192000)  # collect samples during 5 seconds
+sdr.close()
+
+print(samples[:5])
+
+ +
+
+
+ +
+
+
+
In [ ]:
+
+
+
# Load the samples into a numpy array
+
+import numpy as np
+
+samples = np.array(samples).astype('complex64')
+
+ +
+
+
+ +
+
+
+
In [ ]:
+
+
+
# We captured too many samples so we need to apply a low pass filter
+# In other words, we have a too large window and we want to make it smaller
 
+import scipy.signal as signal
 
-
+BANDWIDTH = 200e3 +DECIMATION_RATE = int(1.2e6 / BANDWIDTH) -
+samples = signal.decimate(samples, DECIMATION_RATE) +
+
+
+
+
+
+
+
In [ ]:
+
+
+
# Apply the demodulation, we use a polar discriminator
 
+samples = np.angle(samples[1:] * np.conj(samples[:-1]))
+
-
-
+
+
+ +
+
+
+
In [ ]:
+
+
+
# De-emphasis filter - too "sciency"
+# MAKE THINGS SOUND BETTER
+
+d = BANDWIDTH * 75e-6
+x = np.exp(-1/d)
+b, a = [1-x], [1,-x]
+samples = signal.lfilter(b, a, samples)
+
+
+
+ +
+
+
+
In [ ]:
+
+
+
# Decimate the signal down to something an audio driver can handle
+# We only catch the mono part of the signal
+
+AUDIO_RATE = 50e3
+DECIMATION_RATE = int(1.2e6 / BANDWIDTH / AUDIO_RATE)
+
+samples = signal.decimate(samples, DECIMATION_RATE)
+
+ +
+
+
+ +
+
+
+
In [ ]:
+
+
+
# HIT IT
 
+whatever.play(samples)
+
+ +
+
+
+
+
+
+

Caveats

    +
  • Python, NumPy and SciPy are very good at doing fast processing of static data
  • +
  • When handling real-time data, buffering becomes a serious issue
  • +
  • GNU Radio
      +
    • top-notch framework
    • +
    • implemented many signal processing primivites
    • +
    • has a great scheduling engine
    • +
    +
  • +
+ +
+
-- cgit v1.3.1