Skip to content

Instantly share code, notes, and snippets.

@nickrobinson
Created May 6, 2019 22:57
Show Gist options
  • Save nickrobinson/3e3f3c70910090cf79be3ee720a3c6d0 to your computer and use it in GitHub Desktop.
Save nickrobinson/3e3f3c70910090cf79be3ee720a3c6d0 to your computer and use it in GitHub Desktop.
from rtlsdr import RtlSdr
import struct
import numpy as np
sdr = RtlSdr()
# configure device
sdr.sample_rate = 2.048e6 # Hz
sdr.center_freq = 100e6 # Hz
sdr.freq_correction = 60 # PPM
sdr.gain = 'auto'
def get_samples():
bytes = sdr.read_bytes(1024)
samples = [(x - 127.4) * (1/128.0) for x in bytes]
num_samples = len(samples)
return struct.pack('%sf' % num_samples, *samples)
output_file = open('rec.bin', 'wb')
while True:
try:
output_file.write(get_samples())
except KeyboardInterrupt:
output_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment