Skip to content

Preserve sampling and FFT metadata in WelchPeriodogram - #94

Open
antonsoo wants to merge 1 commit into
cokelaer:mainfrom
antonsoo:fix/welch-sampling-metadata
Open

antonsoo wants to merge 1 commit into
cokelaer:mainfrom
antonsoo:fix/welch-sampling-metadata

Conversation

@antonsoo

Copy link
Copy Markdown

WelchPeriodogram computes its PSD with the supplied sampling rate but constructs the returned Spectrum with sampling 1 and the input length as its FFT length. Its frequency metadata can disagree with the PSD even though the raw Matplotlib result is correct.

For example, a 32 Hz sinusoid sampled at 256 Hz returns a raw peak at 32 Hz while Spectrum.frequencies() labels it 0.125 Hz. Default segment lengths and pad_to can also leave the frequency vector with a different length from the PSD.

Forward the sampling rate and effective FFT length into Spectrum, using Matplotlib's default of 256 when NFFT is omitted and pad_to when specified. PSD computation remains the existing Matplotlib call.

Validation:

  • All 18 new sampling/default/explicit/padded-length regressions fail before and pass afterward.
  • Full project CI pytest command: 187 tests pass after rebuilding the native DPSS extension in this worktree.
  • On piano and voice/music recordings, all 24 returned real-signal frequency grids now match the raw Matplotlib grids and independently calculated FFT bin frequencies. Every raw PSD and all 24 ordinary 1 Hz control outputs remain byte-identical. Input arrays remain unchanged.

The recording check covers real inputs. Linux/Python 3.12 validation; 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