-
Notifications
You must be signed in to change notification settings - Fork 63
/
ssbdemodulator.lua
41 lines (34 loc) · 1.46 KB
/
ssbdemodulator.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
35
36
37
38
39
40
41
---
-- Demodulate a baseband, single-sideband amplitude modulated complex-valued
-- signal.
--
-- $$ y[n] = \text{SSBDemodulate}(x[n], \text{sideband}, \text{bandwidth}) $$
--
-- @category Demodulation
-- @block SSBDemodulator
-- @tparam string sideband Sideband, choice of "lsb" or "usb".
-- @tparam[opt=3e3] number bandwidth Bandwidth in Hz
--
-- @signature in:ComplexFloat32 > out:Float32
--
-- @usage
-- -- SSB LSB demodulator with 3 kHz bandwidth
-- local demod = radio.SSBDemodulator("lsb", 3e3)
local block = require('radio.core.block')
local types = require('radio.types')
local blocks = require('radio.blocks')
local SSBDemodulator = block.factory("SSBDemodulator", blocks.CompositeBlock)
function SSBDemodulator:instantiate(sideband, bandwidth)
blocks.CompositeBlock.instantiate(self)
assert(sideband, "Missing argument #1 (sideband)")
assert(sideband == "lsb" or sideband == "usb", "Sideband should be 'lsb' or 'usb'")
bandwidth = bandwidth or 3e3
local sb_filter = blocks.ComplexBandpassFilterBlock(129, (sideband == "lsb") and {0, -bandwidth} or {0, bandwidth})
local am_demod = blocks.ComplexToRealBlock()
local af_filter = blocks.LowpassFilterBlock(128, bandwidth)
self:connect(sb_filter, am_demod, af_filter)
self:add_type_signature({block.Input("in", types.ComplexFloat32)}, {block.Output("out", types.Float32)})
self:connect(self, "in", sb_filter, "in")
self:connect(self, "out", af_filter, "out")
end
return SSBDemodulator