Skip to content

Commit 2769dab

Browse files
committed
hrv - handling possible divide-by-zero
1 parent 26c6a4d commit 2769dab

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/data_analysis/heart_rate_variability/exploring_heart_rate_variability.clj

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,18 @@
157157
(defn LF-to-HF [freqs spectrogram]
158158
(let [ds (tc/dataset {:f freqs
159159
:s (:magnitude spectrogram)}
160-
tc/dataset)]
161-
(/ (-> ds
162-
(tc/select-rows #(<= 0.04 (% :f) 0.15))
163-
:s
164-
tcc/sum)
165-
(-> ds
166-
(tc/select-rows #(<= 0.15 (% :f) 0.4))
167-
:s
168-
tcc/sum))))
160+
tc/dataset)
161+
lf-power (-> ds
162+
(tc/select-rows #(<= 0.04 (% :f) 0.15))
163+
:s
164+
tcc/sum)
165+
hf-power (-> ds
166+
(tc/select-rows #(<= 0.15 (% :f) 0.4))
167+
:s
168+
tcc/sum)]
169+
(if (pos? hf-power)
170+
(/ lf-power hf-power)
171+
Double/NaN))) ; Return NaN when HF power is zero or negative
169172

170173
(defn plot-with-measures [{:keys [sampling-rate
171174
window-size

0 commit comments

Comments
 (0)