Skip to content

Commit 74cebba

Browse files
authored
Merge pull request #142 from florisvb/make-spectral-freq-cutoff-right-scale
realized one of the params of spectraldiff was scaled oddly
2 parents f2f409d + 35d0e54 commit 74cebba

6 files changed

Lines changed: 64 additions & 54 deletions

File tree

examples/1_basic_tutorial.ipynb

Lines changed: 25 additions & 21 deletions
Large diffs are not rendered by default.

examples/2a_optimizing_parameters_with_dxdt_known.ipynb

Lines changed: 24 additions & 18 deletions
Large diffs are not rendered by default.

examples/2b_optimizing_parameters_with_dxdt_unknown.ipynb

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

pynumdiff/linear_model/_linear_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def spectraldiff(x, dt, params=None, options=None, high_freq_cutoff=None, even_e
263263
:param dict options: (**deprecated**, prefer :code:`even_extension`
264264
and :code:`pad_to_zero_dxdt`) a dictionary consisting of {'even_extension': (bool), 'pad_to_zero_dxdt': (bool)}
265265
:param float high_freq_cutoff: The high frequency cutoff as a multiple of the Nyquist frequency: Should be between 0
266-
and 0.5. Frequencies below this threshold will be kept, and above will be zeroed.
266+
and 1. Frequencies below this threshold will be kept, and above will be zeroed.
267267
:param bool even_extension: if True, extend the data with an even extension so signal starts and ends at the same value.
268268
:param bool pad_to_zero_dxdt: if True, extend the data with extra regions that smoothly force the derivative to
269269
zero before taking FFT.
@@ -310,7 +310,7 @@ def spectraldiff(x, dt, params=None, options=None, high_freq_cutoff=None, even_e
310310
omega = k*2*np.pi/(dt*N) # turn wavenumbers into frequencies in radians/s
311311

312312
# Frequency based smoothing: remove signals with a frequency higher than high_freq_cutoff
313-
discrete_cutoff = int(high_freq_cutoff*N)
313+
discrete_cutoff = int(high_freq_cutoff*N/2) # Nyquist is at N/2 location, and we're cutting off as a fraction of that
314314
omega[discrete_cutoff:N-discrete_cutoff] = 0
315315

316316
# Derivative = 90 deg phase shift

pynumdiff/tests/test_diff_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def iterated_first_order(*args, **kwargs): return first_order(*args, **kwargs)
3434
(lineardiff, {'order':3, 'gamma':5, 'window_size':11, 'solver':'CLARABEL'}), (lineardiff, [3, 5, 11], {'solver':'CLARABEL'}),
3535
(polydiff, {'poly_order':2, 'window_size':3}), (polydiff, [2, 3]),
3636
(savgoldiff, {'poly_order':2, 'window_size':5, 'smoothing_win':5}), (savgoldiff, [2, 5, 5]),
37-
(spectraldiff, {'high_freq_cutoff':0.1}), (spectraldiff, [0.1]),
37+
(spectraldiff, {'high_freq_cutoff':0.2}), (spectraldiff, [0.2]),
3838
(mediandiff, {'window_size':3, 'num_iterations':2}), (mediandiff, [3, 2], {'iterate':True}),
3939
(meandiff, {'window_size':3, 'num_iterations':2}), (meandiff, [3, 2], {'iterate':True}),
4040
(gaussiandiff, {'window_size':5}), (gaussiandiff, [5]),

pynumdiff/tests/test_optimize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def test_savgoldiff():
8383
def test_spectraldiff():
8484
params1, val1 = optimize(spectraldiff, x, dt, dxdt_truth=dxdt_truth, padding='auto')
8585
params2, val2 = optimize(spectraldiff, x, dt, tvgamma=tvgamma, padding='auto')
86-
np.testing.assert_almost_equal(params1['high_freq_cutoff'], 0.0975, decimal=3)
87-
np.testing.assert_almost_equal(params2['high_freq_cutoff'], 0.10, decimal=2)
86+
np.testing.assert_almost_equal(params1['high_freq_cutoff'], 0.105, decimal=2)
87+
np.testing.assert_almost_equal(params2['high_freq_cutoff'], 0.105, decimal=2)
8888

8989
def test_polydiff():
9090
params1, val1 = optimize(polydiff, x, dt, search_space={'step_size':1}, dxdt_truth=dxdt_truth, padding='auto')

0 commit comments

Comments
 (0)