Close

Larger plot

A project log for DIY SDR for fun

I try programming my own SDR for fun and to learn Python and digital signal processing.

max-felix-mllerMax-Felix Müller 05/05/2019 at 21:200 Comments

As you may have noticed, the data I read in is very focused around the center frequeny.

Here is my first attempt to plot a broader spectrum.

from rtlsdr import RtlSdr
import matplotlib.pyplot as plt
import numpy as np

sdr = RtlSdr()

# configure device
sdr.sample_rate = 2.4e6  # Hz
# sdr.center_freq = 94.7e6  # Hz
sdr.freq_correction = 60   # PPM
sdr.gain = 'auto'

for i in range(70, 130, 2):
    sdr.center_freq = i*1e6  # Hz
    samples = sdr.read_samples(256*1024)
    # use matplotlib to estimate and plot the PSD
    plt.psd(samples, NFFT=1024, Fs=sdr.sample_rate/1e6, Fc=sdr.center_freq/1e6)

sdr.close()

plt.xlabel('Frequency (MHz)')
plt.ylabel('Relative power (dB)')
plt.show()

 The center frequency is increased in small steps. For every step, the output is caculated and added to the graph. Ideally I want to combine all samples into one plot (same color, continuos values) but today there's no time left.

Another thing is the automatic gain which might throw off measurements taken at different times, I will check that out.

PS: Yes, it is. I set the gain to always be 4 for now.

Discussions