rtl tcp radio on iPad, part 3

A quick review on this project: the goal is to write a program for pythonista, on the iPad, that can stream IQ samples from a remote SDR via rtl_tcp, running on the remote computer ("quantalinux"). I wanted to start simple, so I first created a working flow graph in GNU radio, below, to realize each blocks needed to implement a functioning AM radio.

GNU Radio Flow Graph

The next step was to write the code for pythonista. However, this turned out to be too big of a step, since pythonista doesn't have the scipy module, which includes filtering. So instead, I decided to write the code for the flow graph above for my Linux server quantalinux, since I can easily install additional modules. I installed scipy, and then proceeded to write the code (see below).
There is one more issue, a bit more subtle, with the above flow graph that needed to be dumbed down: the problem of continuously streaming audio, and then playing it at the same time. So for now, I just settled on reading IQ samples, processing them into audio, and then writing to a wave file for listening. The following code is tested (and works):

#!/usr/bin/ipython

from rtlsdr import RtlSdr
import scipy.signal as spsi
from   scipy.io.wavfile import write
import numpy as np
from pylab import *
from rtlsdr import *

##################### RTL-SDR Source Block #####################################
sdr = RtlSdr()

freq_offset = 124996881 # Hz Use this offset when ham-it-up is turned on.
station     =    810396 # Hz
tune_to     = freq_offset + station

seconds    =  5        # Seconds
Fs         = 960000    # Hz  Default: 2.048e6  # 1323000 = 44100 * 30, 
audio_rate = 48000     # Hz

# configure device
sdr.sample_rate = Fs    
sdr.center_freq = tune_to   # Hz
sdr.gain = 32.8             # set to auto to enable AGC

signal = sdr.read_samples(seconds*Fs)
################################################################################

#################### Low Pass Filter and Down Sampling #########################
N=111
Fc=2000.0/Fs  # = 2000/960000 (2KHz width in relative frequency.)
Fl=  100.0/Fs  # reject below this frequency
# Low pass filter, 2KHz
h=spsi.firwin( numtaps=N, cutoff=Fc, nyq=Fs/2)
# 'signal' is the time-series data you are filtering
filtered=spsi.lfilter( h, 1.0, signal) 

# down-sampling after filtering sounds much better. 
filtered = filtered[0::int(Fs/audio_rate)]  
################################################################################

###################### Complex to Mag ##########################################
filtered = abs(filtered)
################################################################################

##################### Write to Wave File (substitute for audio sink) ###########
scaled = np.int16(filtered/np.max(np.abs(filtered)) * 32767)
write('test.wav', audio_rate, scaled)
################################################################################

The next step is to port the above code to pythonista on the iPad, which doesn't have scipy (for filtering), and is probably somewhat limited in the audio sampling rates that it supports.


Last posts

  1. rtl tcp radio on iPad, part 2

    tags: software defined radiopython

  2. Play rtl_tcp radio on iPad using Pythonista

    tags: software defined radiopython

  3. A Useful Windows Tool

    tags: useful software

  4. Hello OpenElec, Good-bye Arch Linux.

    tags: Entertainment CenterRaspberry PiLinuxOdroid U3Odroid C1

  5. Hello Pelican, Good Bye WordPress

    tags: Blog