Created
May 6, 2019 22:57
-
-
Save nickrobinson/3e3f3c70910090cf79be3ee720a3c6d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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