From 9d44d520177a8e67ac76ce40b9e5777608b0031e Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sat, 26 May 2018 13:16:24 +0300 Subject: Fix signal processing, use files --- talk.slides.html | 82 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 28 deletions(-) (limited to 'talk.slides.html') diff --git a/talk.slides.html b/talk.slides.html index 31d711f..e00e354 100644 --- a/talk.slides.html +++ b/talk.slides.html @@ -11915,7 +11915,6 @@ a.anchor-link {
# Load the samples into a numpy array
+# Alternatively, load previously captured samples from rtl_sdr
+# and convert them from unsigned 8-bit samples to a complex IQ array
import numpy as np
-samples = np.array(samples).astype('complex64')
+raw = np.fromfile('/tmp/samples.in', np.uint8).astype(np.float64)
+raw += -127
+raw /= 2**7
+samples = (raw[0::2] + 1j * raw[1::2]).astype(np.complex64)
# We captured too many samples so we need to apply a low pass filter
@@ -12103,7 +12109,7 @@ a.anchor-link {
import scipy.signal as signal
BANDWIDTH = 200e3
-DECIMATION_RATE = int(1.2e6 / BANDWIDTH)
+DECIMATION_RATE = int(1.2e6 / BANDWIDTH) # Decimation factor of 6
samples = signal.decimate(samples, DECIMATION_RATE)
# Apply the demodulation, we use a polar discriminator
+# Apply the Frequency DEmodulation
+# We use something called a polar discriminator
samples = np.angle(samples[1:] * np.conj(samples[:-1]))
@@ -12130,10 +12137,12 @@ a.anchor-link {
# De-emphasis filter - too "sciency"
+# De-emphasis filter
+# Even I'm not sure how/why this works
+
# MAKE THINGS SOUND BETTER
d = BANDWIDTH * 75e-6
@@ -12149,31 +12158,45 @@ a.anchor-link {
-In [ ]:
+In [5]:
# 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)
+DECIMATION_RATE = int(BANDWIDTH / AUDIO_RATE) # Decimation factor of 4
samples = signal.decimate(samples, DECIMATION_RATE)
+
+# Amplify the signal volume
+samples *= 10000
+samples = samples.astype('int16')
-
+ # HIT IT
-whatever.play(samples)
+import alsaaudio
+
+device = alsaaudio.PCM(alsaaudio.PCM_PLAYBACK, device='default')
+device.setchannels(1)
+device.setrate(50000)
+device.setformat(alsaaudio.PCM_FORMAT_S16_LE)
+device.setperiodsize(120)
+
+# Write data in chunks
+for s in np.array_split(samples, 120):
+ device.write(s)