Skip to content

Commit

Permalink
process_notch: Add warning and error for invalid notch frequencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rcassani committed Aug 7, 2023
1 parent 4dbbd57 commit 409dc1f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/license.html
Original file line number Diff line number Diff line change
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.230731 (31-Jul-2023)<br>
<!-- LICENCE_START -->Version: 3.230807 (07-Aug-2023)<br>
<span style="font-style: italic;">COPYRIGHT &copy; 2000-2023
USC &amp; McGill University.<br>
</span>
Expand Down
2 changes: 1 addition & 1 deletion doc/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
% Brainstorm
% v. 3.230731 (31-Jul-2023)
% v. 3.230807 (07-Aug-2023)
10 changes: 8 additions & 2 deletions toolbox/process/functions/process_notch.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
else
filtfilt_fcn = @oc_filtfilt;
end
Messages = [] ;
% Define a default width
% Remove the mean of the data before filtering
xmean = mean(x,2);
Expand All @@ -167,6 +168,11 @@
for ifreq = 1:length(FreqList)
% Define coefficients of an IIR notch filter
w0 = 2 * pi * FreqList(ifreq) / sfreq; %Normalized notch frequncy
% Check for valid notch frequency
if w0 >= 1
Messages = sprintf('Notch frequency cannot be above %.2f Hz.\n', sfreq/2);
return
end
% Pole radius
switch Method
case 'hnotch' % (Default after 2019) radius by a user defined bandwidth (-3dB)
Expand Down Expand Up @@ -225,7 +231,6 @@
% Compute the effective transient: Number of samples necessary for having 99% of the impulse response energy
[tmp, iE99] = min(abs(E - 0.99)) ;
FiltSpec.transient = iE99 / sfreq ;
Messages = [] ;
end


Expand All @@ -249,8 +254,9 @@ function DisplaySpec(sfreq)
end
% Compute filter specification
[tmp, FiltSpec, Messages] = Compute([], sfreq, FreqList, Method, bandWidth) ;
if isempty(FiltSpec)
if isempty(FiltSpec) || ~isempty(Messages)
bst_error(Messages, 'Filter response', 0);
return
end

b = FiltSpec.NumT;
Expand Down

0 comments on commit 409dc1f

Please sign in to comment.