diff --git a/vhsdecode/nonlinear_filter.py b/vhsdecode/nonlinear_filter.py index 9278d29e4..97640473a 100644 --- a/vhsdecode/nonlinear_filter.py +++ b/vhsdecode/nonlinear_filter.py @@ -72,14 +72,14 @@ def sub_deemphasis_inner( # Get the instantaneous amplitude of the signal using the hilbert transform # and divide by the formats specified deviation so we get a amplitude compared to the specifications references. amplitude = abs(sps.hilbert(hf_part)) / deviation - amplitude = filter_simple(amplitude, filters["NLAmplitudeLPF"]) - + # Clip the value after filtering to make sure we don't go negative + amplitude = np.clip(filter_simple(amplitude, filters["NLAmplitudeLPF"]), 0, None) if debug_const_amplitude: amplitude = debug_const_amplitude if linear_scale_1 is not None: amplitude *= linear_scale_1 - # Scale the amplitude by a exponential factore (typically less than 1 so it ends up being a root function of osrts) + # Scale the amplitude by a exponential factore (typically less than 1 so it ends up being a root function of sorts) amplitude = np.power(amplitude, exponential_scale) if linear_scale_2 is not None: amplitude *= linear_scale_2 diff --git a/vhsdecode/process.py b/vhsdecode/process.py index 32b5b68ca..3b5e78fd5 100644 --- a/vhsdecode/process.py +++ b/vhsdecode/process.py @@ -1121,7 +1121,7 @@ def demodblock( # on sharp transitions. Using filtfilt to avoid phase issues. if len(np.where(env == 0)[0]) == 0: # checks for zeroes on env if self._high_boost is not None: - data_filtered = npfft.ifft(indata_fft) + data_filtered = npfft.ifft(indata_fft).real high_part = utils.filter_simple( data_filtered, self.Filters["RFTop"] ) * ((env_mean * 0.9) / env) diff --git a/vhsdecode/utils.py b/vhsdecode/utils.py index 5c3e42652..05a708b2f 100644 --- a/vhsdecode/utils.py +++ b/vhsdecode/utils.py @@ -18,7 +18,7 @@ def gen_compl_wave_at_frequency(frequency, sample_frequency, num_samples): def filter_simple(data, filter_coeffs): - return signal.sosfiltfilt(filter_coeffs, data, padlen=150) + return signal.sosfiltfilt(filter_coeffs, data, padlen=70) @njit(cache=True)