goldsluice.reference.lowpass

Python mirror of src/lowpass.rs: a zero-phase Butterworth low-pass filter of a trace (a transform: it returns a trace).

This mirror is a *reference*, not in the kernel subset (see “When the kernel cannot be written this way” in PORTING.md): the filter is made with the FFT, so kernel uses numpy, and the Rust kernel uses the rustfft crate. The two agree to rounding, not bit for bit, which is why ATOL is set.

The recipe is the one of goldpan.algorithms.lowpass (the two must give the same numbers; goldsluice never imports goldpan, so it is written out here). For one trace x of n samples, with dt = sample_period_s:

  • pad = min(n - 1, 3 * round(1 / (cutoff_hz * dt)) + 1), where round rounds half to even (Python’s own round, as in goldpan; Rust’s round_ties_even). A tie is realistic: 1 / (cutoff_hz * dt) is 12.5 for 100 kHz and 0.8 us per sample;

  • both ends are extended by pad samples with odd symmetry about the end points (2 * x[0] - x[pad .. 1] in front, 2 * x[n-1] - x[n-2 .. n-1-pad] behind), so that the edges do not ring, giving N = n + 2 * pad samples;

  • the spectrum of the extended trace is multiplied by 1 / (1 + (f / cutoff_hz) ** (2 * order)) (the magnitude response of a Butterworth filter, applied forwards and backwards, so there is no phase shift), f being the frequency of the bin;

  • the result is the middle n samples of the inverse transform.

cutoff_hz (below the Nyquist frequency), order (1 or more) and sample_period_s are the filter’s and the readout’s and have no default. kernel returns a list of n floats (KIND = "trace").

Functions

bad_cases()

Inputs both versions must refuse, with the same message: [(traces, params), ...].

cases()

The standard inputs the parity test runs both versions on: [(traces, params), ...].

goldpan_expected(traces, params)

The same numbers from goldpan's own function (the analysis side): {output: array}.

kernel(trace, cutoff_hz, order, sample_period_s)

problem(n_samples, cutoff_hz, order, ...)

Why the parameters do not fit a trace of n_samples, or None if they do.

goldsluice.reference.lowpass.goldpan_expected(traces, params)[source]

The same numbers from goldpan’s own function (the analysis side): {output: array}.

goldsluice.reference.lowpass.problem(n_samples, cutoff_hz, order, sample_period_s)[source]

Why the parameters do not fit a trace of n_samples, or None if they do.

goldsluice.reference.lowpass.kernel(trace, cutoff_hz, order, sample_period_s)[source]
goldsluice.reference.lowpass.cases()[source]

The standard inputs the parity test runs both versions on: [(traces, params), ...].

goldsluice.reference.lowpass.bad_cases()[source]

Inputs both versions must refuse, with the same message: [(traces, params), ...].