From 69a5b8a286afb4ef46770eb79d8e1452eefa6e6e Mon Sep 17 00:00:00 2001 From: Chad Date: Sat, 9 Nov 2024 10:44:54 -0800 Subject: [PATCH] Apply Novgorod's supergauss filter. gets rid of the delay buffer flush in the he010 testdata --- lddecode/core.py | 3 ++- lddecode/utils.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lddecode/core.py b/lddecode/core.py index 1c92c6342..8e2991629 100644 --- a/lddecode/core.py +++ b/lddecode/core.py @@ -27,7 +27,7 @@ from .utils import LRUupdate, clb_findbursts, angular_mean_helper, phase_distance from .utils import build_hilbert, unwrap_hilbert, emphasis_iir, filtfft from .utils import fft_do_slice, fft_determine_slices, StridedCollector, hz_to_output_array -from .utils import Pulse, nb_std, nb_gt, n_ornotrange, nb_concatenate +from .utils import Pulse, nb_std, nb_gt, n_ornotrange, nb_concatenate, gen_bpf_supergauss try: # If Anaconda's numpy is installed, mkl will use all threads for fft etc @@ -446,6 +446,7 @@ def computeefmfilter(self): ) self.Filters["Fefm"] = coeffs * 8 + self.Filters["Fefm"] *= gen_bpf_supergauss(20000, 1600000, 60, 20000000, 32768) # Lambda-scale functions used to simplify following filter builders diff --git a/lddecode/utils.py b/lddecode/utils.py index 40bc3673b..70c2c85d3 100644 --- a/lddecode/utils.py +++ b/lddecode/utils.py @@ -691,6 +691,27 @@ def calczc(data, _start_offset, target, edge=0, count=10, reverse=False): return calczc_do(data, _start_offset, target, edge, count) +# copied from vhs-decode + +def gen_bpf_supergauss(freq_low, freq_high, order, nyquist_hz, block_len): + sg = supergauss( + np.linspace(0, nyquist_hz, block_len // 2 + 1), + freq_high - freq_low, + order, + (freq_high + freq_low) / 2.0, + )[:-1] + + return np.concatenate([sg, np.flip(sg)]) + +def supergauss(x, freq, order=1, centerfreq=0): + return np.exp( + -2 + * np.power( + (2 * (x - centerfreq) * (math.log(2.0) / 2.0) ** (1 / (2 * order))) / freq, + 2 * order, + ) + ) + # Shamelessly based on https://github.com/scipy/scipy/blob/v1.6.0/scipy/signal/signaltools.py#L2264-2267 # ... and intended for real FFT, but seems fine with complex as well ;) def build_hilbert(fft_size):