Skip to content

fix(fourier): correct lsft_fast phase and amplitude - #989

Open
Cherith1222 wants to merge 3 commits into
StingraySoftware:mainfrom
Cherith1222:fix/988-lsft-fast
Open

Cherith1222 wants to merge 3 commits into
StingraySoftware:mainfrom
Cherith1222:fix/988-lsft-fast

Conversation

@Cherith1222

Copy link
Copy Markdown

Why

lsft_fast bound the cosine sum where the sine sum belongs, and it counted frequency bins where the slow transform counts observations. A 300-point series on a 200-bin grid returned a NaN in the first bin. The phase error stayed near pi when oversampling increased.

What changed

  • Bind the sine sum from trig_sum before arctan2.
  • Use the observation count in the amplitude scale and in the cosine and sine variance terms.

Scope

This covers the two formula errors in the reported random-time example. It leaves the exact-Nyquist guard alone, and it leaves the default oversampling at 5. The report says that threshold is not chosen yet. There is no new dependency.

Blast Radius

Callers of the fast transform, including the fast Lomb-Scargle cross spectrum, receive a different complex result. The slow method is unchanged. The existing fast-versus-slow cross-spectrum check still passes.

Verification

  • Before the change, the reported script printed nan_bins=1 and amp_rel_err=1.827e+00 at oversampling 5, 10, and 50.
  • After the change, the same script printed nan_bins=0 and relative errors 3.689e-02, 3.735e-03, and 6.298e-07.
  • pytest on the new test, test_lsft_slow_fast, test_impose_symmetry_lsft, and TestLombScargleCrossspectrum::test_valid_method passed (4).

See #988. This patch does not close the Nyquist follow-up in that report.

Drafted with Cursor.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant