2 % HIST2LIMITS returns the threshold
for detecting saturation artifacts.
4 % Saturation thresholds can be obtained from the histogram [1]. This
5 % routine tries to obtain the saturation threshold in an automated way.
7 % The routine was tested with the histograms of 528 recordings with
8 % three respiratory channels each.
12 % [1] A. Schlögl, B. Kemp, T. Penzel, D. Kunz, S.-L. Himanen,A. Värri, G. Dorffner, G. Pfurtscheller.
13 % Quality Control of polysomnographic Sleep Data by Histogram and Entropy Analysis.
14 % Clin. Neurophysiol. 1999, Dec; 110(12): 2165 - 2170.
18 % $Id:
hist2limits.m 2202 2009-10-27 12:06:45Z schloegl $
19 % Copyright (C) 1999-2003 by Alois Schloegl <a.schloegl@ieee.org>
21 % This program is free software; you can redistribute it and/or
22 % modify it under the terms of the GNU General Public License
23 % as published by the Free Software Foundation; either version 2
24 % of the License, or (at your option) any later version.
26 % This program is distributed in the hope that it will be useful,
27 % but WITHOUT ANY WARRANTY; without even the implied warranty of
28 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 % GNU General Public License
for more details.
31 % You should have received a copy of the GNU General Public License
32 % along with
this program;
if not, write to the Free Software
33 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
42 for k = 1:size(H.H,2),
44 x = H.X(:,min(k,size(H.X,2)));
47 h(tmp([1,length(tmp)])) = 0; % remove max and min values; (necessary
for H recordings and some B)
50 % Lim = H.X(find(h>0),1); % calculate limit values of remaining Histogram
51 Lim = x(find(h>0)); % calculate limit values of remaining Histogram
52 Lim = [max(Lim),min(Lim)];
53 LIM1(:,k) = sort(mean(Lim)+([1;-1]*TH/2)*abs(diff(Lim))); % take range between 10% and 90% of total range.
56 sd = sqrt(((x-mu)'.^2*h)/N);
58 LIM2(:,k) = sort(sd*[1;-1]*norminv(2/N)+mu);
60 h0 = sum(h)*normpdf(x,mu,sd);
62 r0 = (h./max(h0,1e-2));
65 LIM3(:,k) = [NaN;NaN];
67 LIM3(1,k) = x(tmp(1));
71 LIM3(2,k) = x(tmp(1));
74 LIM3(:,k) = sort(mean(LIM3(:,k))+([1;-1]*TH/2)*abs(diff(LIM3(:,k)))); % take range between 10% and 90% of total range.
77 LIM0(:,k) = [max(LIM1(1,k),LIM2(1,k));min(LIM1(2,k),LIM2(2,k))];