Skip to content

Commit

Permalink
Improve signal quality check (#254)
Browse files Browse the repository at this point in the history
* output SCI as a function of time

* Add compatibility if signal processing toolbox is not available

* Fix detect bad channels

* file cleanup

* simplify process: use file instead of custom

* Rename process and first POC for computing CV

* Add POC for continious CV, SCI and power

* Clean code and speed up SCI

* Rename Quality Check

* Clean code.

* dont delete SCI file

* Move to deprecated folder

* Add warning to SCI

* Rename files

* Keep signals event

* add figure

* fix folder
  • Loading branch information
Edouard2laire authored Feb 4, 2025
1 parent b28ee8a commit b570d37
Show file tree
Hide file tree
Showing 3 changed files with 388 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
sProcess.Comment = 'Scalp Coupling Index';
sProcess.Category = 'Custom';
sProcess.SubGroup = {'NIRS', 'Pre-process'};
sProcess.Index = 1201;
sProcess.Index = 0;
sProcess.isSeparator = 0;
sProcess.Description = 'https://github.com/Nirstorm/nirstorm/wiki/Scalp-coupling-index';

Expand Down Expand Up @@ -61,6 +61,9 @@
end

function OutputFiles = Run(sProcess, sInputs)

warning('This process has been deprecated. Use Signal Quality Control instead')

OutputFiles = {};
for iInput=1:length(sInputs)
% Load recordings
Expand Down
33 changes: 15 additions & 18 deletions bst_plugin/preprocessing/process_nst_detect_bad.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@
channel_flags = sData.ChannelFlag;
nirs_flags = strcmpi({channel_def.Channel.Type}, 'NIRS');

signal=sData.F';
nirs_signal=signal(:,nirs_flags);
signal = sData.F';
nirs_signal = signal(:,nirs_flags);

nb_chnnels=size(signal,2);
nb_sample= size(signal,1);
nb_chnnels = size(signal,2);
nb_sample = size(signal,1);


% Remove negative channel
Expand All @@ -282,11 +282,12 @@

% Remove channel with low SCI or power
if options.option_sci.Value
fs = 1 / diff(sData.Time(1:2));
[SCI, power] = process_nst_sci('compute',nirs_signal',channel_def.Channel(nirs_flags), fs);

window_length = 10;
[~, SCI, power] = process_nst_quality_check('compute_SCI', sData.Time, nirs_signal', window_length, channel_def.Channel(nirs_flags));

SCI = SCI *100;
power = power*100;
SCI = median(SCI,2) * 100;
power = median(power,2) * 100;

SCI_threshold = options.sci_threshold.Value{1};
SCI_channels = false(1,nb_chnnels);
Expand Down Expand Up @@ -325,18 +326,14 @@
% Remove channel with high CV
if options.option_coefficient_variation.Value
CV_threshold = options.coefficient_variation.Value{1};
low_cutoff = 1/200;
high_cutoff = 0.1;
order = 2;
fs = 1 / diff(sData.Time(1:2));

[nirs_filtered, transient] = process_nst_iir_filter('Compute',nirs_signal(100:end,:), fs, 'bandpass', low_cutoff, ...
high_cutoff, order, 1);

CV = std(nirs_filtered,1,'omitnan')./mean(nirs_filtered,1).*100;

window_length = 1000;
[~, CV ] = process_nst_quality_check('compute_CV', sData.Time, nirs_signal', window_length);

CV = median(CV,2) * 100;

CV_channels = false(1,nb_chnnels);
CV_channels(nirs_flags) = CV>CV_threshold ;
CV_channels(nirs_flags) = CV > CV_threshold ;

channel_flags(CV_channels) = -1;
criteria(end+1,:)= {'high coeffience variation channels', CV_channels,{}};
Expand Down
Loading

0 comments on commit b570d37

Please sign in to comment.