main application with tuning, playing, and GUI

This commit is contained in:
Brandon4466
2024-01-14 23:41:53 -08:00
commit 7ee950b2c5
21 changed files with 388 additions and 0 deletions

47
main.py Normal file
View File

@@ -0,0 +1,47 @@
import numpy as np
import matplotlib.pyplot as plt
from pysdr import IQFileSource
from pysdr import FMReceiver
from hackrf import HackRfSource
# Set the HackRF parameters
sample_rate = 2e6 # 2 MHz sample rate
center_freq = 100e6 # 100 MHz center frequency
# Set the FM receiver parameters
audio_sample_rate = 48e3 # 48 kHz audio sample rate
fm_deviation = 75e3 # FM deviation (typical for broadcast FM)
# Create HackRF source
hackrf_source = HackRfSource(sample_rate, center_freq)
# Create IQ file source
iq_file_source = IQFileSource('fm_radio.iq', sample_rate)
# Create FM receiver
fm_receiver = FMReceiver(sample_rate, audio_sample_rate, fm_deviation)
# Read samples from the source and process them
try:
while True:
samples = hackrf_source.read_samples(1024)
if len(samples) == 0:
break
# Process the samples using the FM receiver
audio_samples = fm_receiver.process(samples)
# Do something with the audio samples (e.g., play them)
# For simplicity, let's just plot the spectrum
plt.specgram(audio_samples, Fs=audio_sample_rate, cmap='viridis')
plt.xlabel('Time (s)')
plt.ylabel('Frequency (Hz)')
plt.title('FM Radio Spectrum')
plt.show()
except KeyboardInterrupt:
pass
finally:
# Close the HackRF source
hackrf_source.close()