DEGREE PROJECT, INMASTER THESIS , SECOND LEVEL STOCKHOLM, SWEDEN 2015
Developing an sleep scorer by using
Biosignals in Matlab
EVALUATION FOR SLEEP APNEA PATIENTS.
SHHS DATABASE.
IGOR ALFREDO ARROYO PORRAS
KTH ROYAL INSTITUTE OF TECHNOLOGY STH SCHOOL OF TECHNOLOGY AND HEALTH
15
17
-
-
-
-
18
Figure 1. Sleep Cycle
N1
REM
Wake
N2
N3
19
20
21
𝑆𝑙𝑒𝑒𝑝𝐸𝑓𝑓(%) =
𝑇𝑜𝑡𝑎𝑙 𝑆𝑙𝑒𝑒𝑝 𝑇𝑖𝑚𝑒 𝑇𝑖𝑚𝑒 𝑓𝑟𝑜𝑚 𝑠𝑙𝑒𝑒𝑝 𝑜𝑛𝑠𝑒𝑡 𝑡𝑜 𝑚𝑜𝑟𝑛𝑖𝑛𝑔 𝑤𝑎𝑘𝑖𝑛𝑔∗ 100
23
24
25
27
δ
θ
α
28
𝑀𝐴𝑉 =
1
𝑛
∑ |𝑓(𝑘)|
𝑛 𝑘=1
29
𝑆𝑇𝐷 = 𝜎 = √
1
𝑁
∑(𝑥
𝑖− 𝜇)
2 𝑁 𝑖=1𝜇 =
1
𝑁
∑ 𝑥
𝑖 𝑛 𝑖=1
𝑍𝐶𝑅 =
1
𝑇 − 1
∑ 𝑆𝑖𝑔𝑛(𝑠
𝑡∗ 𝑠
𝑡−1)
𝑇−1 𝑡=130
𝑘 =
𝑂𝑏𝑠𝑒𝑟𝑣𝑒𝑑 𝑎𝑔𝑟𝑒𝑒𝑚𝑒𝑛𝑡−𝐴𝑔𝑟𝑒𝑒𝑚𝑒𝑛𝑡 𝑏𝑦 𝑐ℎ𝑎𝑛𝑐𝑒1−𝐴𝑔𝑟𝑒𝑒𝑚𝑒𝑛𝑡 𝑏𝑦 𝑐ℎ𝑎𝑛𝑐𝑒
𝑘 =
𝑃
𝑜− 𝑃
𝑐1 − 𝑃
𝑐32
(𝑇𝑃𝑅)
𝑇𝑃𝑅 =
𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑇𝑃) 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑃).
(𝑆𝑃𝐶)
𝑆𝑃𝐶 =
𝑇𝑟𝑢𝑒 𝑛𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠 (𝑇𝑁) 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠 (𝑁)𝑃𝑃𝑉 =
𝑇𝑟𝑢𝑒 𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑇𝑃) 𝑇𝑟𝑢𝑒 𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑇𝑃) + 𝐹𝑎𝑙𝑠𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠 (𝐹𝑁).
𝐹𝑂𝑅 =
𝐹𝑎𝑙𝑠𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒 (𝐹𝑁) 𝑇𝑟𝑢𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠 (𝑇𝑁) + 𝐹𝑎𝑙𝑠𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠 (𝐹𝑁)𝑁𝑃𝑉 =
𝑇𝑟𝑢𝑒 𝑛𝑒𝑔𝑎𝑡𝑖𝑣𝑒 (𝑇𝑁) 𝑇𝑟𝑢𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒 (𝑇𝑁)+ 𝐹𝑎𝑙𝑠𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒 (𝐹𝑁).
𝐹𝑃𝑅 =
𝐹𝑎𝑙𝑠𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒 (𝐹𝑃) 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒 (𝑁)= 1 − 𝑆𝑃𝐶.
𝐹𝐷𝑅 =
𝐹𝑎𝑙𝑠𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒 (𝐹𝑃) 𝐹𝑎𝑙𝑠𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒 (𝐹𝑃) + 𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒 (𝑇𝑃).
𝐹𝑁𝑅 =
𝐹𝑎𝑙𝑠𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒 (𝐹𝑁) 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒 (𝑃).
𝐴𝐶𝐶 =
𝑇𝑟𝑢𝑒 𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑇𝑃)+ 𝑇𝑟𝑢𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠 (𝑇𝑁) 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑃)+𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠 (𝑁).
33
𝑃𝑟𝑒𝑣𝑎𝑙𝑒𝑛𝑐𝑒 =
𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑃) 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑃)+𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠 (𝑁)(𝐿𝑅 +) =
𝑇𝑟𝑢𝑒 𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑇𝑃) 𝐹𝑎𝑙𝑠𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝐹𝑃).
(𝐿𝑅 −) =
𝑇𝑟𝑢𝑒 𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝑇𝑃) 𝐹𝑎𝑙𝑠𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 (𝐹𝑃)𝐷𝑂𝑅 =
𝐿𝑅+ 𝐿𝑅−.
36
37
38
39
40
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
41
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
42
43
Figure 15. Block diagram for detection of apnea
Yes
46
-
-
47
-
-
-
-
-
-
48
𝑇ℎ𝑟𝑒𝑠ℎ𝑜𝑙𝑑 = 𝑀𝑒𝑎𝑛 (𝑠𝑖𝑔𝑛𝑎𝑙) + 𝑋 ∗ 𝑆𝑇𝐷(𝑠𝑖𝑔𝑛𝑎𝑙)
0 0,2 0,4 0,6 0,8 1 0 0,2 0,4 0,6 0,8 1 SE N SIB IL IT Y 1-SPECIFICITYROC ANALYSIS
51
53
(a) Normal abdominal signal. Maximums are extracted and then is calculated their MAV.
(b) Obstructive apnea episode, example of the abdominal signal. Maximums are extracted and then is
54
(a). Oxygen Saturation before low pass filtering
,
(b).Oxygen saturation after low pass filtering at 0.15Hz
Figure 27. Sao2 low pass filtering
55
Confusion matrix for Sao2 of patient 1
Confusion matrix for Sao2 of patient 11
Figure 29. Confusion Matrixes for Sao2 desaturation detection
56
- - - - - - -57
ε
ε
ε
64
68
PSGAnnotation> <SoftwareVersion>Compumedics</SoftwareVersion> <EpochLength>30</EpochLength> <ScoredEvents> <ScoredEvent><EventConcept>Recording Start Time</EventConcept> <Start>0</Start> <Duration>32520</Duration> <ClockTime>17.09.96 21.00.00</ClockTime> </ScoredEvent> <ScoredEvent> <EventConcept>SignalArtifactEvent</EventConcept> <Duration>8</Duration> <Start>1895.0</Start> <Notes>SpO2 artifact</Notes> </ScoredEvent> <ScoredEvent> <EventConcept>SignalArtifactEvent</EventConcept> <Duration>18</Duration> <Start>1995.0</Start> <Notes>SpO2 artifact</Notes> </ScoredEvent> <ScoredEvent> <EventConcept>SignalArtifactEvent</EventConcept> <Duration>3</Duration> <Start>2026.0</Start> <Notes>SpO2 artifact</Notes> </ScoredEvent> <ScoredEvent> <EventConcept>SignalArtifactEvent</EventConcept> <Duration>12</Duration> <Start>2048.0</Start> <Notes>SpO2 artifact</Notes> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:SleepArousalFinding</EventConcept> <Duration>9.6</Duration> <Start>3550.1</Start> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:SleepArousalFinding</EventConcept>
69
<Duration>8.3</Duration> <Start>3579.1</Start> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:SleepArousalFinding</EventConcept> <Duration>7.1</Duration> <Start>3632.8</Start> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:HypopneaFinding</EventConcept> <Duration>28.1</Duration> <Start>3699.4</Start> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:HemoglobinOxygenDesaturationFinding</Ev entConcept> <Duration>28.1</Duration> <Start>3729.4</Start> <SpO2Nadir>96</SpO2Nadir> <SpO2Baseline>97.0</SpO2Baseline> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:SleepArousalFinding</EventConcept> <Duration>9.3</Duration> <Start>3756.2</Start> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:SleepArousalFinding</EventConcept> <Duration>12.6</Duration> <Start>3797.5</Start> </ScoredEvent> <ScoredEvent> <ScoredEvent> <EventConcept>SDO:SleepArousalFinding</EventConcept> <Duration>8.9</Duration> <Start>4333.9</Start> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:HypopneaFinding</EventConcept> <Duration>34.1</Duration> <Start>4685.6</Start> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:HemoglobinOxygenDesaturationFinding</Ev entConcept> <Duration>34.1</Duration> <Start>4715.6</Start> <SpO2Nadir>97</SpO2Nadir> <SpO2Baseline>98.0</SpO2Baseline> </ScoredEvent> . . .70
<ScoredEvent> <EventConcept>SDO:WakeState</EventConcept> <Start>0.0</Start> <Duration>3390.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N1 </EventConcept> <Start>3390.0</Start> <Duration>30.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:WakeState</EventConcept> <Start>3420.0</Start> <Duration>90.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N1 < /EventConcept> <Start>3510.0</Start> <Duration>60.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N2 </EventConcept> <Start>3570.0</Start> <Duration>360.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:WakeState</EventConcept> <Start>3930.0</Start> <Duration>30.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N2 </EventConcept> <Start>3960.0</Start> <Duration>90.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N2 </EventConcept> <Start>9330.0</Start> <Duration>60.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N3 </EventConcept> <Start>9390.0</Start> <Duration>1140.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N2 </EventConcept> <Start>10530.0</Start> <Duration>300.0</Duration> </ScoredEvent> <ScoredEvent>71
<EventConcept>SDO:NonRapidEyeMovementSleep-N3 </EventConcept> <Start>10830.0</Start> <Duration>60.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N3 </EventConcept> <Start>10950.0</Start> <Duration>60.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N2 </EventConcept> <Start>11010.0</Start> <Duration>180.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:RapidEyeMovementSleep</EventConcept <Start>12660.0</Start> <Duration>1620.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N2 </EventConcept> <Start>14280.0</Start> <Duration>210.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:RapidEyeMovementSleep</EventConcept <Start>14490.0</Start> <Duration>180.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:NonRapidEyeMovementSleep-N2 </EventConcept> <Start>14670.0</Start> <Duration>780.0</Duration> </ScoredEvent> <ScoredEvent> <EventConcept>SDO:WakeState</EventConcept> <Start>15450.0</Start> <Duration>30.0</Duration> </ScoredEvent> </ScoredEvents> </PSGAnnotation>72
Subject: 1
Number Of 30 Second epochs: 1084
Epoch Scorer Visual Score Reason Respiratory disorders
1 Wake Wake 2 Wake Wake 3 Wake Wake 4 Wake Wake 5 Wake Wake 6 Wake Wake 7 Wake Wake 8 Wake Wake 9 Wake Wake 10 Wake Wake 11 Wake Wake 12 Wake Wake 13 Wake Wake 14 Wake Wake 15 Wake Wake 16 Wake Wake 17 Wake Wake 18 Wake Wake 19 Wake Wake 20 Wake Wake 21 Wake Wake 22 Wake Wake 23 Wake Wake 24 Wake Wake 25 Wake Wake 26 Wake Wake 27 Wake Wake 28 Wake Wake
Rem in Wake Stage
29 Wake N1
30 N1 N2 Delta + Theta>60% & low mean EMG
31 N2 N2
73
33 N2 Wake 34 N1 N1 35 N2 N2 SWdetection>20% 36 N3 N2 37 N2 N2 SWdetection>20% 38 N3 N2 39 N2 N2 SWdetection>20% 40 N3 N2 41 N3 N2 SWdetection>20% . . . . . . . . . 311 N2 N2312 N2 Wake Continue with the last score Apnea/hypopnea detected
313 N2 Wake
314 N1 Wake
Apnea/hypopnea detected
315 Wake Wake
316 Wake Wake Apnea/hypopnea detected
317 Wake Wake
Continue with the last score
318 Wake N1
319 N1 N2 Delta + Theta>60% & low mean EMG
320 N1 N2 Continue with the last score
321 N2 N2
Apnea/hypopnea detected
322 N2 N2
323 N2 N2
324 N3 N2
Continue with the last score
325 N2 Wake
Apnea/hypopnea detected
326 N2 Wake Continue with the last score
327 N2 Wake
328 N2 Wake Continue with the last score
329 N2 Wake Continue with the last score
330 N2 Wake Continue with the last score
331 Wake Wake 332 Wake Wake 333 Wake Wake 334 Wake Wake 335 Wake Wake 336 Wake Wake 337 Wake Wake
Continue with the last score
338 Wake N1
339 Wake N1 Continue with the last score
340 Wake N1 Continue with the last score
341 N1 N1 342 N2 N2 343 N2 N2 344 N2 N2 345 N2 N2 . . . . . . . . . 458 N2 N2
Continue with the last score
459 N2 Wake
460 N2 N1 Continue with the last score
74
462 N1 REM
Apnea/hypopnea detected
463 N1 REM Continue with the last score
464 N2 REM
465 REM REM
Apnea/hypopnea detected
466 REM REM
467 REM REM
468 REM REM Apnea/hypopnea detected
469 REM REM Apnea/hypopnea detected
REM K complex/Sleep Spindle detected
470 N2
471 N1 REM SEM detected
Apnea/hypopnea detec
N2 REM K complex/Sleep Spindle detected Apnea/hypopnea detected
472 REM
473 REM
474 REM REM
475 REM REM
476 REM REM Apnea/hypopnea detected
477 REM REM Apnea/hypopnea detected
. .
. .
. .
REM488 REM
489 REM REM
490 REM REM Apnea/hypopnea detected
REM
491 REM
492 REM REM
493 REM REM Apnea/hypopnea detected
494 REM REM Apnea/hypopnea detected
Wake K complex / Sleep Spindle detected
495 N2
496 N2 Wake Continue with the last score Apnea/hypopnea detec
N1 Continue with the last score
497 N2
498 N2 N1 Continue with the last score
499 N2 N2
500 N2 N2
501 N2 N2
502 N2 N2
. . .
. . .
. . .
686 N2 N2
687 N2 N2
688 N2 N2 689 N2 N2
Continue with the last score
75
691 N2 REM Continue with the last score
692 Wake REM Blink detected
693 Wake REM Continue with the last score
694 Wake REM Continue with the last score
695 N1 REM SEM detected
696 N1 REM Continue with the last score
697 REM REM 698 REM REM 699 REM REM 700 REM REM 701 REM REM 702 REM REM 703 REM REM Apnea/hypopnea detected 704 REM REM 705 REM REM 706 REM REM 707 REM REM 708 REM REM 709 REM REM 710 REM REM 711 REM REM 712 REM REM
K complex / Sleep Spindle detected
713 N2 REM
714 N2 REM Continue with the last score
715 N2 Wake Continue with the last score
716 N2 Wake Continue with the last score
717 N2 Wake Continue with the last score
718 N2 Wake Continue with the last score
719 Wake Wake
720 Wake Wake
721 Wake Wake
722 Wake Wake
Continue with the last score
723 Wake N1
724 Wake N1 Continue with the last score
725 Wake N1 Continue with the last score
726 N1 N1 727 N1 N1 728 N2 N2
.
. . . . . . . . Waking Wake Wake 1071 1072 Wake Wake 1073 Wake Wake 1074 Wake Wake 1075 Wake Wake 1076 Wake Wake 1077 Wake Wake 1078 Wake Wake 1079 Wake Wake76
1080 Wake Wake 1081 Wake Wake 1082 Wake Wake 1083 Wake Wake 1084 Wake WakeDifferent scores: 259 and 23.89 Percent
---
Scorer Visual Score Sleep Parameters
393
376 Total Sleep Time (mins)
Sleep Onset 32 31 Sleep Waking 910 909 Sleep Efficiency 89.52 85.54 Respiratory disorders 49.09 Apnea/hypopnea Sensitivity Apnea/hypopnea Specificity 91.55