Skip to content

Commit

Permalink
Added warning for relative power with overlapping freq bands
Browse files Browse the repository at this point in the history
  • Loading branch information
ftadel committed Mar 16, 2022
1 parent 17efee9 commit a570450
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/license.html
Expand Up @@ -5,7 +5,7 @@
<body alink="#fff000" link="#fff000" vlink="#fff000">
<h4><span style="font-family: Arial Black; color: #ffffff;"><strong>THERE IS NO UNDO BUTTON!<BR>SET UP A <FONT color=red>BACKUP</FONT> OF YOUR DATABASE</strong></span></h4>
<HR>
<!-- LICENCE_START -->Version: 3.220315 (15-Mar-2022)<br>
<!-- LICENCE_START -->Version: 3.220316 (16-Mar-2022)<br>
<span style="font-style: italic;">COPYRIGHT &copy; 2000-2022
USC &amp; McGill University.<br>
</span>
Expand Down
2 changes: 1 addition & 1 deletion doc/version.txt
@@ -1,2 +1,2 @@
% Brainstorm
% v. 3.220315 (15-Mar-2022)
% v. 3.220316 (16-Mar-2022)
27 changes: 24 additions & 3 deletions toolbox/process/functions/process_tf_norm.m
Expand Up @@ -22,7 +22,7 @@
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Francois Tadel, 2014
% Authors: Francois Tadel, 2014-2022
% Marc Lalancette, 2020

eval(macro_method);
Expand All @@ -48,6 +48,11 @@
'multiply2020', 'multiply', 'relative2020'};
sProcess.options.normalize.Type = 'radio_label';
sProcess.options.normalize.Value = 'multiply2020';
% Extra label
sProcess.options.warning.Comment = ['<BR><I><FONT color="#a0a0a0">Warning: The total power is computed as the sum of all the values.<BR>' ...
'With overlapping frequency bands, e.g. 8-12Hz 8-10Hz 10-12Hz,<BR>' ...
'parts of the spectrum would be added twice to the total power.</FONT></I>'];
sProcess.options.warning.Type = 'label';
end


Expand Down Expand Up @@ -91,8 +96,12 @@
[sInput.A, errorMsg] = Compute(sInput.A, TfMat.Measure, TfMat.Freqs, Method);
% Error management
if ~isempty(errorMsg)
bst_report('Error', sProcess, sInput, errorMsg);
sInput = [];
if isempty(sInput.A)
bst_report('Error', sProcess, sInput, errorMsg);
sInput = [];
else
bst_report('Warning', sProcess, sInput, errorMsg);
end
end
% Do not keep the Std field in the output
if isfield(sInput, 'Std') && ~isempty(sInput.Std)
Expand Down Expand Up @@ -164,6 +173,18 @@
% Reshape to have the scaling values in the third dimension
Factor = reshape(Factor, 1, 1, []);
case 'relative2020'
% Check if overlap between bands
if iscell(Freqs)
BandBounds = process_tf_bands('GetBounds', Freqs);
for iBand = 1:size(BandBounds,1)
if any((BandBounds(iBand,1) > BandBounds(:,1)) & (BandBounds(iBand,1) < BandBounds(:,2))) || ...
any((BandBounds(iBand,2) > BandBounds(:,1)) & (BandBounds(iBand,2) < BandBounds(:,2)))
errorMsg = ['Some frequency bands in the input file are overlapping. Some parts of the spectrum are added multiple times to the total power, ' ...
'leading to a wrong estimation of the relative power. Consider computing the PSD/TF files with the sub-frequency bands only, and group them after normalization.'];
break;
end
end
end
% Always sum total power (then sqrt for relative magnitude)
switch Measure
case 'power'
Expand Down

0 comments on commit a570450

Please sign in to comment.