TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
nk2hyp.m
Go to the documentation of this file.
1 function [hyp,g1,g2] = nk2hyp(fn)
2 % NK2HYP extracts the hypnogram from NihonKohden data
3 %
4 % [hyp,g] = nk2hyp(fn)
5 %
6 % fn filename
7 % hyp hypnogram in 'W1234R' encoding
8 % g hypnogram in 0=W,1,2,3,4,5=R encoding
9 
10 
11 % $Id$
12 % Copyright (C) 2010 by Alois Schloegl <a.schloegl@ieee.org>
13 % This is part of the BIOSIG-toolbox http://biosig.sf.net/
14 
15 
16 % This program is free software; you can redistribute it and/or
17 % modify it under the terms of the GNU General Public License
18 % as published by the Free Software Foundation; either version 3
19 % of the License, or (at your option) any later version.
20 %
21 % This program is distributed in the hope that it will be useful,
22 % but WITHOUT ANY WARRANTY; without even the implied warranty of
23 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 % GNU General Public License for more details.
25 %
26 % You should have received a copy of the GNU General Public License
27 % along with this program; if not, write to the Free Software
28 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 
30 
31 [p,f,e] = fileparts(fn);
32 
33 fn = fullfile(p,[f,'.dat']);
34 fid = fopen(fn,'r');
35 dat = fread(fid,inf,'uint8');
36 fclose(fid);
37 
38 pos = length(dat);
39 ix = [];
40 nn = [];
41 while all(dat(pos+[-1,0])==255)
42  ix = [pos,ix];
43  pos = pos-62;
44  nn = [[1,256]*dat(pos+[1:2]),nn];
45 end;
46 if (nn(1)~=1) || any(diff(nn)~=1)
47  % sanity check
48  error('nk2hyp failed');
49 end;
50 g2 = dat(ix-3)';
51 g1 = dat(ix-2)';
52 clear dat;
53 
54 g2(g2=='W')=0;
55 g2(g2=='R')=5;
56 g1(g1=='W')=0;
57 g1(g1=='R')=5;
58 
59 H = 'W12345R';
60 hyp = H(g2+1);
nk2hyp
function nk2hyp(in fn)