rtlsdr_nbfm.lua

This example is a Narrowband FM radio receiver. It can be used to listen to NOAA weather radio in the US, amateur radio operators, analog police and emergency services, and more, on the VHF and UHF bands. It uses the RTL-SDR as an SDR source, plays audio with PulseAudio, and shows two real-time plots: the RF spectrum and the demodulated audio spectrum.

This NBFM demodulator composition is available in LuaRadio as the NBFMDemodulator block.

Flow Graph

Source
local radio = require('radio')

if #arg < 1 then
    io.stderr:write("Usage: " .. arg[0] .. " <frequency>\n")
    os.exit(1)
end

local frequency = tonumber(arg[1])
local tune_offset = -100e3
local deviation = 5e3
local bandwidth = 4e3

-- Blocks
local source = radio.RtlSdrSource(frequency + tune_offset, 1102500)
local tuner = radio.TunerBlock(tune_offset, 2*(deviation+bandwidth), 50)
local fm_demod = radio.FrequencyDiscriminatorBlock(deviation/bandwidth)
local af_filter = radio.LowpassFilterBlock(128, bandwidth)
local sink = os.getenv('DISPLAY') and radio.PulseAudioSink(1) or radio.WAVFileSink('nbfm.wav', 1)

-- Plotting sinks
local plot1 = radio.GnuplotSpectrumSink(2048, 'RF Spectrum', {yrange = {-120, -40}})
local plot2 = radio.GnuplotSpectrumSink(2048, 'AF Spectrum', {yrange = {-120, -40},
                                                              xrange = {0, bandwidth},
                                                              update_time = 0.05})

-- Connections
local top = radio.CompositeBlock()
top:connect(source, tuner, fm_demod, af_filter, sink)
if os.getenv('DISPLAY') then
    top:connect(tuner, plot1)
    top:connect(af_filter, plot2)
end

top:run()
Usage
Usage: examples/rtlsdr_nbfm.lua <frequency>

Running this example in a headless environment will inhibit plotting and record audio to the WAV file nbfm.wav.

Usage Example

Listen to NOAA1, 162.400 MHz:

$ ./luaradio examples/rtlsdr_nbfm.lua 162.400e6

Additional NOAA weather radio station frequencies: 162.400 MHz (NOAA1), 162.425 MHz (NOAA2), 162.450 MHz (NOAA3), 162.475 MHz (NOAA4), 162.500 MHz (NOAA5), 162.525 MHz (NOAA6), 162.550 MHz (NOAA7).