-
Notifications
You must be signed in to change notification settings - Fork 1
/
testingfile3.py
38 lines (30 loc) · 956 Bytes
/
testingfile3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import rtlsdr
import numpy as np
import matplotlib.pyplot as plt
# Define the RTL SDR module settings
center_freq = 100e6 # Hz
sample_rate = 2.4e6 # Hz
gain = 40 # dB
# Create the RTL SDR object
sdr = rtlsdr.RtlSdr()
# Set the RTL SDR module parameters
sdr.sample_rate = sample_rate
sdr.center_freq = center_freq
sdr.gain = gain
# Read samples from the RTL SDR module
samples = sdr.read_samples(1024*1024)
# Calculate the power spectral density (PSD) in dBm
psd = 10*np.log10(np.abs(np.fft.fft(samples))**2/len(samples)*50)+30
# Create the frequency axis for the plot
freq_axis = np.fft.fftfreq(len(samples), 1/sample_rate)
freq_axis = np.fft.fftshift(freq_axis)
freq_axis = freq_axis + center_freq
freq_axis = freq_axis/1e6
# Plot the spectrum
plt.plot(freq_axis, psd)
plt.xlabel('Frequency (MHz)')
plt.ylabel('Power Spectral Density (dBm)')
plt.ticklabel_format(style='plain')
plt.show()
# Close the RTL SDR object
sdr.close()