Signal
rpps.signal ¶
Conditioning: samples to samples, without knowing what signal they carry
filters FIR/IIR design, windows, frequency shifts, the polyphase channelizer, pulse shaping sample sample-rate changes: decimation, interpolation, rational resampling channelize bring one signal of a wider capture to baseband at a few times its width FFTBank many signals of one capture to baseband at once, each at its own width, from one FFT per hop channel the simulated medium between transmitter and receiver: AWGN, offsets, multipath, fading DCBlock, Deemphasis, Conjugate conditioning: DC removal, FM de-emphasis, spectral inversion loops second class: DCBlock and Deemphasis as per-sample loops (the same output; C++ kernels)
Modules:
| Name | Description |
|---|---|
channel |
Channel impairments as stages, to test a receiver against: |
channelize |
|
condition |
Conditioning: DC removal, FM de-emphasis, spectral inversion |
fftbank |
FFTBank: many channels of one capture, each at its own width and rate, from one FFT per hop |
loops |
Conditioning as per-sample loops (second class): the recursions |
channel ¶
Channel impairments as stages, to test a receiver against: signal + rp.signal.channel.AWGN(10) + rp.signal.channel.CFO(300)
Every stage carries its state (noise generator, oscillator phase, fading) in the stream, so the result doesn't depend on how the signal is cut into blocks. Seeds make a run repeatable.
Classes:
| Name | Description |
|---|---|
AWGN |
Additive white gaussian noise at a signal-to-noise ratio |
CFO |
Carrier frequency offset [Hz]: an oscillator whose phase carries across blocks (the centre frequency is not touched) |
PhaseOffset |
Constant phase rotation [rad] |
Gain |
Amplitude gain in dB |
TimingOffset |
Fractional-sample delay (windowed sinc, carried across blocks) |
ClockDrift |
Sample clock error [ppm]: the receiver samples slightly fast (positive) or slow. Rates in Meta are untouched |
Multipath |
Static multipath: a tap at each delay (in samples, whole numbers) with a complex gain |
Fading |
Flat fading by a sum of sinusoids (Jakes): Rayleigh, or Rician with |
AWGN ¶
Bases: Stage
Additive white gaussian noise at a signal-to-noise ratio
Give one of
snr_db: signal power over noise power in the sample bandwidth
esn0_db: symbol energy over noise density: the SNR plus 10*log10(sps) (needs sps on the data)
ebn0_db: bit energy over noise density (needs bits_per_symbol)
power: the signal power the SNR refers to (1.0 for the unit-power constellations). None measures each block
Methods:
| Name | Description |
|---|---|
snr_db |
The SNR [dB] in the sample bandwidth at this sps |
Source code in src/rpps/signal/channel.py
snr_db ¶
The SNR [dB] in the sample bandwidth at this sps
CFO ¶
PhaseOffset ¶
Gain ¶
TimingOffset ¶
Bases: ShiftTime
Fractional-sample delay (windowed sinc, carried across blocks)
Source code in src/rpps/signal/filters/shift.py
ClockDrift ¶
Multipath ¶
Bases: FIR
Static multipath: a tap at each delay (in samples, whole numbers) with a complex gain
Source code in src/rpps/signal/channel.py
channelize ¶
Classes:
| Name | Description |
|---|---|
Channelize |
|
Functions:
| Name | Description |
|---|---|
channelize |
Filter stages that bring a signal to baseband at about |
baseband |
A channel of a whole capture at baseband, in one call: (samples, Fs_out). freq: the channel's centre relative to the |
Channelize ¶
Bases: Stage
channelize as one stage: one channel of the capture to baseband, designed from the stream's sample rate when the
first block arrives (a profile does not know the capture's rate)
narrow = wide + rp.signal.Channelize(freq=-250e3, width=200e3) # Fs out about 3 x 200 kHz
freq: the channel's centre relative to the capture's [Hz]; width: its bandwidth [Hz]
Source code in src/rpps/signal/channelize.py
channelize ¶
Filter stages that bring a signal to baseband at about oversample times its width
Decimates in several stages, each with an anti-alias filter just sharp enough for its own rate, so
a 100 kHz signal in a 100 MS/s capture needs a few short filters rather than one of thousands of taps.
Returns (pipeline, Fs_out, total decimation): block + pipeline. State carries across consecutive blocks of a stream.
Source code in src/rpps/signal/channelize.py
baseband ¶
A channel of a whole capture at baseband, in one call: (samples, Fs_out). freq: the channel's centre relative to the
capture's centre [Hz]; width: its bandwidth [Hz]. The stages of channelize run once over x, flushed, and their group
delay is taken off, so output sample k is the channel at input time k/Fs_out
Source code in src/rpps/signal/channelize.py
condition ¶
Conditioning: DC removal, FM de-emphasis, spectral inversion
Classes:
| Name | Description |
|---|---|
DCBlock |
Removes the DC offset (a one pole high pass: y[n] = x[n] - x[n-1] + r*y[n-1]), an |
Deemphasis |
FM broadcast de-emphasis: a one pole low pass with time constant tau (75 us in the Americas, 50 us elsewhere), an |
Conjugate |
Spectral inversion of a complex signal: x -> conj(x), so a capture whose I and Q were swapped (or taken from the |
DCBlock ¶
Deemphasis ¶
Conjugate ¶
Bases: Stage
Spectral inversion of a complex signal: x -> conj(x), so a capture whose I and Q were swapped (or taken from the lower sideband of a mixer) comes out the right way round. Inverting the spectrum at the symbol level instead is a constellation map ("R090 inverted"); this does it on the samples, before any sync
fftbank ¶
FFTBank: many channels of one capture, each at its own width and rate, from one FFT per hop
bank = rp.signal.FFTBank(Fs, [(mid, width), ...]) # Hz from the capture's centre, Hz wide
for blk in src(16384):
outs = bank.step(blk.data) # [samples at bank.Fs_out[k]] per channel, baseband
outs = bank.flush() # the rest, the end of the stream
Overlap-save on a fixed grid from the start of the stream (so the output does not depend on how the input is cut):
every hop input samples one FFT of n samples (the hop and overlap on each side). Each channel takes only the
bins around its centre, weighted by a smooth mask (flat to guard x width / 2, a raised-cosine skirt transition x
width wide), and an inverse FFT of n / D of them gives its samples decimated by D directly: D the largest power of two
that keeps oversample x width. The bin grid's rounding of the centre is put right with a phase ramp continuous across
hops, so a channel comes out at exactly mid. A signal_profile over twenty channels filters the capture once, where a
shift and decimation per channel (rp.signal.channelize) went over every sample once a channel.
The mask is zero phase (no delay); n is chosen so the skirt spans at least min_bins bins (its impulse response
stays inside the overlap), for the narrowest channel. active in step skips channels nobody reads any more.
Classes:
| Name | Description |
|---|---|
FFTBank |
Channels (mid, width) [Hz] of a capture at Fs: |
FFTBank ¶
Channels (mid, width) [Hz] of a capture at Fs: step(x) -> [baseband samples per channel]. Fs_out[k], D[k]
Methods:
| Name | Description |
|---|---|
step |
Samples in; [baseband samples per channel] out (empty arrays until a hop is in). active: the channels to |
flush |
The end of the stream: the samples still held, zero padded, trimmed to the input's length |
Source code in src/rpps/signal/fftbank.py
step ¶
Samples in; [baseband samples per channel] out (empty arrays until a hop is in). active: the channels to compute (others give empty arrays and lose these samples)
Source code in src/rpps/signal/fftbank.py
flush ¶
The end of the stream: the samples still held, zero padded, trimmed to the input's length
Source code in src/rpps/signal/fftbank.py
loops ¶
Conditioning as per-sample loops (second class): the recursions DCBlock and Deemphasis run sample by sample, in
the C++ kernels when they are built (rpps._native: dc_block, one_pole) and a Python loop otherwise
The first-class stages, rpps.signal.DCBlock and rpps.signal.Deemphasis, are the same recursions as IIR sections run with no loop over the samples (rpps.signal.filters.iir); these give the same output to rounding. They stay as the references the sections are checked against, and for whoever wants the plain loop.
Classes:
| Name | Description |
|---|---|
DCBlock |
Removes the DC offset, a one pole high pass run sample by sample: y[n] = x[n] - x[n-1] + r*y[n-1] |
Deemphasis |
FM broadcast de-emphasis, a one pole low pass with time constant tau run sample by sample: y += a*(x - y) |
DCBlock ¶
rpps.signal.filters ¶
Filters as stages: FIR/IIR design (low_pass, band_pass, remez...), pulse shaping, windows, frequency shifts and a polyphase channelizer: samples + rp.signal.filters.low_pass(401, 3e6, 100e6)
Modules:
| Name | Description |
|---|---|
convert |
Bring filter coefficients from elsewhere into the config format |
convolve |
FFT convolution for long filters |
filter |
|
filters |
|
iir |
IIR filters, with numpy only |
pfb |
|
serial |
Filter definitions, config/filter/ |
shaping |
|
shift |
|
window |
|
convert ¶
Bring filter coefficients from elsewhere into the config format
A definition in config/ never refers to another file; this is how coefficients that live in a file (or in another tool's output) become one. Read a file, get the definition as a dict, or have it written into a config directory:
d = rp.signal.filters.import_fir("taps.txt") # {"base": "fir", "type": "taps", "taps": [...]}
rp.signal.filters.import_fir("lp.f32", dtype="f32", name="my_lp", dest="mine") # writes mine/filter/fir/taps/my_lp.json
rp.signal.filters.import_iir("sections.npy", form="sos", name="my_iir")
rp.add_config_path("mine"); rp.signal.filters.load("fir/taps/my_lp")
Formats: text/CSV, NumPy .npy/.npz, headerless raw binary (GNU Radio file sinks, tofile), numbers in a C/Python/Verilog array
literal, Xilinx .coe. Arrays already in memory (scipy, firdes...) go through fir_def, sos_def, ba_def and zpk_def.
Functions:
| Name | Description |
|---|---|
read_table |
The numbers of a file as a list of 1-D arrays (one per row of text, one for a vector). |
fir_def |
Definition of an FIR with these taps (real, or complex: the imaginary parts go in |
sos_def |
Definition of an IIR from second-order sections, rows [b0 b1 b2 a0 a1 a2] (scipy's |
ba_def |
Definition of an IIR from a transfer function. convention (the sign of the feedback taps |
zpk_def |
Definition of an IIR from zeros, poles and gain (z-plane; complex values are stored as [re, im]) |
import_fir |
The FIR in a file as a config definition (a dict). A text file may wrap the taps over lines. scale multiplies the taps (integer .coe data: 1/32768 for 16 bit). |
import_iir |
The IIR in a file as a config definition. form says what the numbers are: |
read_table ¶
The numbers of a file as a list of 1-D arrays (one per row of text, one for a vector).
fmt: text, npy, npz, raw, source, coe (default from the extension). dtype: for raw files, f16 f32 f64 cf32 cf64 i8t ui8 i16t i32t (pysdrlib's names) or a numpy dtype string. key: the array to take from an .npz
Source code in src/rpps/signal/filters/convert.py
fir_def ¶
Definition of an FIR with these taps (real, or complex: the imaginary parts go in taps_imag). fields: comment, gain, fs...
Source code in src/rpps/signal/filters/convert.py
sos_def ¶
Definition of an IIR from second-order sections, rows [b0 b1 b2 a0 a1 a2] (scipy's sos)
Source code in src/rpps/signal/filters/convert.py
ba_def ¶
Definition of an IIR from a transfer function. convention (the sign of the feedback taps a):
scipy, matlab, gnuradio-new y[n] = sum b[k] x[n-k] - sum a[k] y[n-k] (k >= 1), a[0] = 1
gnuradio (gnuradio-old) y[n] = sum b[k] x[n-k] + sum a[k] y[n-k] (k >= 1); a[0] is ignored (iir_filter_ffd oldstyle=True)
The definition holds the scipy form.
Source code in src/rpps/signal/filters/convert.py
zpk_def ¶
Definition of an IIR from zeros, poles and gain (z-plane; complex values are stored as [re, im])
Source code in src/rpps/signal/filters/convert.py
import_fir ¶
import_fir(path, fmt=None, dtype=None, key=None, scale=1.0, name=None, dest=None, overwrite=False, **fields)
The FIR in a file as a config definition (a dict). A text file may wrap the taps over lines. scale multiplies the taps (integer .coe data: 1/32768 for 16 bit).
name: also write it as config/filter/fir/taps/
Source code in src/rpps/signal/filters/convert.py
import_iir ¶
import_iir(path, form='sos', fmt=None, dtype=None, key=None, convention='scipy', name=None, dest=None, overwrite=False, **fields)
The IIR in a file as a config definition. form says what the numbers are:
sos rows of 6 (b0 b1 b2 a0 a1 a2), one per section
ba two rows or arrays, b then a (see ba_def for convention)
zpk three rows, zeros, poles, then the gain; from an .npz, the arrays z, p, k
A .npz may hold the arrays by name (sos | b, a | z, p, k). name/dest/overwrite as for import_fir (written under filter/iir/
convolve ¶
FFT convolution for long filters
Functions:
| Name | Description |
|---|---|
fft_pays |
Is convolving nx samples with nh taps cheaper by FFT blocks than directly |
convolve |
Convolution of the signal |
correlate |
sum_i x[n + i] conj(t[i]) at every n where the template t fits in x (len(x) - len(t) + 1 values, as |
fft_pays ¶
convolve ¶
Convolution of the signal x with the filter h by overlap-add FFT blocks when that is cheaper than np.convolve
mode: "full" (len(x) + len(h) - 1 samples), "same" (len(x), centred on the full output) or "valid" (len(x) - len(h) + 1, no edges) Real and complex inputs; the result is float32 / complex64 when both inputs are single precision, else double.
Source code in src/rpps/signal/filters/convolve.py
correlate ¶
sum_i x[n + i] conj(t[i]) at every n where the template t fits in x (len(x) - len(t) + 1 values, as np.correlate(x, t, "valid")), by FFT blocks when that is cheaper
Source code in src/rpps/signal/filters/convolve.py
filter ¶
Classes:
| Name | Description |
|---|---|
FIR |
Causal FIR that carries its history across blocks: len(out) == len(in) |
FIR ¶
Bases: Filter
Causal FIR that carries its history across blocks: len(out) == len(in)
Methods:
| Name | Description |
|---|---|
stream |
Filter a block. Returns (output, new history) |
stream
staticmethod
¶
Filter a block. Returns (output, new history)
Source code in src/rpps/signal/filters/filter.py
filters ¶
Classes:
| Name | Description |
|---|---|
ConvFilter |
|
Functions:
| Name | Description |
|---|---|
low_pass |
Windowed-sinc low pass: |
kaiser_window |
A Kaiser window of shape |
kaiser_params |
Taps and beta for a Kaiser-window FIR with |
low_pass_kaiser |
Low pass that meets a specification: stopband |
remez |
Equiripple (Parks-McClellan) FIR: the smallest possible maximum weighted error for |
ConvFilter ¶
low_pass ¶
Windowed-sinc low pass: taps coefficients, cut off at cutoff Hz of sample rate fs (None: normalised, Nyquist is 1)
window: a function of the length, e.g. np.hamming (default), np.blackman, or kaiser_window(beta)
Source code in src/rpps/signal/filters/filters.py
kaiser_window ¶
kaiser_params ¶
Taps and beta for a Kaiser-window FIR with atten_db stopband attenuation and a transition width wide
(a fraction of the sample rate, e.g. 0.05)
Source code in src/rpps/signal/filters/filters.py
low_pass_kaiser ¶
Low pass that meets a specification: stopband atten_db down, the transition (Hz) centred on cutoff
Source code in src/rpps/signal/filters/filters.py
remez ¶
Equiripple (Parks-McClellan) FIR: the smallest possible maximum weighted error for taps coefficients
remez(101, [0, 1000, 1500, 5000], [1, 0], fs=10e3) # low pass: pass 0-1 kHz, stop 1.5 kHz up
bands: band edges in Hz of fs, two per band; desired: one gain per band; weight: one per band (a heavier band gets less ripple);
type: "bandpass", "hilbert" or "differentiator". Needs no scipy
Source code in src/rpps/signal/filters/filters.py
iir ¶
IIR filters, with numpy only
An IIR is a cascade of second-order sections, one row [b0 b1 b2 a0 a1 a2] each:
H(z) = (b0 + b1 z^-1 + b2 z^-2) / (a0 + a1 z^-1 + a2 z^-2)
IIR(sos) filters a stream with them. The design helpers here make the sections from a specification:
butter, cheby1, cheby2, the RBJ biquads, single_pole, and zpk2sos / tf2sos for coefficients from elsewhere.
Frequencies are fractions of the sample rate (0.5 is Nyquist).
Filtering is exact and has no loop over samples (_Cascade): the sections are one state space system, its input cut
into chunks of L samples. Every chunk's zero-state output is one matrix product (the L x L impulse-response matrix), and
so is every chunk's contribution to the state at its end. The states at the chunk starts are an inclusive scan over the
chunks (s_k = A^L s_(k-1) + u_k) in log2(chunks) array passes. The start states' outputs are one more product. Any
block length works, it agrees with the sample-by-sample recursion to rounding (float64 inside), and it needs only
array operations: the form a GPU runs. On the CPU, the C++ kernel (sos_filter, sample by sample, about 5 operations
a sample and section) is 1.3-1.7x faster single-threaded, so it runs when loaded. An IIR has no constant group delay,
so a stream's delay is not changed by it.
Classes:
| Name | Description |
|---|---|
IIR |
Cascade of second-order sections |
RunningMean |
An exponential average that starts at the first sample: m[0] = x[0], m[n] = m[n-1] + alpha (x[n] - m[n-1]), a |
Functions:
| Name | Description |
|---|---|
as_sos |
Sections as a float (n, 6) array normalised to a0 = 1 |
poles |
Every pole of the cascade (a first-order section has one: its unused second pole at the origin is not listed) |
sos2zpk |
(zeros, poles, gain) of a cascade. Zeros at infinity (a section whose b0 is 0) are left out |
zpk2sos |
Sections for a filter of zeros z, poles p and gain k (z-plane, conjugates in pairs). Fewer zeros than poles means delays |
tf2sos |
Sections for the transfer function b(z^-1) / a(z^-1) (coefficients of rising powers of z^-1, as scipy.signal) |
design |
Sections of a Butterworth ("butter") or Chebyshev ("cheby1": ripple_db in the pass band, "cheby2": atten_db in the stop band) filter |
single_pole |
y[n] = alpha x[n] + (1 - alpha) y[n-1]: a leaky integrator / exponential average (0 < alpha <= 1) |
biquad |
One RBJ audio-EQ cookbook biquad. f0: centre/corner as a fraction of the sample rate; q: quality factor; |
IIR ¶
Bases: Filter
Cascade of second-order sections sos (rows [b0 b1 b2 a0 a1 a2]); gain scales the output
The state carries across blocks, so any block length (including 0) works. Real or complex samples: the coefficients are real and act on both parts. Poles must be inside or on the unit circle (an integrator is allowed).
Methods:
| Name | Description |
|---|---|
run |
One-shot (stateless) filtering from zero state |
response |
(f, H): frequency response at n points from 0 to Nyquist (f in cycles per sample) |
Source code in src/rpps/signal/filters/iir.py
run ¶
response ¶
(f, H): frequency response at n points from 0 to Nyquist (f in cycles per sample)
Source code in src/rpps/signal/filters/iir.py
RunningMean ¶
An exponential average that starts at the first sample: m[0] = x[0], m[n] = m[n-1] + alpha (x[n] - m[n-1]), a
single_pole IIR whose state is set from the first sample. run(x, z) -> (m, z); z None until a sample is seen
Source code in src/rpps/signal/filters/iir.py
as_sos ¶
Sections as a float (n, 6) array normalised to a0 = 1
Source code in src/rpps/signal/filters/iir.py
poles ¶
Every pole of the cascade (a first-order section has one: its unused second pole at the origin is not listed)
sos2zpk ¶
(zeros, poles, gain) of a cascade. Zeros at infinity (a section whose b0 is 0) are left out
Source code in src/rpps/signal/filters/iir.py
zpk2sos ¶
Sections for a filter of zeros z, poles p and gain k (z-plane, conjugates in pairs). Fewer zeros than poles means delays
Source code in src/rpps/signal/filters/iir.py
tf2sos ¶
Sections for the transfer function b(z^-1) / a(z^-1) (coefficients of rising powers of z^-1, as scipy.signal)
Source code in src/rpps/signal/filters/iir.py
design ¶
Sections of a Butterworth ("butter") or Chebyshev ("cheby1": ripple_db in the pass band, "cheby2": atten_db in the stop band) filter
cutoff: the edge as a fraction of the sample rate (the -3 dB point of a butter; the ripple edge of cheby1; the stop edge of cheby2), or [low, high] for bandpass and bandstop.
Source code in src/rpps/signal/filters/iir.py
single_pole ¶
y[n] = alpha x[n] + (1 - alpha) y[n-1]: a leaky integrator / exponential average (0 < alpha <= 1)
Source code in src/rpps/signal/filters/iir.py
biquad ¶
One RBJ audio-EQ cookbook biquad. f0: centre/corner as a fraction of the sample rate; q: quality factor; gain_db: for peaking and the shelves
Source code in src/rpps/signal/filters/iir.py
pfb ¶
Classes:
| Name | Description |
|---|---|
Channelizer |
Polyphase filter bank: splits a wideband signal into |
Channelizer ¶
Bases: Stage
Polyphase filter bank: splits a wideband signal into channels equal bands, each at Fs/channels
bands = wide + rp.signal.filters.Channelizer(8) # bands.data is (time, 8); column k is centred on k*Fs/8
one = bands.data[:, 2]
Channel k is centred on k*Fs/channels (channels above half the rate are the negative frequencies). taps_per: prototype filter taps per channel (longer: sharper channels, more delay)
Source code in src/rpps/signal/filters/pfb.py
serial ¶
Filter definitions, config/filter/rp.signal.filters.load("fir/taps/name")), and pulses,
config/pulse/rp.signal.filters.load("pulse/rrc/0p35")): two resources
All frequencies are fractions of the sample rate (0.5 is Nyquist), or Hz with "units": "hz". FIR and shaping filters build their
taps when a stream starts, from its Fs and sps (stage.taps(Fs=..., sps=...) shows them). "gain" scales any of them;
"fs" (optional) is the rate the definition was made for, and warns if the stream differs.
fir "type": "taps" "taps": [...], "taps_imag": [...] (complex), "normalize": "dc" (unity gain at DC)
"type": "windowed" "pass": lowpass | highpass | bandpass | bandstop, "cutoff": f or [low, high], then
"taps": n, "window": name (default np.hamming, as rp.signal.filters.low_pass; "hamming" is the built-in one)
or "transition": width, "atten_db": dB (Kaiser window sized to meet it)
"type": "remez" "taps": n, "bands": [...], "desired": [...], "weight": [...] "response": bandpass (default) | hilbert | differentiator; no scipy
iir numpy only, as second-order sections. No constant group delay, so a stream's `delay` is unchanged. Unstable: rejected.
"type": "sos" "sos": [[b0, b1, b2, a0, a1, a2], ...]
"type": "ba" "b": [...], "a": [...] scipy sign: y[n] = sum(b x) - sum(a[1:] y)
"type": "zpk" "z": [...], "p": [...], "k": gain complex values as [re, im]; fewer zeros than poles = delay
"type": "butter" | "cheby1" | "cheby2"
"order", "pass": as fir, "cutoff": f or [low, high], "ripple_db" (cheby1), "atten_db" (cheby2)
"type": "biquad" "shape": lowpass | highpass | bandpass | notch | allpass | peaking | lowshelf | highshelf,
"f0", "q", "gain_db" (RBJ audio-EQ cookbook)
"type": "single_pole" "alpha": y[n] = alpha x[n] + (1 - alpha) y[n-1]
pulse "type": "rrc" | "rc" "beta": 0.35, "span": 25 (symbols) or "taps": n, "sps": override the stream's
"type": "sinc" | "rect" "taps", "sps" "type": "biphase" Manchester matched filter
window "type": a built-in window name (`Window.s()`), "params": {its arguments}: kaiser/a8 is kaiser(N, a=8).
Plain windows (hann, blackman...) are code, not files; `Window.get` and a design's "window" accept either.
Coefficients that are in a file or another tool go in through rpps.signal.filters.convert, never as a path in a definition.
Classes:
| Name | Description |
|---|---|
Designed |
A FIR defined by a config entry: the taps are made when the stream starts, from its sample rate and symbol rate |
DesignedIIR |
An IIR defined by a config entry: the sections are made when the stream starts (designs in Hz need its sample rate) |
Functions:
| Name | Description |
|---|---|
builtin |
A window function of the code, by name (see |
window |
A window function f(N): a preset ("kaiser/a8"), a built-in ("hann"), inline {"type": "kaiser", "params": {"a": 8}}, or a function |
ls |
List the filter and pulse definitions: {"fir/windowed": [names], "pulse/rrc": [...], "window/kaiser": [...]} |
load |
Load a filter, config/filter/ |
Designed ¶
Bases: FIR
A FIR defined by a config entry: the taps are made when the stream starts, from its sample rate and symbol rate
Methods:
| Name | Description |
|---|---|
taps |
The coefficients for a sample rate and samples per symbol (needed by designs in Hz and by shaping pulses) |
run |
One-shot (stateless) filtering, drops the edges |
Source code in src/rpps/signal/filters/serial.py
DesignedIIR ¶
Bases: Filter
An IIR defined by a config entry: the sections are made when the stream starts (designs in Hz need its sample rate)
Methods:
| Name | Description |
|---|---|
sos |
The sections for a sample rate (needed only by designs in Hz) |
response |
(f, H) from 0 to Nyquist, f in cycles per sample |
run |
One-shot (stateless) filtering from zero state |
Source code in src/rpps/signal/filters/serial.py
builtin ¶
A window function of the code, by name (see Window.s())
Source code in src/rpps/signal/filters/serial.py
window ¶
A window function f(N): a preset ("kaiser/a8"), a built-in ("hann"), inline {"type": "kaiser", "params": {"a": 8}}, or a function
Source code in src/rpps/signal/filters/serial.py
ls ¶
List the filter and pulse definitions: {"fir/windowed": [names], "pulse/rrc": [...], "window/kaiser": [...]}
load ¶
Load a filter, config/filter/load("fir/taps/moving_average_4"), load("pulse/rrc/0p35"). kind: fir | iir | window | pulse.
params: values of the definition's "params" (see rp._config.resolve)
Source code in src/rpps/signal/filters/serial.py
shaping ¶
Classes:
| Name | Description |
|---|---|
ShapingFilter |
|
ShapingRRC |
|
ShapingRC |
|
ShapingHalfSine |
|
ShapingGaussian |
|
ShapingMatRRC |
|
ShapingBiphase |
Matched filter for biphase (Manchester) symbols: first half +1, second half -1 |
Functions:
| Name | Description |
|---|---|
rrc_pulse |
Root-raised-cosine pulse, t in symbols. Handles the t=0 and |t|=1/(4*beta) limits |
rc_pulse |
Raised-cosine pulse, t in symbols. Handles the |t| = 1/(2*beta) limit |
ShapingFilter ¶
ShapingRRC ¶
Bases: ShapingFilter
Root-Raised Cosine shaping taps: number of taps for FIR (None: 25 symbols) sps: samples per symbol (sample width for 0 ISI) beta: roll off factor [0.35, 0 <= beta <= 1] gain: filter gain [1]
Source code in src/rpps/signal/filters/shaping.py
ShapingRC ¶
Bases: ShapingFilter
Raised Cosine shaping taps: number of taps for FIR (None: 25 symbols) sps: samples per symbol (sample width for 0 ISI) beta: roll off factor [0.35, 0 <= beta <= 1] gain: filter gain [1]
Source code in src/rpps/signal/filters/shaping.py
ShapingHalfSine ¶
Bases: ShapingFilter
Half-sine pulse lasting one symbol: sin(pi*n/sps) for n = 0..sps, so the ends are zero and, for an even sps, the centre
is a whole sample (sps + 1 taps, peak gain). On both rails of O-QPSK (staggered by half a symbol) it is MSK
sps: samples per symbol
Source code in src/rpps/signal/filters/shaping.py
ShapingGaussian ¶
Bases: ShapingFilter
Gaussian-filtered rectangle: the frequency pulse of GMSK and GFSK, from a held level of one symbol
sps: samples per symbol. bt: 3 dB bandwidth times the symbol period (BLE 0.5, GSM 0.3). span: symbols the Gaussian covers
The taps sum to sps, so a level held for a symbol comes out as that level: zero-stuff each symbol to sps samples,
then filter, and the shaped signal integrates (rp.wave.FM) to the phase the modulation index asks for
Source code in src/rpps/signal/filters/shaping.py
ShapingMatRRC ¶
Bases: ShapingFilter
Methods:
| Name | Description |
|---|---|
calc_tmat |
N: the sample count at 1 SPS |
pulse_rrc |
tmat: time matrix to generated pulses |
Source code in src/rpps/signal/filters/shaping.py
ShapingBiphase ¶
Bases: ShapingFilter
Matched filter for biphase (Manchester) symbols: first half +1, second half -1
One symbol is meta.isps samples, so this takes sps from Meta when the stream starts.
Source code in src/rpps/signal/filters/shaping.py
rrc_pulse ¶
Root-raised-cosine pulse, t in symbols. Handles the t=0 and |t|=1/(4*beta) limits
Source code in src/rpps/signal/filters/shaping.py
rc_pulse ¶
Raised-cosine pulse, t in symbols. Handles the |t| = 1/(2*beta) limit
Source code in src/rpps/signal/filters/shaping.py
shift ¶
Classes:
| Name | Description |
|---|---|
ShiftFreq |
Shift the spectrum by |
ShiftFreqIdx |
Shift by |
ShiftTime |
Delay by a fraction of a sample (windowed-sinc fractional delay), carrying its history across blocks |
ShiftFreq ¶
ShiftFreqIdx ¶
ShiftTime ¶
Bases: FIR
Delay by a fraction of a sample (windowed-sinc fractional delay), carrying its history across blocks
delay: samples, normally in [0, 1). The filter's own latency is (taps-1)/2 samples
Methods:
| Name | Description |
|---|---|
run |
One-shot (stateless) shift, drops the edges |
Source code in src/rpps/signal/filters/shift.py
window ¶
Classes:
| Name | Description |
|---|---|
Window |
|
Window ¶
Bases: Filter
Methods:
| Name | Description |
|---|---|
step |
Weight each block by the window (one window per block: N, or the block's length) |
s |
Names of the built-in windows (presets are listed by |
get |
The window function |
Source code in src/rpps/signal/filters/window.py
step ¶
Weight each block by the window (one window per block: N, or the block's length)
Source code in src/rpps/signal/filters/window.py
s
staticmethod
¶
get
staticmethod
¶
The window function name: a built-in (see s()), or a preset from config/filter/window ("kaiser/a8")
rpps.signal.filters.impl ¶
Building blocks behind rpps.signal.filters: designer (simple lowpass/highpass prototypes by name: sinc, delta,
exponential...), gaussian (the Gaussian and its FWHM), window (window functions and their properties)
Modules:
| Name | Description |
|---|---|
designer |
|
gaussian |
|
remez |
Parks-McClellan equiripple FIR design (the Remez exchange), numpy only |
window |
Window functions |
designer ¶
gaussian ¶
remez ¶
Parks-McClellan equiripple FIR design (the Remez exchange), numpy only
The amplitude response of a linear-phase FIR is A(w) = Q(w) P(w), P a cosine series of r terms and Q fixed by the type:
type taps symmetry Q h
I odd even 1 h[c +- m] = b[m] / 2
II even even cos(w/2) h[c +- m] = b[m] / 2
III odd odd sin(w) h[c + m] = s[m] / 2, h[c - m] = -s[m] / 2 (Hilbert, differentiator)
IV even odd sin(w/2) as III
with c = (taps - 1) / 2. Dividing the desired response by Q and multiplying the weight by it turns every type into the same weighted approximation of D by P. Each pass of the exchange fits P through r points of the current extremal set with the error alternating in sign, then moves the extremals to the extrema of the weighted error on a dense grid. The error equioscillates at the optimum.
Functions:
| Name | Description |
|---|---|
remez |
Equiripple FIR of |
remez ¶
Equiripple FIR of taps coefficients, optimal in the weighted Chebyshev sense: the maximum error is the smallest possible
bands edges of the bands that count, in Hz of sample rate fs, rising: [0, 1000, 1500, 5000] is two bands. The gaps are don't-care
desired one gain per band (bandpass, hilbert), or one slope per band (differentiator)
weight one weight per band, default all 1. A heavier band is held to a smaller error
type "bandpass" (a filter; the default), "hilbert" or "differentiator" (odd symmetry)
Returns the float64 coefficients. Raises ValueError for an impossible specification and RuntimeError when the exchange does not converge
Source code in src/rpps/signal/filters/impl/remez.py
window ¶
Window functions
Generalized properties - (NB) Noise bandwidth, / Spectral leakage - (SL) Scalloping loss / Amplitude accuracy - (FR) Frequency resolution Ratings, (Best, Good, Fair, Poor) [5,3,1,0]
| Window | NB | SL | FR |
|---|---|---|---|
| Blackman | 5 | 3 | 1 |
| Flattop | 3 | 5 | 0 |
| Gaussian | 1 | 3 | 1 |
| Rectangle | 0 | 0 | 5 |
| Hanning | 3 | 1 | 3 |
| Hamming | 1 | 1 | 3 |
| Kaiser | 3 | 3 | 1 |
rpps.signal.sample ¶
Sample-rate changes as stages: down (decimation), up (interpolation) and re (rational resampling), fractional (any ratio, with a shift fused in); resample_poly and fractional_resample resample an array in one call
Modules:
| Name | Description |
|---|---|
down |
|
fractional |
Resampling by any ratio with a windowed-sinc polyphase filter, and an optional frequency shift fused in front of it |
re |
|
resample |
One-shot rational resampling of an array |
sample |
|
up |
|
down ¶
Classes:
| Name | Description |
|---|---|
Decimate |
Keep every |
FractionalSpline |
|
Functions:
| Name | Description |
|---|---|
interpolate_stream |
Read |
Decimate ¶
Bases: Downsample
Keep every ratioth sample, starting with sample offset. The phase carries across blocks, so any block length works
Methods:
| Name | Description |
|---|---|
run |
One-shot (stateless) decimation |
Source code in src/rpps/signal/sample/down.py
FractionalSpline ¶
Bases: Downsample
kind: "linear", or "cubic" for a smoother result
Methods:
| Name | Description |
|---|---|
run |
One-shot (stateless) resampling |
Source code in src/rpps/signal/sample/down.py
interpolate_stream ¶
Read samples at positions st.pos, st.pos + step, ... by interpolation, carrying the position and the unread
tail in st (SimpleNamespace(tail=None, pos=0.0); for "cubic", pos starts at 1.0). step: input samples per output
sample. kind: "linear", or "cubic" (Catmull-Rom: smoother, needs one sample before and two after)
Source code in src/rpps/signal/sample/down.py
fractional ¶
Resampling by any ratio with a windowed-sinc polyphase filter, and an optional frequency shift fused in front of it
Classes:
| Name | Description |
|---|---|
FractionalPolyphase |
Resample by any ratio (output rate over input rate) with a Kaiser-windowed sinc polyphase filter, and optionally move the spectrum first |
Functions:
| Name | Description |
|---|---|
design_bank |
(phases + 1, taps) table of the interpolation filter: row p is the kernel for a read position p/phases of the way past a sample |
read_python |
The reference for |
fractional_resample |
Resample the array |
FractionalPolyphase ¶
Bases: Sample
Resample by any ratio (output rate over input rate) with a Kaiser-windowed sinc polyphase filter, and optionally move the spectrum first
stage = FractionalPolyphase(10.7622/20) # 20 MS/s to 10.7622 MS/s, anti-aliased
stage = FractionalPolyphase(10.7622/20, cutoff=3.7e6, shift=-0.5e6) # the channel at +0.5 MHz to baseband, then resample
Output m is the input at time m/ratio, with no delay (as resample_poly). The read position and the oscillator phase carry across
blocks, so any block length gives the same stream, and ratio may be changed between blocks (a clock error trim): the position carries
in input samples and the filter stays as designed. Real input gives real output unless a shift is asked for.
output rate / input rate. cutoff: [Hz, at the input rate] edge of the pass band; None: the lower Nyquist, so decimating
does not alias. taps: filter length (even): it sets the transition width. phases: kernels tabulated over one input sample: the read position is rounded to the nearest, so the interpolation error of the position is about 1/(2phases) of a sample (the image it makes is -20log10(pi*bandwidth/phases) dB below the signal). beta: Kaiser window, sets the stop band depth (7: about 70 dB).
shift: [Hz] translation applied before the filter, equal to ShiftFreq(shift) followed by this stage; the centre frequency moves with it.
Methods:
| Name | Description |
|---|---|
bank |
The (phases + 1, taps) table for an input sample rate |
Source code in src/rpps/signal/sample/fractional.py
bank ¶
The (phases + 1, taps) table for an input sample rate Fs
design_bank ¶
(phases + 1, taps) table of the interpolation filter: row p is the kernel for a read position p/phases of the way past a sample
taps: even length (the kernel spans taps/2 samples either side of the read position). cutoff: [cycles per input sample] 0..0.5. Kaiser window, every row normalised to unit gain at DC so a constant keeps its level wherever it is read
Source code in src/rpps/signal/sample/fractional.py
read_python ¶
The reference for native.polyphase_read: output k is buf read at pos + k*step, the nearest of the table's phases. A chunk of outputs at a time
Source code in src/rpps/signal/sample/fractional.py
fractional_resample ¶
Resample the array x (sample rate Fs, which only matters to cutoff and shift, in Hz) by ratio: a one-call FractionalPolyphase
Source code in src/rpps/signal/sample/fractional.py
re ¶
Classes:
| Name | Description |
|---|---|
Resample |
|
Polyphase |
Stateful FIR rational resampler. Output length tracks up/down across blocks |
Resample ¶
Bases: Sample
Rational resampler by up/down taps: anti-image/anti-alias FIR length at the up-sampled rate [20*max(up, down)+1]
Source code in src/rpps/signal/sample/re.py
Polyphase ¶
Bases: Resample
Stateful FIR rational resampler. Output length tracks up/down across blocks
Source code in src/rpps/signal/sample/re.py
resample ¶
One-shot rational resampling of an array
Functions:
| Name | Description |
|---|---|
design |
The filter |
resample_poly |
Resample |
design ¶
The filter resample_poly uses: (taps at the up-sampled rate, gain up included, centre index)
Source code in src/rpps/signal/sample/resample.py
resample_poly ¶
Resample x by the rational factor up/down with a linear-phase FIR low pass and no delay: output m is the input at time m*down/up
Only the outputs that are kept are computed (polyphase). Returns ceil(len(x)*up/down) samples; single precision stays single. window: ("kaiser", beta), a function of the length, or the taps themselves (at the up-sampled rate, odd length)
Source code in src/rpps/signal/sample/resample.py
sample ¶
up ¶
Classes:
| Name | Description |
|---|---|
Interpolate |
Zero stuff by |
Sinc |
Zero stuff and interpolate with a windowed sinc. The filter history carries across blocks |
Interpolate ¶
Bases: Upsample
Zero stuff by ratio and filter with filt (an FIR stage, a pulse shape) in one step: the same output as
Zeros(ratio) + filt, in polyphase form, so the zeros are never multiplied (ratio times less work)
tx = symbols + rp.signal.sample.up.Interpolate(8, rp.signal.filters.load("pulse/rrc/0_35"))
Output sample n*ratio + p is phase p of the taps (taps[p::ratio]) run over the input, so each phase is an ordinary FIR on the input samples, with one history shared by all of them. A flush (the end of the stream) also sends the filter's tail, so the last symbols' pulses are complete.
Source code in src/rpps/signal/sample/up.py
Sinc ¶
Bases: Interpolate
Zero stuff and interpolate with a windowed sinc. The filter history carries across blocks
Methods:
| Name | Description |
|---|---|
run |
One-shot (stateless) interpolation, same length as ratio*samples |
Source code in src/rpps/signal/sample/up.py
run ¶
One-shot (stateless) interpolation, same length as ratio*samples