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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
"""
Type stubs for the orion-sdr native extension module.
All classes live in the flat ``orion_sdr`` namespace. IQ arrays use
``numpy.complex64``; audio arrays use ``numpy.float32``; bit arrays use
``numpy.uint8`` (one bit per byte, value 0 or 1). Every ``process()``
call returns a new 1-D array; arrays must be 1-D and C-contiguous, or a
``ValueError`` is raised.
"""
# ---------------------------------------------------------------------------
# Demodulators (IQ complex64 → audio float32)
# ---------------------------------------------------------------------------
"""One-pole envelope detector for CW signals.
Tracks the instantaneous magnitude of the IQ input with a low-pass
time constant derived from *env_bw_hz*. *tone_hz* is accepted for
API symmetry but is not used internally (pre-tune the signal before
passing it in).
"""
...
...
...
"""AM envelope demodulator with 4th-order IIR low-pass and DC blocker.
Two envelope methods are available:
* ``abs_approx=False`` (default) — ``sqrt(I² + Q²)`` after the LP filter
(*PowerSqrt*); highest fidelity.
* ``abs_approx=True`` — ``k1·|I| + k2·|Q|`` approximation (*AbsApprox*,
k1=0.9482, k2=0.3920); slightly faster with a small amplitude error.
"""
...
...
"""SSB product detector with BFO rotator and 4th-order IIR audio filter.
Set *bfo_hz* to 0 for a signal already tuned to baseband, or to a small
offset to shift the recovered audio pitch.
"""
...
...
"""FM quadrature (phase-difference) discriminator.
Output is scaled so that ±*dev_hz* of instantaneous frequency deviation
maps to roughly ±1.0. A 4th-order IIR low-pass at *audio_bw_hz* follows
the discriminator.
"""
...
...
"""PM quadrature demodulator (instantaneous phase difference).
*k* scales the recovered phase difference to the output audio level.
A 4th-order IIR low-pass at *audio_bw_hz* follows the discriminator.
"""
...
...
# ---------------------------------------------------------------------------
# Digital demodulators (IQ complex64 → bits uint8)
# ---------------------------------------------------------------------------
"""BPSK demodulator: hard-decision slicer.
Input: complex64 IQ array, carrier-removed baseband, 1 sample per symbol.
Output: uint8 bit array — one bit (0 or 1) per input symbol.
Decision rule: Re(z) ≥ 0 → 0, Re(z) < 0 → 1.
*gain* scales the soft metric before slicing (use 1.0 for normalized input).
"""
...
...
...
"""QPSK demodulator: hard-decision slicer.
Input: complex64 IQ array, carrier-removed baseband, 1 sample per symbol.
Output: uint8 bit array — two bits per input symbol, interleaved as
``[b0_I, b0_Q, b1_I, b1_Q, …]``. Matches the Gray coding of ``QpskMod``.
*gain* scales the soft metric before slicing (use 1.0 for normalized input).
"""
...
...
...
"""QAM demodulator: hard-decision slicer for square QAM constellations.
*order* must be 16, 64, or 256 (raises ``ValueError`` otherwise).
Input: complex64 IQ array, carrier-removed baseband, 1 sample per symbol.
Output: uint8 bit array — ``log2(order)`` bits per input symbol, laid out
as ``log2(order)/2`` I-axis bits then ``log2(order)/2`` Q-axis bits
(MSB-first within each axis Gray index). Matches ``QamMod`` bit layout.
*gain* scales the soft metric before slicing (use 1.0 for normalized input).
"""
...
...
...
# ---------------------------------------------------------------------------
# Modulators (audio float32 → IQ complex64)
# ---------------------------------------------------------------------------
"""AM double-sideband modulator with optional carrier and RF upconversion.
* *carrier_level* — 1.0 produces full carrier (A3E); 0.0 gives DSB-SC.
* *modulation_index* — values ≤ 1.0 are recommended to avoid
over-modulation.
* *rf_hz* — set to 0.0 for baseband IQ output.
"""
...
...
"""Clamp the modulated envelope to ±1 to prevent over-modulation."""
...
...
"""CW keyed carrier modulator with shaped rise/fall envelope.
The input array is a **keying envelope** in the range 0..1 (not raw
audio): 1.0 = key down, 0.0 = key up. Rise and fall times are
smoothed by one-pole filters with time constants *rise_ms* / *fall_ms*
to suppress key clicks.
"""
...
...
...
"""FM modulator using a phasor-recurrence phase accumulator.
Each sample multiplies a running phasor by ``exp(j·2π·kf·x/fs)``
where ``kf = deviation_hz``. The phasor is renormalized every 1024
samples to prevent amplitude drift. Set *rf_hz* to 0.0 for baseband
output.
"""
...
...
...
...
"""PM modulator: instantaneous phase φ = kp · x[n].
*kp_rad_per_unit* maps ±1.0 audio to ±kp radians of carrier phase.
Set *rf_hz* to 0.0 for baseband output.
"""
...
...
"""Update the phase sensitivity (rad per unit input amplitude)."""
...
...
"""SSB phasing modulator (Weaver-style IIR variant).
Audio is up-converted to *audio_if_hz* via a complex rotator, split
into I and Q paths through matched 4th-order IIR low-pass filters,
then combined to select the desired sideband. Set *usb=True* for
upper sideband, *usb=False* for lower sideband. Set *rf_hz* to 0.0
for baseband IQ output.
"""
...
...
# ---------------------------------------------------------------------------
# Digital modulators (bits uint8 → IQ complex64)
# ---------------------------------------------------------------------------
"""BPSK modulator: Gray-coded constellation mapper + waveform stage.
Input: uint8 bit array (LSB of each byte used), one bit per symbol.
Output: complex64 IQ array of the same length.
Constellation: bit 0 → (+1, 0), bit 1 → (−1, 0).
Set *rf_hz* to 0.0 for baseband output; non-zero upconverts via an
internal ``Rotator`` (phasor recurrence, no per-sample trig).
"""
...
...
...
"""QPSK modulator: Gray-coded constellation mapper + waveform stage.
Input: uint8 bit array (LSB of each byte); consumed in pairs ``[b0, b1]``.
Output: complex64 IQ array of length ``len(bits) // 2``.
Constellation is normalized to unit energy (each axis ±1/√2).
Set *rf_hz* to 0.0 for baseband output.
"""
...
...
...
"""Square QAM modulator: Gray-coded constellation mapper + waveform stage.
*order* must be 16, 64, or 256 (raises ``ValueError`` otherwise).
Input: uint8 bit array (LSB of each byte); consumed ``log2(order)`` bytes
per symbol. Output: complex64 IQ array of length
``len(bits) // log2(order)``.
Constellation is Gray-coded on each axis independently and normalized to
unit average symbol energy. Set *rf_hz* to 0.0 for baseband output.
"""
...
...
...