Skip to content

Add frequency-domain coherence estimation with resolution mapping#11

Draft
Copilot wants to merge 12 commits intofeature-freq-domain-shiftsfrom
copilot/implement-frequency-domain-coherence
Draft

Add frequency-domain coherence estimation with resolution mapping#11
Copilot wants to merge 12 commits intofeature-freq-domain-shiftsfrom
copilot/implement-frequency-domain-coherence

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Overview

Implements frequency-domain coherence path alongside existing time-domain modulation for A/B verification. Fixes critical bugs in alpha selection, frequency resolution handling, and bin mapping that caused IndexError crashes and poor performance.

Implementation

New coherence method (coherence_manager.py):

  • compute_coherence_freq_shifted(): Computes coherence via frequency shifts instead of time-domain modulation
  • Transform modes: High-res STFT (configurable nfft) or full-file DFT
  • Interpolation: none (nearest), linear, or 8-point Lagrange on complex bins
  • Frame-start phase correction for STFT windowing

Configuration (default.yaml):

cyclic:
  use_freq_coherence_method: false       # Enable freq-domain
  use_stft_for_freq_coherence: true      # false = DFT
  freq_coherence_nfft: null              # Optional high-res size
  freq_coherence_interpolation: 'lagrange'
  freq_coherence_apply_phase_correction: true

Bug Fixes

1. Alpha ordering mismatch

Time-domain sorts alphas via Modulator.unique_with_relative_tolerance_fast(), freq-domain was using input order. Now both sort identically (correlation: -0.39 → 0.87).

2. Wrong max_bin calculation

DFT was using STFT's delta_f instead of its own, analyzing 3× too much data. Now calculates method-specific delta_f (70% fewer bins for DFT).

3. Alpha=0 exclusion from unstable sort

When 6+ alphas have coherence=1.0 and P_max_cfg=5, numpy's argsort could arbitrarily exclude alpha=0. Now explicitly reserves first slot for alpha=0.

4. Frequency bin resolution mismatch (IndexError)

Coherence computed at high-res (e.g., 2048 FFT → 1025 bins), but beamforming uses low-res (512 FFT → 257 bins). Indexing harmonic_sets[1036] crashed. Now maps via frequency:

freq_hz = k_highres * delta_f_coherence
k_lowres = round(freq_hz / delta_f_beamforming)
if k_lowres < nfft_real_beamforming:
    harmonic_bins_.append(k_lowres)  # Skip out-of-range bins

Test Coverage

27 new tests covering interpolation modes, resolution mapping, alpha selection edge cases, and method equivalence. All 100 tests passing.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 18, 2026 10:11
Co-authored-by: Screeen <20363442+Screeen@users.noreply.github.com>
Co-authored-by: Screeen <20363442+Screeen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add frequency-domain coherence shifts module Implement frequency-domain coherence shifts with interpolation modes Feb 18, 2026
Copilot AI requested a review from Screeen February 18, 2026 10:15
Co-authored-by: Screeen <20363442+Screeen@users.noreply.github.com>
Copilot AI changed the title Implement frequency-domain coherence shifts with interpolation modes Fix spurious warning in coherence manager zero-frequency check Feb 18, 2026
Co-authored-by: Screeen <20363442+Screeen@users.noreply.github.com>
Copilot AI changed the title Fix spurious warning in coherence manager zero-frequency check Enforce zero at first position in modulation sets and add high-res STFT config Feb 18, 2026
Copilot AI and others added 2 commits February 18, 2026 11:28
Co-authored-by: Screeen <20363442+Screeen@users.noreply.github.com>
Co-authored-by: Screeen <20363442+Screeen@users.noreply.github.com>
Copilot AI changed the title Enforce zero at first position in modulation sets and add high-res STFT config Fix alpha ordering mismatch between coherence computation methods Feb 18, 2026
…rison test

Co-authored-by: Screeen <20363442+Screeen@users.noreply.github.com>
Copilot AI changed the title Fix alpha ordering mismatch between coherence computation methods Fix max_bin calculation for DFT coherence method Feb 18, 2026
Copilot stopped work on behalf of Screeen due to an error February 18, 2026 12:58
Co-authored-by: Screeen <20363442+Screeen@users.noreply.github.com>
Copilot AI changed the title Fix max_bin calculation for DFT coherence method Implement frequency-domain coherence with DFT/STFT modes and fix alpha=0 selection Feb 18, 2026
Co-authored-by: Screeen <20363442+Screeen@users.noreply.github.com>
Copilot AI changed the title Implement frequency-domain coherence with DFT/STFT modes and fix alpha=0 selection Add frequency-domain coherence estimation with resolution mapping Feb 18, 2026
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