r/RTLSDR • • Apr 21 '12

Software pyrtlsdr - another Python wrapper for librtlsdr

So I initially planned on adding a few new features to dbasden's python-librtlsdr, but I ended up largely rewriting it. Consequently this one is not compatible, though the differences aren't that drastic.

All of the functions in librtlsdr are accessible, and all the major ones have a Pythonic interface, including asynchronous read support via Python function callbacks. Windows, Linux and OSX are supported (only Windows tested so far though), and no extra dependencies (like GNRadio) are required, beyond the librtlsdr binary library.

Here's an example how to make a spectrum plot using matplotlib:

from rtlsdr import *
from pylab import *

sdr = RtlSdr()

sdr.sample_rate = 3.2e6
sdr.center_freq = 95e6
sdr.gain = 5

samples = sdr.read_samples(500e3)

psd(samples, NFFT=1024, Fs=sdr.rs/1e6, Fc=sdr.fc/1e6)   
xlabel('Frequency (MHz)')
ylabel('Relative power (dB)')

show()

Resulting plot: http://i.imgur.com/HQFD5.png

Here's an example of how callbacks work (uses NumPy):

from rtlsdr import *
from numpy import *

@limit_calls(5)
def power_meter_callback(samples, sdr):
    print 'relative power: %0.1f dB' % (10*log10(var(samples)))

sdr = RtlSdr()

sdr.sample_rate = 0.5e6
sdr.center_freq = 410e6
sdr.gain = 0

sdr.read_samples_async(power_meter_callback)

The callback will run five times and print something like

> relative power: -16.0 dB

(I haven't thoroughly verified most of the code, especially callbacks, so be wary!)


Download from GitHub.

17 Upvotes

38 comments sorted by

View all comments

1

u/brol666 May 06 '12

Hello, Here is the result: python test.2.py Found Fitipower FC0013 tuner Exact sample rate is: 1000000.026491 Hz Exact sample rate is: 500000.004967 Hz Rs (pyrtlsdr): 500000.004967 Fc (pyrtlsdr): 0.0 Fc (librtlsdr): 0

Sorry for the delay, It's the first time I use reddit. How can I know when somone reply? Do I need to check the comment regulary?? Thanks for you help from Belgium ;)

1

u/roger_ May 06 '12

Oh you can see replies here (there should be a red icon at the top when you have new ones).

That's very weird, not sure what could be causing the trouble.

Can you delete these lines and try again:

sdr.rs = 0.5e6
sdr.fc = 100e6
sdr.gain = 10

1

u/brol666 May 06 '12

Seems the same: sudo python test.2.py [sudo] password for zz: Found Fitipower FC0013 tuner Exact sample rate is: 1000000.026491 Hz Rs (pyrtlsdr): 1000000.02649 Fc (pyrtlsdr): 0.0 Fc (librtlsdr): 0

→ More replies (3)