Python Forum
pyrtlsdr and matplotlib's psd - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: pyrtlsdr and matplotlib's psd (/thread-12982.html)



pyrtlsdr and matplotlib's psd - kiyoshi7 - Sep-22-2018

Hi, I'm trying to read data and integrate the results for a given bandwidth, something that I thought was going to be easy. the problem is that I cannot control the badwidth.

this is the code I am running, its a light modification from the one found on github.
from pylab import *
from rtlsdr import *
import matplotlib
matplotlib.rcdefaults()

for i in range(50):
    sdr = RtlSdr()

    # configure device
    sdr.sample_rate = 2.4e6
    sdr.center_freq = 1.6e9
    sdr.bandwidth = 10e9   # I added to set the bandwith
    sdr.gain = 1

    samples = sdr.read_samples(256*1024)
    sdr.close()

    # use matplotlib to estimate and plot the PSD
    fig = psd(samples, NFFT=1024, Fs=sdr.sample_rate/1e6, Fc=sdr.center_freq/1e6)
    xlabel('Frequency (MHz)')
    ylabel('Relative power (dB)')
    matplotlib.use('Agg')
    name = str(i)
    savefig(name)
    plt.clf()
when I run this code I get a sequence of images like this that gives me only a small region. How can I make the region wider? and how can i extract the average relative power like shown in the graph?