Skip to content

Commit

Permalink
fix: correct bias in Hilbert trans when padding
Browse files Browse the repository at this point in the history
  • Loading branch information
nicrie committed Jul 10, 2023
1 parent 00ac5b3 commit c0183df
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions xeofs/utils/xarray_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def hilbert_transform(data: DataArray, dim, padding='exp', decay_factor=.2) -> D
return xr.apply_ufunc(
_hilbert_transform_with_padding,
data,
input_core_dims=[['sample']],
output_core_dims=[['sample']],
input_core_dims=[['sample', 'feature']],
output_core_dims=[['sample', 'feature']],
kwargs={'padding': padding, 'decay_factor': decay_factor},
dask='parallelized',
dask_gufunc_kwargs={'allow_rechunk': True}
Expand Down Expand Up @@ -204,6 +204,10 @@ def _hilbert_transform_with_padding(y, padding='exp', decay_factor=.2):
if padding == 'exp':
y = y[n_samples:2*n_samples]

# Padding can introduce a shift in the mean of the imaginary part
# of the Hilbert transform. Correct for this shift.
y = y - y.mean(axis=0)

return y

def _pad_exp(y, decay_factor=.2):
Expand Down

0 comments on commit c0183df

Please sign in to comment.