Skip to content

Align ntfperf integration grid#92

Merged
Arcadia-1 merged 1 commit into
Arcadia-1:mainfrom
chenzc24:codex/ntfperf-grid-policy
Jul 8, 2026
Merged

Align ntfperf integration grid#92
Arcadia-1 merged 1 commit into
Arcadia-1:mainfrom
chenzc24:codex/ntfperf-grid-policy

Conversation

@chenzc24

@chenzc24 chenzc24 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add explicit NTF integration grid controls to ntf_analyzer.
  • Keep ntf_analyzer's historical Python grid as the default.
  • Make ntfperf use MATLAB ntfperf.m's grid contract by default: w = (1:N)/N/2, N = 1_000_000.
  • Update oversampling compatibility tests to check the explicit MATLAB grid policy instead of treating ntfperf as a simple alias.

Rationale

This is a grid-policy alignment, not a core algorithm change. Python and MATLAB already use the same integrated squared-magnitude formula:

np = sum(|NTF(w)|^2 in band) / len(w)
snr = -10*log10(np)

The observed mismatch comes from the integration grid:

MATLAB ntfperf: w = (1:N)/N/2, N = 1e6
Python ntf_analyzer: np.linspace(0, 0.5, 2**16)

ntf_analyzer remains the lightweight Python analyzer. ntfperf is the MATLAB-compatible wrapper, so it now defaults to MATLAB's grid while still exposing n_grid for tests and experimentation.

Experiment

Dataset/function cases generated from MATLAB ntfperf.m and Python on the same NTFs:

case Python ntf_analyzer default delta vs MATLAB Python ntfperf MATLAB grid delta vs MATLAB
[1,-1]/[1,0], band [0, 0.5/16] 30.9616429351113 +0.001352172349 30.9602907627623 +2.84e-14
[1,-2,1]/[1,0,0], band [0, 0.5/16] 47.3320195872251 +0.002208366542 47.3298112206832 -2.84e-14
[1,0,1]/[1,0,0], band [0.24, 0.26] 36.7669311709645 -0.003238854921 36.7701700258856 0

Tests

  • uv run --with pytest pytest tests/unit/oversampling/test_matlab_compat_api.py -q
  • uv run --with pytest pytest tests/unit/oversampling/test_noise_shaping_examples.py -q
  • uv run --with pytest pytest tests/unit/oversampling/test_ntf_analyzer.py -q -m "not slow"
  • uv run --with pytest pytest tests/unit/oversampling/test_matlab_compat_api.py tests/unit/oversampling/test_noise_shaping_examples.py tests/unit/oversampling/test_ntf_analyzer.py -q -m "not slow"
  • git diff --check

@Arcadia-1
Arcadia-1 merged commit a3b98bc into Arcadia-1:main Jul 8, 2026
1 check passed
@chenzc24
chenzc24 deleted the codex/ntfperf-grid-policy branch July 9, 2026 06:07
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.

2 participants