Skip to content

[2/3] Fastgraph: Remove SPES artifacts using EMD - #912

Merged
rcassani merged 15 commits into
brainstorm-tools:masterfrom
chinmaychinara91:fastgraph2
Jun 3, 2026
Merged

[2/3] Fastgraph: Remove SPES artifacts using EMD#912
rcassani merged 15 commits into
brainstorm-tools:masterfrom
chinmaychinara91:fastgraph2

Conversation

@chinmaychinara91

@chinmaychinara91 chinmaychinara91 commented Apr 21, 2026

Copy link
Copy Markdown
Member

This PR is the 2nd part required for Fastgraph. It involves cleaning the data for any artifacts.

Prerequisite: Follow steps in PR #911

Remove SPES artifacts

Linked to process_remove_spes_artifacts and it involves removing SPES artifacts and slow drifts using the Empirical Mode Decomposition (EMD) based filtering.

The GUI

image

Inputs

  • Stimulation event: The stimulation event around which to remove the artifacts (here, STIM)
  • EMD cutoff frequency (in Hz): Self explanatory
  • Time to account for artifact (in ms): The duration of the actual stimulation artifact itself, starting at the stimulation event. Used to set the main artifact span inside the interpolation window (here, 5 ms).
  • Time on either side of the artifact to spline with (in ms): How much clean signal to take from before and after that artifact window so the spline has anchor points to interpolate across the bad segment (here, 3 ms).

Steps to use

  1. Follow steps as in PR [1/3] Fastgraph: Customize SPES (Nihon Kohden) #911 .
  2. Drag the loaded stimulation blocks into the Process1 tab. For e.g. SB A13-A14 4 (#1) .
  3. Click on Run > Stimulation > Remove SPES artifacts.
  4. Fill in the values as seen in the GUI figure above. Click Run.

It creates new stimulation block e.g. SB A13-A14 4 (#1)_emd. The results can be seen as under.
Screenshot 2026-04-21 140035

Associated PRs

  1. [1/3] Fastgraph: Customize SPES (Nihon Kohden) #911
  2. [3/3] Fastgraph: Plot Fastgraphs #916

@jcmosher @Nastaranlotfi @yashvakilna

Remove Single-Pulse Electrical Stimulation (SPES) artifacts and slow drifts using Empirical Mode Decomposition (EMD) based filtering.
@chinmaychinara91
chinmaychinara91 marked this pull request as ready for review April 29, 2026 14:10
@chinmaychinara91
chinmaychinara91 marked this pull request as draft April 29, 2026 17:20
@chinmaychinara91
chinmaychinara91 marked this pull request as ready for review May 1, 2026 20:52

@rcassani rcassani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR presents the process process_remove_spes_artifacts to remove artifacts from stimulation, and to remove drift.

There is reason for artifact-removal operations to be in the same process. It would be more versatile to have them in two different process, so Brainstorm users can use them separately.

Comment thread toolbox/process/functions/process_remove_spes_artifacts.m Outdated
Comment thread toolbox/process/functions/process_remove_spes_artifacts.m Outdated

% Convert trigger times to sample indices
stimTimes = DataMat.Events(iStimEvent).times;
[isMatch, stimSamples] = ismembertol(stimTimes, DataMat.Time, 1e-7);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use bst_closest

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done 0f12ef0

Comment thread toolbox/process/functions/process_remove_spes_artifacts.m Outdated
Comment thread toolbox/process/functions/process_remove_spes_artifacts.m Outdated
@chinmaychinara91

chinmaychinara91 commented May 24, 2026

Copy link
Copy Markdown
Member Author

There is reason for artifact-removal operations to be in the same process.

The reason we do stimulation artifact removal before drift correction is to avoid the large transient artifacts that may bias the drift estimate. Hence, we decided to club them in one process here.

It would be more versatile to have them in two different processes, so Brainstorm users can use them separately.

I agree that the two operations are conceptually independent, and separating them into two independent processes would definitely make the workflow more flexible for users. Thank you for the recommendation.

@jcmosher, any more inputs on this ?

Should I go ahead and create two separate processes? While documenting in the tutorial, we can suggest the recommended order for the users when both steps are applied.

@rcassani

Copy link
Copy Markdown
Member

Should I go ahead and create two separate processes? While documenting in the tutorial, we can suggest the recommended order for the users when both steps are applied.

Drift removal with EMD can be applied to any other data, that is the reason to have it separated.
Yes, create two processes.

In the tutorial explain what each process do and that will lead the reasoning about the order in which the processes must be used for that tutorial, not a suggestion. As swapping the order is incorrect way to do it for the data of that tutorial.

@chinmaychinara91
chinmaychinara91 requested a review from rcassani May 25, 2026 18:56
@rcassani
rcassani merged commit adddc0e into brainstorm-tools:master Jun 3, 2026
chinmaychinara91 added a commit to chinmaychinara91/brainstorm3 that referenced this pull request Jun 17, 2026
- Rename processes as per the changes in PR brainstorm-tools#911 and brainstorm-tools#912
- Adding `ODD` and `EVEN` events not part of the tutorial (left at user's discretion with a note added to the tutorial about it). As recommended by @jcmosher.
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