Skip to content

GEDAI v1.8 (option to set recording reference) - #24

Merged
neurotuning-personal merged 8 commits into
mainfrom
saman
Sep 25, 2026
Merged

neurotuning-personal merged 8 commits into
mainfrom
saman

Conversation

@neurotuning-personal

Copy link
Copy Markdown
Collaborator

This pull request updates GEDAI to version 1.8 and introduces several improvements to reference channel handling and artifact visualisation. The most important changes are summarized below.

Reference Channel Handling: [Special thanks to Saman Seifpour for spearheading this approach]

  • Enhanced the reference channel selection in the user interface:
    • If the original recording reference is specified in the EEG structure but not present in the channel list, it is now offered as an option in the output reference popup.
    • Added a new text field allowing users to manually specify a custom recording reference channel, which takes precedence over popup selection. [1] [2]

This change centralizes reference mode selection and uses the same logic for internal leadfield generation, data re-referencing, and final output metadata. It validates required reference channels before bad-channel removal, keeps REST/AvgRef consistent after interpolation, and rebuilds artifact data in a common reference space. This prevents mismatched references during two-pass channel rejection and stabilizes custom/precomputed leadfield workflows.
Improve reference handling in GEDAI by detecting flat recording-reference channels and keeping them out of bad-channel rejection, while storing/reporting this in GEDAI metadata and warnings. Add support for external recording references not present in chanlocs by treating them as leadfield-only references (including template leadfield lookup and warped leadfield alignment path updates). Also restore warning state correctly after wavelet processing.

Update pop_GEDAI UI to expose omitted EEG.ref recording references in the reference popup and add a custom reference text field that overrides popup selection.
Update GEDAI leadfield handling so native-reference mode uses dedicated AvgRef and REST paths with the correct gain matrices and precomputed gram matrices, then returns early. In interpolated mode, apply average referencing before interpolation for AvgRef and avoid re-referencing afterward, while keeping existing behavior for other references. This makes reference-specific covariance construction consistent and avoids double-referencing errors.
Updates GEDAI metadata and UI labels from v1.7 to v1.8 in core, plugin, popup GUI, and FieldTrip/Brainstorm wrapper files. Also fixes the long-standing header typo from "Intrument" to "Instrument" and refreshes the plugin release date string to September 2026.
Ensure artifact visualization uses the actual channel and sample masks for the displayed data, preventing stale masks from earlier toolboxes (for example clean_rawdata) from causing mismatches. The fix resets stale sample and cumulative masks when no regional subset is applied, ensures masks match the active data dimensions, and updates the Y-scaling used by vis_artifacts to reflect the cleaned data.
This change enforces a minimum epoch length based on the number of channels to avoid rank-deficient and ill-conditioned operations in dense electrode arrays. Broadband and wavelet-based epoch sizes are now at least large enough for stable processing, while preserving the existing rule-based tuning for lower frequencies.
Adds support for numeric artifact thresholds in command/history strings and plot labels, introduces adaptive flat-channel tolerance based on signal scale, and falls back to average reference when required reference channels are rejected. The wavelet pass now only attempts GPU paths when parallel GPU support is available and restores warning state safely. Leadfield/template loading is centralized and cached to avoid repeated file I/O across reference/template helpers. Also adds `.gitignore` entry for MATLAB autosave (`*.asv`).
This change introduces a `k_channel_multiplier` option to control the minimum epoch length relative to channel count instead of hard-coding a 2x channel minimum. The setting is propagated through the pass-1 and pass-2 GEDAI workflow and used when calculating broadband and wavelet epoch-size bounds to reduce rank-deficiency issues in high-density arrays.
Copilot AI lite review requested due to automatic review settings September 25, 2026 17:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate reference, leadfield, metadata, and visualization issues require fixes.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

GEDAI v1.8 adds configurable recording-reference handling and improves leadfield processing and artifact visualization.

Changes:

  • Adds custom and omitted recording-reference selection.
  • Refactors reference and leadfield processing.
  • Improves visualization validation and version metadata.
File Reviewed changes
pop_GEDAI.m Adds recording-reference UI and popup options.
GEDAI.m Updates reference processing, leadfield handling, visualization, and epoch sizing.
GEDAI.asv Updates backup visualization and version content.
Fieldtrip and Brainstorm wrappers/​process_gedai.m Updates wrapper version metadata.
eegplugin_GEDAI.m Updates plugin version metadata.
auxiliaries/​vis_artifacts.m Validates channel and sample masks.
.gitignore Ignores MATLAB autosave files.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread GEDAI.m
% ignore if leadfield file cannot be loaded
if any(idx==0), error('GEDAI:ElectrodeLabelsNotFound','Electrode labels not found: %s.',strjoin(labels(idx==0),', ')); end
if strcmpi(internal_reference, 'AvgRef')
G_343_av = L.leadfield4GEDAI.Gain - mean(L.leadfield4GEDAI.Gain, 1);
Comment thread GEDAI.m
Comment on lines +1626 to +1627
ref_loc = sanitize_and_fill_chanlocs(struct('labels', spec_warp.external_ref_label));
EEGin_lf.chanlocs(end+1) = ref_loc;
@neurotuning-personal
neurotuning-personal merged commit 22be45d into main Sep 25, 2026
1 check passed
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