Skip to content

Align matrix periodograms with the selected sample axis - #93

Open
antonsoo wants to merge 1 commit into
cokelaer:mainfrom
antonsoo:fix/matrix-periodogram-axis
Open

antonsoo wants to merge 1 commit into
cokelaer:mainfrom
antonsoo:fix/matrix-periodogram-axis

Conversation

@antonsoo

Copy link
Copy Markdown

speriodogram accepts matrix input and an axis, but always computes its FFT along axis 0. It also reshapes repeated windows rather than broadcasting one taper along the sample dimension. As a result, column spectra differ from independent calls on each column; row samples can produce the wrong shape or raise during detrending.

Broadcast the selected window along axis, use that sample count for the default FFT length, and retain the mean's reduced dimension for broadcasting. The FFT uses the same selected axis for real and complex input. The existing one-dimensional results, detrending convention and spectral normalization are preserved. The docstring now explains rows, columns and output shape.

For example, speriodogram(np.arange(24).reshape(8, 3).T, axis=1, NFFT=8, detrend=False) should return shape (3, 5), but currently returns (5, 8).

Validation:

  • New tests cover both axes and negative equivalents, three tapers, default/odd/padded FFT lengths, detrending and real/complex matrices. Before: 120 failures and 24 controls pass. After: all 144 pass.
  • The complete project CI pytest command passes: 313 tests, with the same eight pre-existing warnings as the 169-test baseline.
  • On voice/music and stereo recordings, 288 frame-batch configurations are checked against a direct complex-exponential DFT with independently constructed SciPy tapers. All 240 incorrect matrix results are corrected; the 48 already-correct matrix controls remain correct. The maximum absolute spectral error is 2.39e-15. All 288 arrays of separate one-dimensional channel results stay byte-identical, and inputs are preserved.

These checks establish sample-axis and window consistency, without changing the estimator's normalization or claiming an improvement in statistical quality. Python 3.12 on Linux; other platforms are untested.

@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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