Skip to content

Commit

Permalink
fix(vhs-decode): avoid negative values in linear_filter, use a bit le…
Browse files Browse the repository at this point in the history
…ss padding in filter_simple, only pass real to filter_simple
  • Loading branch information
oyvindln committed Jan 10, 2025
1 parent 58ac9d1 commit 4c30dea
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions vhsdecode/nonlinear_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vhsdecode/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion vhsdecode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4c30dea

Please sign in to comment.