Created
December 13, 2019 23:53
-
-
Save luigifcruz/9cb90c18377615251e4a520c46cfae9a 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
import simpleaudio as sa | |
from rtlsdr import RtlSdr | |
import math | |
import signal | |
def signal_handler(signum, frame): | |
exit(-1) | |
signal.signal(signal.SIGINT, signal_handler) | |
# User definable settings | |
fm_freq = 102.9e6 | |
# Nerdy definable settings | |
buffer_sec = 1 | |
run_on_gpu = True | |
audio_fs = 48e3 | |
# Setup SDR stuff | |
sdr = RtlSdr() | |
sdr.set_sample_rate(2.4e6) | |
sdr.set_center_freq(fm_freq) | |
# Setup GPU | |
if run_on_gpu: | |
import cupy as np | |
import cusignal as signal | |
else: | |
import numpy as np | |
from scipy import signal | |
# Receiving loop | |
def callback(rec_signal, ctx): | |
rec_signal = signal.resample_poly(rec_signal, 3, 2, window='flattop') | |
rec_signal = np.diff(np.unwrap(np.angle(rec_signal))) | |
caudio = signal.resample_poly(rec_signal, 1, (1.5*sdr.sample_rate)//audio_fs, window='flattop') | |
caudio *= 65535/math.pi | |
sa.play_buffer(np.asnumpy(caudio.astype(np.int16)), 1, 2, int(audio_fs)) | |
sdr.read_samples_async(callback, int(sdr.sample_rate*buffer_sec)) | |
stream.stop_stream() | |
pa.close() | |
sdr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment