Extracting and visualizing subject head movement

Continuous head movement can be encoded during MEG recordings by use of HPI coils that continuously emit sinusoidal signals. These signals can then be extracted from the recording and used to estimate head position as a function of time. Here we show an example of how to do this, and how to visualize the result.

HPI frequencies

First let’s load a short bit of raw data where the subject intentionally moved their head during the recording. Its power spectral density shows five peaks (most clearly visible in the gradiometers) corresponding to the HPI coil frequencies, plus other peaks related to power line interference (60 Hz and harmonics).

# Authors: Eric Larson <larson.eric.d@gmail.com>
#          Richard Höchenberger <richard.hoechenberger@gmail.com>
#          Daniel McCloy <dan@mccloy.info>
#
# License: BSD-3-Clause
from os import path as op
import mne

data_path = op.join(mne.datasets.testing.data_path(verbose=True), 'SSS')
fname_raw = op.join(data_path, 'test_move_anon_raw.fif')
raw = mne.io.read_raw_fif(fname_raw, allow_maxshield='yes').load_data()
raw.plot_psd()
EEG, Gradiometers, Magnetometers

Out:

Opening raw data file /home/circleci/mne_data/MNE-testing-data/SSS/test_move_anon_raw.fif...
    Read a total of 12 projection items:
        mag.fif : PCA-v1 (1 x 306)  idle
        mag.fif : PCA-v2 (1 x 306)  idle
        mag.fif : PCA-v3 (1 x 306)  idle
        mag.fif : PCA-v4 (1 x 306)  idle
        mag.fif : PCA-v5 (1 x 306)  idle
        mag.fif : PCA-v6 (1 x 306)  idle
        mag.fif : PCA-v7 (1 x 306)  idle
        grad.fif : PCA-v1 (1 x 306)  idle
        grad.fif : PCA-v2 (1 x 306)  idle
        grad.fif : PCA-v3 (1 x 306)  idle
        grad.fif : PCA-v4 (1 x 306)  idle
        Average EEG reference (1 x 60)  idle
    Range : 10800 ... 31199 =      9.000 ...    25.999 secs
Ready.
Reading 0 ... 20399  =      0.000 ...    16.999 secs...
Effective window size : 1.707 (s)
Effective window size : 1.707 (s)
Effective window size : 1.707 (s)

We can use mne.chpi.get_chpi_info to retrieve the coil frequencies, the index of the channel indicating when which coil was switched on, and the respective “event codes” associated with each coil’s activity.

chpi_freqs, ch_idx, chpi_codes = mne.chpi.get_chpi_info(info=raw.info)
print(f'cHPI coil frequencies extracted from raw: {chpi_freqs} Hz')

Out:

Using 5 HPI coils: 83 143 203 263 323 Hz
cHPI coil frequencies extracted from raw: [ 83. 143. 203. 263. 323.] Hz

Estimating continuous head position

First, let’s extract the HPI coil amplitudes as a function of time:

Out:

Using 5 HPI coils: 83 143 203 263 323 Hz
Line interference frequencies: 60 120 180 240 300 360 Hz
Using time window: 83.3 ms
Fitting 5 HPI coil locations at up to 1696 time points (17.0 sec duration)

  0%|          | cHPI amplitudes : 0/1696 [00:00<?,       ?it/s]
  0%|          | cHPI amplitudes : 1/1696 [00:02<1:09:56,    2.48s/it]
  1%|1         | cHPI amplitudes : 18/1696 [00:02<03:41,    7.58it/s]
  2%|2         | cHPI amplitudes : 42/1696 [00:02<01:31,   18.11it/s]
  4%|3         | cHPI amplitudes : 60/1696 [00:02<01:03,   25.78it/s]
  5%|4         | cHPI amplitudes : 82/1696 [00:02<00:44,   35.97it/s]
  6%|6         | cHPI amplitudes : 106/1696 [00:02<00:33,   47.52it/s]
  7%|7         | cHPI amplitudes : 127/1696 [00:02<00:27,   56.46it/s]
  9%|8         | cHPI amplitudes : 150/1696 [00:02<00:22,   68.01it/s]
 10%|#         | cHPI amplitudes : 173/1696 [00:02<00:19,   79.98it/s]
 12%|#1        | cHPI amplitudes : 196/1696 [00:02<00:16,   89.74it/s]
 13%|#2        | cHPI amplitudes : 220/1696 [00:02<00:14,  102.73it/s]
 14%|#4        | cHPI amplitudes : 244/1696 [00:02<00:12,  116.17it/s]
 16%|#5        | cHPI amplitudes : 268/1696 [00:02<00:11,  126.00it/s]
 17%|#7        | cHPI amplitudes : 291/1696 [00:02<00:10,  139.29it/s]
 19%|#8        | cHPI amplitudes : 315/1696 [00:02<00:08,  153.62it/s]
 20%|#9        | cHPI amplitudes : 339/1696 [00:02<00:08,  162.57it/s]
 21%|##1       | cHPI amplitudes : 362/1696 [00:02<00:07,  176.62it/s]
 23%|##2       | cHPI amplitudes : 384/1696 [00:02<00:06,  190.29it/s]
 24%|##3       | cHPI amplitudes : 406/1696 [00:03<00:06,  196.98it/s]
 25%|##5       | cHPI amplitudes : 427/1696 [00:03<00:06,  210.24it/s]
 26%|##6       | cHPI amplitudes : 447/1696 [00:03<00:05,  223.08it/s]
 28%|##7       | cHPI amplitudes : 468/1696 [00:03<00:05,  227.76it/s]
 29%|##8       | cHPI amplitudes : 489/1696 [00:03<00:04,  241.72it/s]
 30%|###       | cHPI amplitudes : 510/1696 [00:03<00:04,  256.01it/s]
 31%|###1      | cHPI amplitudes : 532/1696 [00:03<00:04,  259.90it/s]
 33%|###2      | cHPI amplitudes : 556/1696 [00:03<00:04,  276.91it/s]
 34%|###4      | cHPI amplitudes : 580/1696 [00:03<00:03,  294.41it/s]
 35%|###5      | cHPI amplitudes : 602/1696 [00:03<00:03,  296.28it/s]
 37%|###6      | cHPI amplitudes : 626/1696 [00:03<00:03,  313.94it/s]
 38%|###8      | cHPI amplitudes : 650/1696 [00:03<00:03,  331.96it/s]
 40%|###9      | cHPI amplitudes : 675/1696 [00:03<00:02,  351.19it/s]
 40%|###9      | cHPI amplitudes : 676/1696 [00:03<00:03,  334.42it/s]
 41%|####1     | cHPI amplitudes : 699/1696 [00:03<00:02,  352.41it/s]
 43%|####2     | cHPI amplitudes : 724/1696 [00:03<00:02,  372.62it/s]
 44%|####4     | cHPI amplitudes : 748/1696 [00:03<00:02,  371.48it/s]
 46%|####5     | cHPI amplitudes : 772/1696 [00:03<00:02,  390.64it/s]
 47%|####6     | cHPI amplitudes : 796/1696 [00:03<00:02,  410.07it/s]
 48%|####8     | cHPI amplitudes : 820/1696 [00:03<00:02,  406.19it/s]
 50%|####9     | cHPI amplitudes : 844/1696 [00:03<00:02,  425.66it/s]
 51%|#####1    | cHPI amplitudes : 869/1696 [00:03<00:01,  446.14it/s]
 53%|#####2    | cHPI amplitudes : 893/1696 [00:03<00:01,  439.58it/s]
 54%|#####4    | cHPI amplitudes : 917/1696 [00:03<00:01,  459.13it/s]
 55%|#####5    | cHPI amplitudes : 941/1696 [00:03<00:01,  478.88it/s]
 57%|#####6    | cHPI amplitudes : 966/1696 [00:03<00:01,  470.28it/s]
 58%|#####8    | cHPI amplitudes : 990/1696 [00:03<00:01,  489.72it/s]
 60%|#####9    | cHPI amplitudes : 1014/1696 [00:03<00:01,  509.63it/s]
 61%|######1   | cHPI amplitudes : 1039/1696 [00:03<00:01,  498.36it/s]
 63%|######2   | cHPI amplitudes : 1061/1696 [00:03<00:01,  515.62it/s]
 64%|######3   | cHPI amplitudes : 1085/1696 [00:03<00:01,  535.32it/s]
 65%|######5   | cHPI amplitudes : 1109/1696 [00:04<00:01,  520.46it/s]
 67%|######6   | cHPI amplitudes : 1133/1696 [00:04<00:01,  540.06it/s]
 68%|######8   | cHPI amplitudes : 1157/1696 [00:04<00:00,  559.89it/s]
 70%|######9   | cHPI amplitudes : 1180/1696 [00:04<00:00,  541.40it/s]
 71%|#######   | cHPI amplitudes : 1203/1696 [00:04<00:00,  559.54it/s]
 72%|#######2  | cHPI amplitudes : 1224/1696 [00:04<00:00,  575.57it/s]
 74%|#######3  | cHPI amplitudes : 1248/1696 [00:04<00:00,  595.53it/s]
 74%|#######3  | cHPI amplitudes : 1249/1696 [00:04<00:00,  556.10it/s]
 75%|#######5  | cHPI amplitudes : 1273/1696 [00:04<00:00,  576.56it/s]
 76%|#######6  | cHPI amplitudes : 1296/1696 [00:04<00:00,  595.95it/s]
 78%|#######7  | cHPI amplitudes : 1320/1696 [00:04<00:00,  616.77it/s]
 78%|#######7  | cHPI amplitudes : 1321/1696 [00:04<00:00,  573.22it/s]
 79%|#######9  | cHPI amplitudes : 1345/1696 [00:04<00:00,  594.74it/s]
 81%|########  | cHPI amplitudes : 1369/1696 [00:04<00:00,  616.11it/s]
 82%|########1 | cHPI amplitudes : 1390/1696 [00:04<00:00,  586.98it/s]
 83%|########3 | cHPI amplitudes : 1413/1696 [00:04<00:00,  606.60it/s]
 85%|########4 | cHPI amplitudes : 1436/1696 [00:04<00:00,  626.51it/s]
 86%|########6 | cHPI amplitudes : 1459/1696 [00:04<00:00,  598.93it/s]
 87%|########7 | cHPI amplitudes : 1481/1696 [00:04<00:00,  617.09it/s]
 89%|########8 | cHPI amplitudes : 1503/1696 [00:04<00:00,  635.31it/s]
 90%|########9 | cHPI amplitudes : 1523/1696 [00:04<00:00,  602.15it/s]
 91%|#########1| cHPI amplitudes : 1544/1696 [00:04<00:00,  618.92it/s]
 92%|#########2| cHPI amplitudes : 1566/1696 [00:04<00:00,  636.92it/s]
 94%|#########3| cHPI amplitudes : 1587/1696 [00:04<00:00,  605.24it/s]
 95%|#########4| cHPI amplitudes : 1606/1696 [00:04<00:00,  618.96it/s]
 96%|#########5| cHPI amplitudes : 1628/1696 [00:04<00:00,  636.78it/s]
 97%|#########7| cHPI amplitudes : 1650/1696 [00:04<00:00,  654.90it/s]
 97%|#########7| cHPI amplitudes : 1651/1696 [00:04<00:00,  605.65it/s]
 99%|#########8| cHPI amplitudes : 1672/1696 [00:04<00:00,  623.20it/s]
100%|#########9| cHPI amplitudes : 1694/1696 [00:04<00:00,  641.03it/s]
100%|##########| cHPI amplitudes : 1696/1696 [00:04<00:00,  345.94it/s]

Second, let’s compute time-varying HPI coil locations from these:

Out:

Computing 4385 HPI location guesses (1 cm grid in a 10.7 cm sphere)
HPIFIT: 5 coils digitized in order 5 1 4 3 2
HPI consistency of isotrak and hpifit is OK.

  0%|          | cHPI locations  : 0/1696 [00:00<?,       ?it/s]
  0%|          | cHPI locations  : 1/1696 [00:00<21:56,    1.29it/s]
  0%|          | cHPI locations  : 7/1696 [00:00<03:16,    8.59it/s]
  3%|2         | cHPI locations  : 46/1696 [00:00<00:28,   58.07it/s]
  5%|5         | cHPI locations  : 85/1696 [00:00<00:14,  108.01it/s]
  6%|5         | cHPI locations  : 101/1696 [00:01<00:16,   94.37it/s]
  8%|8         | cHPI locations  : 140/1696 [00:01<00:11,  133.20it/s]
 10%|#         | cHPI locations  : 178/1696 [00:01<00:08,  171.66it/s]
 11%|#1        | cHPI locations  : 189/1696 [00:01<00:08,  172.20it/s]
 12%|#1        | cHPI locations  : 201/1696 [00:01<00:09,  150.93it/s]
 14%|#4        | cHPI locations  : 240/1696 [00:01<00:07,  185.18it/s]
 16%|#6        | cHPI locations  : 279/1696 [00:01<00:06,  220.16it/s]
 17%|#7        | cHPI locations  : 289/1696 [00:01<00:06,  216.81it/s]
 18%|#7        | cHPI locations  : 301/1696 [00:01<00:07,  186.33it/s]
 18%|#7        | cHPI locations  : 303/1696 [00:01<00:07,  176.68it/s]
 20%|#9        | cHPI locations  : 333/1696 [00:01<00:06,  199.59it/s]
 21%|##        | cHPI locations  : 354/1696 [00:01<00:06,  215.20it/s]
 22%|##2       | cHPI locations  : 377/1696 [00:01<00:05,  232.94it/s]
 24%|##3       | cHPI locations  : 400/1696 [00:01<00:05,  251.01it/s]
 24%|##3       | cHPI locations  : 401/1696 [00:02<00:06,  203.53it/s]
 26%|##5       | cHPI locations  : 440/1696 [00:02<00:05,  233.24it/s]
 28%|##8       | cHPI locations  : 479/1696 [00:02<00:04,  263.70it/s]
 30%|##9       | cHPI locations  : 501/1696 [00:02<00:05,  227.99it/s]
 32%|###1      | cHPI locations  : 541/1696 [00:02<00:04,  255.59it/s]
 33%|###2      | cHPI locations  : 559/1696 [00:02<00:05,  217.64it/s]
 33%|###3      | cHPI locations  : 568/1696 [00:03<00:06,  186.19it/s]
 34%|###3      | cHPI locations  : 573/1696 [00:03<00:06,  160.54it/s]
 34%|###4      | cHPI locations  : 577/1696 [00:03<00:07,  140.65it/s]
 34%|###4      | cHPI locations  : 581/1696 [00:03<00:08,  124.30it/s]
 35%|###4      | cHPI locations  : 587/1696 [00:04<00:09,  111.84it/s]
 35%|###4      | cHPI locations  : 593/1696 [00:04<00:09,  110.84it/s]
 35%|###5      | cHPI locations  : 600/1696 [00:04<00:10,  100.93it/s]
 38%|###7      | cHPI locations  : 641/1696 [00:04<00:09,  116.27it/s]
 40%|####      | cHPI locations  : 681/1696 [00:04<00:07,  131.81it/s]
 41%|####1     | cHPI locations  : 700/1696 [00:05<00:08,  121.02it/s]
 44%|####3     | cHPI locations  : 742/1696 [00:05<00:06,  136.56it/s]
 46%|####6     | cHPI locations  : 785/1696 [00:05<00:05,  153.10it/s]
 47%|####6     | cHPI locations  : 789/1696 [00:05<00:06,  138.35it/s]
 47%|####6     | cHPI locations  : 794/1696 [00:05<00:07,  125.24it/s]
 47%|####7     | cHPI locations  : 800/1696 [00:05<00:07,  114.69it/s]
 47%|####7     | cHPI locations  : 805/1696 [00:06<00:08,  105.34it/s]
 48%|####7     | cHPI locations  : 810/1696 [00:06<00:09,   96.93it/s]
 48%|####8     | cHPI locations  : 815/1696 [00:06<00:09,   89.87it/s]
 48%|####8     | cHPI locations  : 819/1696 [00:07<00:10,   83.30it/s]
 49%|####8     | cHPI locations  : 823/1696 [00:07<00:11,   77.54it/s]
 49%|####8     | cHPI locations  : 827/1696 [00:07<00:12,   72.32it/s]
 49%|####9     | cHPI locations  : 833/1696 [00:08<00:12,   68.18it/s]
 50%|#####     | cHPI locations  : 848/1696 [00:08<00:12,   66.72it/s]
 50%|#####     | cHPI locations  : 853/1696 [00:08<00:12,   66.72it/s]
 52%|#####2    | cHPI locations  : 889/1696 [00:08<00:10,   76.19it/s]
 55%|#####4    | cHPI locations  : 926/1696 [00:08<00:08,   86.35it/s]
 56%|#####5    | cHPI locations  : 948/1696 [00:08<00:08,   83.66it/s]
 58%|#####8    | cHPI locations  : 984/1696 [00:08<00:07,   93.43it/s]
 60%|######    | cHPI locations  : 1020/1696 [00:08<00:06,  103.62it/s]
 61%|######1   | cHPI locations  : 1040/1696 [00:09<00:06,  100.85it/s]
 62%|######1   | cHPI locations  : 1051/1696 [00:09<00:06,   95.57it/s]
 63%|######2   | cHPI locations  : 1062/1696 [00:09<00:07,   88.84it/s]
 63%|######3   | cHPI locations  : 1072/1696 [00:10<00:07,   84.42it/s]
 64%|######4   | cHPI locations  : 1086/1696 [00:10<00:07,   79.85it/s]
 66%|######5   | cHPI locations  : 1115/1696 [00:10<00:06,   86.86it/s]
 68%|######8   | cHPI locations  : 1156/1696 [00:10<00:05,   97.37it/s]
 70%|######9   | cHPI locations  : 1184/1696 [00:10<00:04,  103.37it/s]
 70%|######9   | cHPI locations  : 1186/1696 [00:10<00:05,   95.55it/s]
 72%|#######1  | cHPI locations  : 1221/1696 [00:10<00:04,  104.86it/s]
 74%|#######4  | cHPI locations  : 1257/1696 [00:10<00:03,  114.86it/s]
 76%|#######5  | cHPI locations  : 1285/1696 [00:11<00:03,  121.10it/s]
 76%|#######5  | cHPI locations  : 1286/1696 [00:11<00:03,  113.51it/s]
 76%|#######6  | cHPI locations  : 1296/1696 [00:11<00:03,  106.59it/s]
 77%|#######6  | cHPI locations  : 1301/1696 [00:11<00:03,   99.23it/s]
 77%|#######7  | cHPI locations  : 1306/1696 [00:12<00:04,   92.53it/s]
 77%|#######7  | cHPI locations  : 1311/1696 [00:12<00:04,   86.62it/s]
 78%|#######7  | cHPI locations  : 1315/1696 [00:12<00:04,   81.15it/s]
 78%|#######7  | cHPI locations  : 1319/1696 [00:13<00:04,   76.28it/s]
 78%|#######8  | cHPI locations  : 1325/1696 [00:13<00:05,   72.12it/s]
 78%|#######8  | cHPI locations  : 1331/1696 [00:13<00:05,   68.42it/s]
 79%|#######9  | cHPI locations  : 1341/1696 [00:14<00:05,   64.78it/s]
 80%|########  | cHPI locations  : 1363/1696 [00:14<00:04,   69.74it/s]
 82%|########1 | cHPI locations  : 1386/1696 [00:14<00:04,   75.16it/s]
 83%|########2 | cHPI locations  : 1402/1696 [00:14<00:03,   78.05it/s]
 84%|########3 | cHPI locations  : 1424/1696 [00:14<00:03,   83.63it/s]
 85%|########4 | cHPI locations  : 1441/1696 [00:14<00:03,   81.31it/s]
 85%|########5 | cHPI locations  : 1450/1696 [00:14<00:02,   82.10it/s]
 88%|########7 | cHPI locations  : 1492/1696 [00:14<00:02,   93.56it/s]
 91%|######### | cHPI locations  : 1535/1696 [00:14<00:01,  105.81it/s]
 91%|######### | cHPI locations  : 1541/1696 [00:14<00:01,   99.05it/s]
 92%|#########2| cHPI locations  : 1565/1696 [00:15<00:01,   95.05it/s]
 93%|#########2| cHPI locations  : 1573/1696 [00:15<00:01,   89.56it/s]
 93%|#########3| cHPI locations  : 1580/1696 [00:15<00:01,   84.47it/s]
 94%|#########3| cHPI locations  : 1586/1696 [00:16<00:01,   79.67it/s]
 94%|#########3| cHPI locations  : 1590/1696 [00:16<00:01,   74.75it/s]
 94%|#########3| cHPI locations  : 1594/1696 [00:16<00:01,   69.09it/s]
 94%|#########4| cHPI locations  : 1599/1696 [00:17<00:01,   65.41it/s]
 95%|#########4| cHPI locations  : 1609/1696 [00:17<00:01,   63.22it/s]
 96%|#########6| cHPI locations  : 1630/1696 [00:17<00:00,   67.87it/s]
 97%|#########6| cHPI locations  : 1637/1696 [00:17<00:00,   68.41it/s]
 97%|#########7| cHPI locations  : 1652/1696 [00:17<00:00,   65.48it/s]
100%|#########9| cHPI locations  : 1689/1696 [00:17<00:00,   74.15it/s]
100%|##########| cHPI locations  : 1696/1696 [00:17<00:00,   94.36it/s]

Lastly, compute head positions from the coil locations:

Out:

t=9.000:     5/5 good HPI fits, movements [mm/s] =      0.1 /      0.2 /      0.5 /      0.2 /      0.3
t=10.000:    5/5 good HPI fits, movements [mm/s] =      0.1 /      0.2 /      0.0 /      0.1 /      0.1
t=11.000:    5/5 good HPI fits, movements [mm/s] =      0.1 /      0.1 /      0.1 /      0.0 /      0.1
t=12.000:    5/5 good HPI fits, movements [mm/s] =      0.0 /      0.0 /      0.1 /      0.0 /      0.0
t=13.000:    5/5 good HPI fits, movements [mm/s] =      0.0 /      0.1 /      0.0 /      0.0 /      0.0
t=14.000:    5/5 good HPI fits, movements [mm/s] =      0.1 /      0.1 /      0.1 /      0.1 /      0.1
t=14.580:    5/5 good HPI fits, movements [mm/s] =      5.0 /      4.8 /      6.1 /      5.5 /      4.9
t=14.670:    5/5 good HPI fits, movements [mm/s] =     33.5 /     33.6 /     39.8 /     37.9 /     30.2
t=14.720:    5/5 good HPI fits, movements [mm/s] =     49.0 /     47.7 /     60.6 /     59.3 /     44.5
t=14.760:    5/5 good HPI fits, movements [mm/s] =     65.2 /     63.1 /     72.7 /     71.1 /     56.3
t=14.800:    5/5 good HPI fits, movements [mm/s] =     67.0 /     59.7 /     83.1 /     78.2 /     61.1
t=14.860:    5/5 good HPI fits, movements [mm/s] =     54.7 /     52.2 /     57.6 /     62.2 /     47.1
t=14.990:    5/5 good HPI fits, movements [mm/s] =     23.1 /     22.5 /     24.0 /     27.1 /     19.9
t=15.990:    5/5 good HPI fits, movements [mm/s] =      0.7 /      0.9 /      0.8 /      0.8 /      0.9
t=16.880:    5/5 good HPI fits, movements [mm/s] =      2.5 /      3.4 /      3.0 /      3.8 /      3.3
t=16.930:    5/5 good HPI fits, movements [mm/s] =     52.6 /     55.5 /     58.1 /     67.3 /     59.4
t=16.990:    5/5 good HPI fits, movements [mm/s] =     56.8 /     54.0 /     62.0 /     64.8 /     57.6
t=17.040:    5/5 good HPI fits, movements [mm/s] =     53.6 /     50.0 /     59.7 /     61.9 /     49.7
t=17.090:    5/5 good HPI fits, movements [mm/s] =     57.9 /     49.7 /     66.8 /     65.0 /     51.4
t=17.140:    5/5 good HPI fits, movements [mm/s] =     60.0 /     55.1 /     72.6 /     67.1 /     57.6
t=17.180:    5/5 good HPI fits, movements [mm/s] =     63.9 /     57.3 /     74.5 /     72.5 /     61.7
t=17.220:    5/5 good HPI fits, movements [mm/s] =     60.9 /     60.6 /     75.7 /     71.4 /     63.4
t=17.260:    5/5 good HPI fits, movements [mm/s] =     68.0 /     66.2 /     72.6 /     68.5 /     69.1
t=17.320:    5/5 good HPI fits, movements [mm/s] =     49.4 /     50.2 /     55.3 /     55.2 /     52.3
t=17.470:    5/5 good HPI fits, movements [mm/s] =     18.5 /     21.4 /     19.3 /     20.5 /     17.4
t=18.470:    5/5 good HPI fits, movements [mm/s] =      1.9 /      2.7 /      2.0 /      2.4 /      1.9
t=19.390:    5/5 good HPI fits, movements [mm/s] =      2.4 /      2.7 /      1.9 /      2.9 /      2.5
t=19.500:    5/5 good HPI fits, movements [mm/s] =     23.0 /     25.1 /     19.3 /     28.8 /     27.8
t=19.610:    5/5 good HPI fits, movements [mm/s] =     21.3 /     25.7 /     21.7 /     31.6 /     31.3
t=19.710:    5/5 good HPI fits, movements [mm/s] =     21.6 /     20.6 /     23.3 /     29.9 /     27.8
t=19.850:    5/5 good HPI fits, movements [mm/s] =     16.5 /     14.7 /     18.6 /     21.8 /     20.1
t=20.850:    5/5 good HPI fits, movements [mm/s] =      2.3 /      1.9 /      2.0 /      2.5 /      2.2
t=21.850:    5/5 good HPI fits, movements [mm/s] =      0.6 /      1.7 /      1.7 /      2.0 /      1.9
t=21.950:    5/5 good HPI fits, movements [mm/s] =     25.8 /     27.0 /     24.0 /     32.1 /     26.4
t=22.000:    5/5 good HPI fits, movements [mm/s] =     65.7 /     59.2 /     46.1 /     64.7 /     51.9
t=22.050:    5/5 good HPI fits, movements [mm/s] =     59.9 /     62.6 /     51.3 /     69.2 /     57.9
t=22.100:    5/5 good HPI fits, movements [mm/s] =     61.4 /     65.6 /     58.6 /     75.0 /     64.8
t=22.140:    5/5 good HPI fits, movements [mm/s] =     74.8 /     73.5 /     62.2 /     79.7 /     67.8
t=22.180:    5/5 good HPI fits, movements [mm/s] =     63.5 /     59.0 /     53.3 /     67.7 /     53.7
t=22.240:    5/5 good HPI fits, movements [mm/s] =     38.6 /     39.6 /     36.3 /     47.8 /     42.1
t=22.300:    5/5 good HPI fits, movements [mm/s] =     41.9 /     39.9 /     33.7 /     47.4 /     39.3
t=22.400:    5/5 good HPI fits, movements [mm/s] =     32.0 /     28.5 /     22.2 /     30.8 /     24.9
t=23.400:    5/5 good HPI fits, movements [mm/s] =      1.8 /      1.8 /      1.0 /      1.5 /      1.2
t=24.400:    5/5 good HPI fits, movements [mm/s] =      1.3 /      0.8 /      0.7 /      0.8 /      0.7
t=24.640:    5/5 good HPI fits, movements [mm/s] =     12.6 /     11.6 /     11.5 /     13.1 /     10.9
t=24.720:    5/5 good HPI fits, movements [mm/s] =     30.5 /     33.1 /     31.7 /     38.9 /     35.2
t=24.790:    5/5 good HPI fits, movements [mm/s] =     31.1 /     35.7 /     32.8 /     43.0 /     41.2
t=24.850:    5/5 good HPI fits, movements [mm/s] =     37.2 /     41.0 /     35.8 /     45.0 /     42.2
t=24.890:    5/5 good HPI fits, movements [mm/s] =     50.6 /     52.2 /     49.7 /     59.7 /     53.0
t=24.930:    5/5 good HPI fits, movements [mm/s] =     55.8 /     54.8 /     59.1 /     68.8 /     61.8
t=24.980:    5/5 good HPI fits, movements [mm/s] =     47.2 /     47.6 /     51.0 /     58.4 /     53.7
t=25.080:    5/5 good HPI fits, movements [mm/s] =     23.8 /     19.0 /     23.2 /     28.1 /     26.3
t=25.510:    5/5 good HPI fits, movements [mm/s] =      2.5 /      6.4 /      7.3 /      6.5 /      7.8

Note that these can then be written to disk or read from disk with mne.chpi.write_head_pos() and mne.chpi.read_head_pos(), respectively.

Visualizing continuous head position

We can plot as traces, which is especially useful for long recordings:

Position (mm), Rotation (quat)

Or we can visualize them as a continuous field (with the vectors pointing in the head-upward direction):

59 head positions

These head positions can then be used with mne.preprocessing.maxwell_filter() to compensate for movement, or with mne.preprocessing.annotate_movement() to mark segments as bad that deviate too much from the average head position.

Computing SNR of the HPI signal

It is also possible to compute the SNR of the continuous HPI measurements. This can be a useful proxy for head position along the vertical dimension, i.e., it can indicate the distance between the HPI coils and the MEG sensors. Using compute_chpi_snr, the HPI power and SNR are computed separately for each MEG sensor type and each HPI coil (frequency), along with the residual power for each sensor type. The results can then be visualized with plot_chpi_snr. Here we’ll just show a few seconds, for speed:

SNR, magnetometers, cHPI power, magnetometers, Residual variance, magnetometers, SNR, gradiometers, cHPI power, gradiometers, Residual variance, gradiometers

Out:

Using 5 HPI coils: 83 143 203 263 323 Hz
Line interference frequencies: 60 120 180 240 300 360 Hz
Using time window: 83.3 ms
Fitting 5 HPI coil locations at up to 496 time points (5.0 sec duration)

  0%|          | cHPI SNRs : 0/496 [00:00<?,       ?it/s]
  0%|          | cHPI SNRs : 1/496 [00:04<33:40,    4.08s/it]
  3%|3         | cHPI SNRs : 15/496 [00:04<02:05,    3.84it/s]
  6%|6         | cHPI SNRs : 30/496 [00:04<00:59,    7.86it/s]
  9%|9         | cHPI SNRs : 45/496 [00:04<00:37,   12.05it/s]
 11%|#         | cHPI SNRs : 54/496 [00:04<00:30,   14.48it/s]
 14%|#3        | cHPI SNRs : 68/496 [00:04<00:22,   18.68it/s]
 17%|#6        | cHPI SNRs : 83/496 [00:04<00:17,   23.38it/s]
 20%|#9        | cHPI SNRs : 97/496 [00:04<00:14,   27.48it/s]
 23%|##2       | cHPI SNRs : 112/496 [00:04<00:11,   32.49it/s]
 25%|##5       | cHPI SNRs : 126/496 [00:04<00:09,   37.35it/s]
 28%|##8       | cHPI SNRs : 141/496 [00:04<00:08,   41.98it/s]
 31%|###1      | cHPI SNRs : 156/496 [00:04<00:07,   47.52it/s]
 34%|###4      | cHPI SNRs : 171/496 [00:04<00:06,   53.28it/s]
 37%|###7      | cHPI SNRs : 185/496 [00:04<00:05,   57.61it/s]
 40%|####      | cHPI SNRs : 199/496 [00:04<00:04,   63.27it/s]
 43%|####3     | cHPI SNRs : 214/496 [00:04<00:04,   69.57it/s]
 46%|####5     | cHPI SNRs : 228/496 [00:04<00:03,   73.89it/s]
 48%|####8     | cHPI SNRs : 240/496 [00:04<00:03,   79.10it/s]
 51%|#####1    | cHPI SNRs : 255/496 [00:04<00:02,   85.98it/s]
 54%|#####4    | cHPI SNRs : 269/496 [00:04<00:02,   90.19it/s]
 57%|#####7    | cHPI SNRs : 283/496 [00:04<00:02,   96.88it/s]
 60%|#####9    | cHPI SNRs : 296/496 [00:04<00:01,  103.23it/s]
 62%|######2   | cHPI SNRs : 310/496 [00:04<00:01,  107.22it/s]
 65%|######5   | cHPI SNRs : 324/496 [00:04<00:01,  114.44it/s]
 68%|######8   | cHPI SNRs : 339/496 [00:04<00:01,  122.44it/s]
 71%|#######1  | cHPI SNRs : 353/496 [00:04<00:01,  126.02it/s]
 74%|#######3  | cHPI SNRs : 367/496 [00:04<00:00,  133.73it/s]
 77%|#######7  | cHPI SNRs : 382/496 [00:04<00:00,  142.28it/s]
 80%|########  | cHPI SNRs : 397/496 [00:04<00:00,  145.94it/s]
 83%|########2 | cHPI SNRs : 411/496 [00:05<00:00,  154.11it/s]
 86%|########5 | cHPI SNRs : 426/496 [00:05<00:00,  163.14it/s]
 89%|########8 | cHPI SNRs : 441/496 [00:05<00:00,  166.10it/s]
 92%|#########1| cHPI SNRs : 455/496 [00:05<00:00,  174.70it/s]
 95%|#########4| cHPI SNRs : 470/496 [00:05<00:00,  184.20it/s]
 98%|#########7| cHPI SNRs : 485/496 [00:05<00:00,  186.27it/s]
100%|##########| cHPI SNRs : 496/496 [00:05<00:00,   95.33it/s]

Total running time of the script: ( 0 minutes 44.920 seconds)

Estimated memory usage: 139 MB

Gallery generated by Sphinx-Gallery