Simplification and removal of workarounds after re-work of ImaGIN_BipolarMontage
Showing
1 changed file
with
15 additions
and
44 deletions
@@ -17,66 +17,33 @@ function ImaGIN_SpikesDetection(S) | @@ -17,66 +17,33 @@ function ImaGIN_SpikesDetection(S) | ||
17 | bp_stimulation_obj = ImaGIN_BipolarMontage(Sbp); | 17 | bp_stimulation_obj = ImaGIN_BipolarMontage(Sbp); |
18 | clear channels_map; | 18 | clear channels_map; |
19 | for cc=1:nchannels(bp_stimulation_obj) | 19 | for cc=1:nchannels(bp_stimulation_obj) |
20 | - bipolar_chan = chanlabels(bp_stimulation_obj,cc); | 20 | + bipolar_chan = chanlabels(bp_stimulation_obj,cc); |
21 | mono_chans = regexp(bipolar_chan,'-','split'); | 21 | mono_chans = regexp(bipolar_chan,'-','split'); |
22 | channels_map(cc).bp_chan = bipolar_chan; | 22 | channels_map(cc).bp_chan = bipolar_chan; |
23 | channels_map(cc).bp_idx = cc; | 23 | channels_map(cc).bp_idx = cc; |
24 | channels_map(cc).mono_chan1 = mono_chans{1}{1}; | 24 | channels_map(cc).mono_chan1 = mono_chans{1}{1}; |
25 | channels_map(cc).mono_chan2 = mono_chans{1}{2}; | 25 | channels_map(cc).mono_chan2 = mono_chans{1}{2}; |
26 | - | ||
27 | - % Test if the channel label exists in the monopolar object, if not, add a '0' and try again. | ||
28 | - %chan1_idx = indchannel(mono_stimulation_obj,mono_chans{1}{1}); | ||
29 | - chan1_idx = find(strcmp(monopolar_sensors.label,mono_chans{1}{1})); | ||
30 | - if numel(chan1_idx) == 0 | ||
31 | - old_name = mono_chans{1}{1}; | ||
32 | - match = regexp(old_name,'^(?<label>.*?)(?<index>[0-9]+)$','once','names'); | ||
33 | - new_name = [match.label '0' match.index]; | ||
34 | - channels_map(cc).mono_chan1 = new_name; | ||
35 | - %chan1_idx = indchannel(mono_stimulation_obj,new_name); | ||
36 | - chan1_idx = find(strcmp(monopolar_sensors.label,new_name)); | ||
37 | - end | ||
38 | - %chan2_idx = indchannel(mono_stimulation_obj,mono_chans{1}{2}); | ||
39 | - chan2_idx = find(strcmp(monopolar_sensors.label,mono_chans{1}{2})); | ||
40 | - if numel(chan2_idx) == 0 | ||
41 | - old_name = mono_chans{1}{2}; | ||
42 | - match = regexp(old_name,'^(?<label>.*?)(?<index>[0-9]+)$','once','names'); | ||
43 | - new_name = [match.label '0' match.index]; | ||
44 | - channels_map(cc).mono_chan2 = new_name; | ||
45 | - %chan2_idx = indchannel(mono_stimulation_obj,new_name); | ||
46 | - chan2_idx = find(strcmp(monopolar_sensors.label,new_name)); | ||
47 | - end | ||
48 | - | 26 | + % Get the monopolar channels idxes. |
27 | + chan1_idx = find(strcmp(monopolar_sensors.label,mono_chans{1}{1})); | ||
28 | + chan2_idx = find(strcmp(monopolar_sensors.label,mono_chans{1}{2})); | ||
49 | % Test and correct for duplicated labels in the monopolar object | 29 | % Test and correct for duplicated labels in the monopolar object |
50 | - if numel(chan1_idx) == 0 % Could not find the monopolar label | 30 | + if numel(chan1_idx) == 0 |
51 | error('Could not find the monopolar channel from the bipolar montage.'); | 31 | error('Could not find the monopolar channel from the bipolar montage.'); |
52 | elseif numel(chan1_idx) == 1 % If 1 match, as expected, do nothing | 32 | elseif numel(chan1_idx) == 1 % If 1 match, as expected, do nothing |
53 | - %pass | ||
54 | - elseif numel(chan1_idx) == 2 % If 2 matches, find and eliminate the channel without coordinates AND flagged as badchannel (scalp measurement) | ||
55 | - chan1_matching = [sum(badchannels(mono_stimulation_obj) == chan1_idx(1)) == 1 & sum(isnan(monopolar_sensors.elecpos(chan1_idx(1),:))) == 3,... | ||
56 | - sum(badchannels(mono_stimulation_obj) == chan1_idx(2)) == 1 & sum(isnan(monopolar_sensors.elecpos(chan1_idx(2),:))) == 3]; % [0,1] or [1,0] | ||
57 | - chan1_idx = chan1_idx(~chan1_matching(:)); | 33 | + %pass |
58 | else | 34 | else |
59 | - error('3 or more channels with the same label') | 35 | + error('2 or more channels with the same label') |
60 | end | 36 | end |
61 | % Same logic as for chan1_idx | 37 | % Same logic as for chan1_idx |
62 | if numel(chan2_idx) == 0 | 38 | if numel(chan2_idx) == 0 |
63 | error('Could not find the monopolar channel from the bipolar montage.'); | 39 | error('Could not find the monopolar channel from the bipolar montage.'); |
64 | elseif numel(chan2_idx) == 1 | 40 | elseif numel(chan2_idx) == 1 |
65 | - %pass | ||
66 | - elseif numel(chan2_idx) == 2 | ||
67 | - chan2_matching = [sum(badchannels(mono_stimulation_obj) == chan2_idx(1)) == 1 & sum(isnan(monopolar_sensors.elecpos(chan2_idx(1),:))) == 3,... | ||
68 | - sum(badchannels(mono_stimulation_obj) == chan2_idx(2)) == 1 & sum(isnan(monopolar_sensors.elecpos(chan2_idx(2),:))) == 3]; | ||
69 | - chan2_idx = chan2_idx(~chan2_matching(:)); | 41 | + %pass |
70 | else | 42 | else |
71 | - error('3 or more channels with the same label') | ||
72 | - end | ||
73 | - | ||
74 | - if (chan2_idx - chan1_idx) ~= 1 | ||
75 | - error('Found non-consecutive channels.') | ||
76 | - else | ||
77 | - channels_map(cc).mono_idx1 = chan1_idx; | ||
78 | - channels_map(cc).mono_idx2 = chan2_idx; | 43 | + error('2 or more channels with the same label') |
79 | end | 44 | end |
45 | + channels_map(cc).mono_idx1 = chan1_idx; | ||
46 | + channels_map(cc).mono_idx2 = chan2_idx; | ||
80 | end | 47 | end |
81 | clear mono_stimulation_obj bp_stimulation_obj monopolar_sensors; | 48 | clear mono_stimulation_obj bp_stimulation_obj monopolar_sensors; |
82 | 49 | ||
@@ -107,6 +74,10 @@ function ImaGIN_SpikesDetection(S) | @@ -107,6 +74,10 @@ function ImaGIN_SpikesDetection(S) | ||
107 | time_axis = time(D); | 74 | time_axis = time(D); |
108 | onset = timeonset(D); | 75 | onset = timeonset(D); |
109 | negative_time_idxes = find(time_axis > onset+1 & time_axis < -1); % Arbitrary time margins of 1 s around prestimulus period | 76 | negative_time_idxes = find(time_axis > onset+1 & time_axis < -1); % Arbitrary time margins of 1 s around prestimulus period |
77 | + | ||
78 | + disp(size(D)); | ||
79 | + disp(stims_files{ff}); | ||
80 | + | ||
110 | file_baselines = D(:,negative_time_idxes,1); | 81 | file_baselines = D(:,negative_time_idxes,1); |
111 | file_baselines(all_bad_channels_idxes,:,1) = zeros(numel(all_bad_channels_idxes),numel(negative_time_idxes)); | 82 | file_baselines(all_bad_channels_idxes,:,1) = zeros(numel(all_bad_channels_idxes),numel(negative_time_idxes)); |
112 | concat_baselines = [concat_baselines file_baselines]; | 83 | concat_baselines = [concat_baselines file_baselines]; |
-
Please register or login to post a comment