TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
hist2limits.m
Go to the documentation of this file.
1 function [LIM1,LIM2,LIM3,h0] = hist2limits(H,TH)
2 % HIST2LIMITS returns the threshold for detecting saturation artifacts.
3 %
4 % Saturation thresholds can be obtained from the histogram [1]. This
5 % routine tries to obtain the saturation threshold in an automated way.
6 %
7 % The routine was tested with the histograms of 528 recordings with
8 % three respiratory channels each.
9 %
10 %
11 % Reference(s):
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.
15 
16 
17 % $Revision: 1.1 $
18 % $Id: hist2limits.m 2202 2009-10-27 12:06:45Z schloegl $
19 % Copyright (C) 1999-2003 by Alois Schloegl <a.schloegl@ieee.org>
20 
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.
25 %
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.
30 %
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.
34 
35 
36 
37 
38 if isnumeric(H)
39  H = histo2(H);
40 end;
41 
42 for k = 1:size(H.H,2),
43  h = H.H(:,k);
44  x = H.X(:,min(k,size(H.X,2)));
45 
46  tmp = find(h>0);
47  h(tmp([1,length(tmp)])) = 0; % remove max and min values; (necessary for H recordings and some B)
48  N = sum(h);
49 
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.
54 
55  mu = x'*h/N;
56  sd = sqrt(((x-mu)'.^2*h)/N);
57 
58  LIM2(:,k) = sort(sd*[1;-1]*norminv(2/N)+mu);
59 
60  h0 = sum(h)*normpdf(x,mu,sd);
61 
62  r0 = (h./max(h0,1e-2));
63  [s,ix] = sort(-r0);
64  tmp = ix(x(ix)>mu);
65  LIM3(:,k) = [NaN;NaN];
66  if 1;r0(tmp(1))>1e2;
67  LIM3(1,k) = x(tmp(1));
68  end;
69  tmp = ix(x(ix)<mu);
70  if 1;r0(tmp(1))>1e3;
71  LIM3(2,k) = x(tmp(1));
72  end;
73 
74  LIM3(:,k) = sort(mean(LIM3(:,k))+([1;-1]*TH/2)*abs(diff(LIM3(:,k)))); % take range between 10% and 90% of total range.
75 
76 
77  LIM0(:,k) = [max(LIM1(1,k),LIM2(1,k));min(LIM1(2,k),LIM2(2,k))];
78  LIM = LIM1;
79 end;
80 
81 
hist2limits
function hist2limits(in H, in TH)