-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathrtlsdr_nbfm.lua
34 lines (28 loc) · 1.16 KB
/
rtlsdr_nbfm.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()