GEDAI v1.8 (option to set recording reference) - #24
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
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
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.
| % 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 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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]