Skip to content

Commit 867849b

Browse files
committed
[bug fix] throw warning if no channel labels for connectivity_features
1 parent a279ddd commit 867849b

File tree

3 files changed

+63
-45
lines changed

3 files changed

+63
-45
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ in the git logs.
77
### Changed
88
### Removed
99
### Fixed
10+
- Bug fix for `connectivity_features`; was: if channel labels (cell of strings) are empty
11+
then would assume (incorrectly) only 2 channels and would use index [1,2] for left,right
12+
hemisphere; now: if no channel labels throw warning
1013
### Added
14+
- Check in `spectral_features`: is `L_window` longer than signal (and if so throw
15+
warning)?
16+
17+
1118

1219

1320
## [0.4.3] - 2020-04-22

connectivity_features/connectivity_features.m

+8-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
% John M. O' Toole, University College Cork
4141
% Started: 13-04-2016
4242
%
43-
% last update: Time-stamp: <2019-01-09 15:58:25 (otoolej)>
43+
% last update: Time-stamp: <2020-08-17 16:49:56 (otoolej)>
4444
%-------------------------------------------------------------------------------
4545
function featx = connectivity_features(x, Fs, feat_name, params_st, ch_labels)
4646
if(nargin<2), error('need 2 input arguments'); end
@@ -76,17 +76,18 @@
7676
N_freq_bands = 1;
7777
end
7878

79-
80-
if(N_channels>2 && ~isempty(ch_labels))
79+
if(~isempty(ch_labels))
80+
% find left and right channels:
8181
[ileft, iright] = channel_hemispheres(ch_labels);
8282
ipairs = channel_hemisphere_pairs(ch_labels);
83-
elseif(N_channels == 2)
84-
% if no channel labels then guess:
85-
ileft = 1; iright = 2;
86-
ipairs = [1 2]';
83+
else
84+
warning('REQUIRED: channel names for coherence function.');
85+
featx = NaN;
86+
return;
8787
end
8888

8989

90+
9091
switch feat_name
9192
case 'connectivity_BSI'
9293
%---------------------------------------------------------------------

spectral_features/spectral_features.m

+48-38
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
% John M. O' Toole, University College Cork
2727
% Started: 07-04-2016
2828
%
29-
% last update: Time-stamp: <2020-04-22 17:27:24 (otoolej)>
29+
% last update: Time-stamp: <2020-08-17 16:53:32 (otoolej)>
3030
%-------------------------------------------------------------------------------
3131
function featx=spectral_features(x,Fs,feat_name,params_st)
3232
if(nargin<2), error('need 2 input arguments'); end
@@ -48,50 +48,57 @@
4848
total_freq_bands=params_st.total_freq_bands;
4949

5050

51+
if(length(x) < (params_st.L_window * Fs))
52+
warning('SPECTRAL features: signal length < window length; set shorter L_window');
53+
warning('SPECTRAL features: not calculating spectral features.');
54+
featx = NaN;
55+
return;
56+
end
57+
5158

5259
switch feat_name
5360
case {'spectral_power','spectral_relative_power'}
54-
%---------------------------------------------------------------------
55-
% use periodogram to estimate spectral power
56-
%---------------------------------------------------------------------
57-
params_st.method='periodogram';
58-
[pxx,itotal_bandpass,f_scale,N,fp]=gen_spectrum(x,Fs,params_st,1);
59-
pxx=pxx.*Fs;
60-
61-
Nh=length(pxx);
62-
63-
if(DBplot)
64-
figure(1); clf; hold all;
65-
plot(fp,20*log10(pxx));
66-
end
67-
68-
if(strcmp(feat_name,'spectral_relative_power'))
69-
pxx_total=sum( pxx(itotal_bandpass) )/N;
61+
%---------------------------------------------------------------------
62+
% use periodogram to estimate spectral power
63+
%---------------------------------------------------------------------
64+
params_st.method='periodogram';
65+
[pxx,itotal_bandpass,f_scale,N,fp]=gen_spectrum(x,Fs,params_st,1);
66+
pxx=pxx.*Fs;
67+
68+
Nh=length(pxx);
69+
70+
if(DBplot)
71+
figure(1); clf; hold all;
72+
plot(fp,20*log10(pxx));
73+
end
74+
75+
if(strcmp(feat_name,'spectral_relative_power'))
76+
pxx_total=sum( pxx(itotal_bandpass) )/N;
77+
else
78+
pxx_total=1;
79+
end
80+
81+
spec_pow=NaN(1,size(freq_bands,1));
82+
83+
for p=1:size(freq_bands,1)
84+
if(p==1)
85+
istart=ceil(freq_bands(p,1)*f_scale);
7086
else
71-
pxx_total=1;
87+
istart=ibandpass(end)-1;
7288
end
89+
ibandpass=istart:floor(freq_bands(p,2)*f_scale);
90+
ibandpass=ibandpass+1;
91+
ibandpass(ibandpass<1)=1; ibandpass(ibandpass>Nh)=Nh;
7392

74-
spec_pow=NaN(1,size(freq_bands,1));
75-
76-
for p=1:size(freq_bands,1)
77-
if(p==1)
78-
istart=ceil(freq_bands(p,1)*f_scale);
79-
else
80-
istart=ibandpass(end)-1;
81-
end
82-
ibandpass=istart:floor(freq_bands(p,2)*f_scale);
83-
ibandpass=ibandpass+1;
84-
ibandpass(ibandpass<1)=1; ibandpass(ibandpass>Nh)=Nh;
85-
86-
spec_pow(p)=sum( pxx(ibandpass) )/(N*pxx_total);
87-
88-
if(DBplot)
89-
line([fp(ibandpass(1)) fp(ibandpass(1))],ylim,'color','k');
90-
line([fp(ibandpass(end)) fp(ibandpass(end))],ylim,'color','k');
91-
end
92-
end
93-
featx=spec_pow;
93+
spec_pow(p)=sum( pxx(ibandpass) )/(N*pxx_total);
9494

95+
if(DBplot)
96+
line([fp(ibandpass(1)) fp(ibandpass(1))],ylim,'color','k');
97+
line([fp(ibandpass(end)) fp(ibandpass(end))],ylim,'color','k');
98+
end
99+
end
100+
featx=spec_pow;
101+
95102

96103
case 'spectral_flatness'
97104
%---------------------------------------------------------------------
@@ -225,3 +232,6 @@
225232

226233

227234

235+
236+
end
237+

0 commit comments

Comments
 (0)