|
95 | 95 | hop-size 8 |
96 | 96 | n-windows (int (/ (- n window-size) |
97 | 97 | hop-size)) |
98 | | - spectrograms (->> (range n-windows) |
99 | | - (pfor/pmap (fn [w] |
100 | | - (let [start-idx (* w hop-size) |
101 | | - window (-> resampled-ppi |
102 | | - :ppi |
103 | | - (dtype/sub-buffer start-idx window-size)) |
104 | | - window-standardized (stats/standardize window) |
| 98 | + windows (->> (range n-windows) |
| 99 | + (map (fn [w] |
| 100 | + [w (let [start-idx (* w hop-size)] |
| 101 | + (-> resampled-ppi |
| 102 | + :ppi |
| 103 | + (dtype/sub-buffer start-idx window-size)))]))) |
| 104 | + rmssds (->> windows |
| 105 | + (map (fn [[w window]] |
| 106 | + (-> window |
| 107 | + (tcc/shift 1) |
| 108 | + (tcc/- window) |
| 109 | + tcc/sq |
| 110 | + tcc/mean |
| 111 | + tcc/sqrt)))) |
| 112 | + spectrograms (->> windows |
| 113 | + (pfor/pmap (fn [[w window]] |
| 114 | + (let [window-standardized (stats/standardize window) |
105 | 115 | window-filtered (.bandPassFilter bw |
106 | 116 | (double-array window-standardized) |
107 | 117 | 4 |
|
116 | 126 | vec)] |
117 | 127 | {:sampling-rate sampling-rate |
118 | 128 | :resampled-ppi resampled-ppi |
| 129 | + :rmssds rmssds |
119 | 130 | :spectrograms spectrograms}))) |
120 | 131 |
|
121 | 132 |
|
|
145 | 156 |
|
146 | 157 | (defn plot-with-measures [{:keys [sampling-rate |
147 | 158 | resampled-ppi |
| 159 | + rmssds |
148 | 160 | spectrograms]}] |
149 | 161 | (when spectrograms |
150 | 162 | (let [n (-> spectrograms first :magnitude count) |
|
160 | 172 | (when (:label resampled-ppi) |
161 | 173 | {:=color :label |
162 | 174 | :=color-type :nominal})))) |
| 175 | + :rmssd (-> {:t times |
| 176 | + :rmssd rmssds} |
| 177 | + tc/dataset |
| 178 | + (plotly/base {:=height 300 :=width 700}) |
| 179 | + (plotly/layer-line {:=x :t |
| 180 | + :=y :rmssd}) |
| 181 | + plotly/plot |
| 182 | + (assoc-in [:layout :yaxis :range] [0 0.1])) |
163 | 183 | :power-spectrum (kind/plotly |
164 | 184 | {:data [{:x times |
165 | 185 | :y freqs |
|
340 | 360 |
|
341 | 361 | (def WESAD-spectrograms |
342 | 362 | (memoize |
343 | | - (fn [{:keys [ppi-params spectrogram-params]}] |
| 363 | + (fn [{:keys [ppi-params measures-params]}] |
344 | 364 | (-> ppi-params |
345 | 365 | extract-ppi |
346 | | - (compute-measures spectrogram-params))))) |
| 366 | + (compute-measures measures-params))))) |
347 | 367 |
|
348 | 368 |
|
349 | 369 | (delay |
350 | 370 | (-> {:ppi-params {:subject-id 5 |
351 | 371 | :row-interval [0 1000000]} |
352 | | - :spectrogram-params {:sampling-rate 10 |
353 | | - :window-size-in-sec 120}} |
| 372 | + :measures-params {:sampling-rate 10 |
| 373 | + :window-size-in-sec 120}} |
354 | 374 | WESAD-spectrograms |
355 | 375 | plot-with-measures)) |
356 | 376 |
|
|
382 | 402 |
|
383 | 403 | (delay |
384 | 404 | (let [subject 5] |
385 | | - (-> (label-intervals subject) |
386 | | - (tc/select-rows #(not= (:label %) :ignore)) |
387 | | - #_(tc/select-rows #(= (:label %) :meditation)) |
388 | | - (tc/rows :as-maps) |
389 | | - (->> (map (fn [{:keys [offset n label]}] |
390 | | - [label |
391 | | - (try (-> {:ppi-params {:subject-id subject |
392 | | - :row-interval [offset (+ offset n)]} |
393 | | - :spectrogram-params {:sampling-rate 10 |
394 | | - :window-size-in-sec 120}} |
395 | | - WESAD-spectrograms |
396 | | - plot-with-measures |
397 | | - ;; :LF-to-HF-series |
398 | | - ) |
399 | | - (catch Exception e 'unavailable))])))))) |
| 405 | + (kind/fragment |
| 406 | + (-> (label-intervals subject) |
| 407 | + (tc/select-rows #(not= (:label %) :ignore)) |
| 408 | + #_(tc/select-rows #(= (:label %) :meditation)) |
| 409 | + (tc/rows :as-maps) |
| 410 | + (->> (mapcat (fn [{:keys [offset n label]}] |
| 411 | + [label |
| 412 | + (try (-> {:ppi-params {:subject-id subject |
| 413 | + :row-interval [offset (+ offset n)]} |
| 414 | + :measures-params {:sampling-rate 10 |
| 415 | + :window-size-in-sec 120}} |
| 416 | + WESAD-spectrograms |
| 417 | + plot-with-measures) |
| 418 | + (catch Exception e 'unavailable))]))))))) |
0 commit comments