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>
#
# License: BSD (3-clause)

from os import path as op

import mne

print(__doc__)

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)

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:16:56,    2.72s/it]
  1%|1         | cHPI amplitudes : 17/1696 [00:02<04:17,    6.51it/s]
  2%|1         | cHPI amplitudes : 30/1696 [00:02<02:22,   11.69it/s]
  3%|2         | cHPI amplitudes : 43/1696 [00:02<01:36,   17.07it/s]
  3%|2         | cHPI amplitudes : 50/1696 [00:02<01:23,   19.67it/s]
  4%|3         | cHPI amplitudes : 64/1696 [00:02<01:03,   25.83it/s]
  5%|5         | cHPI amplitudes : 85/1696 [00:02<00:45,   35.51it/s]
  6%|6         | cHPI amplitudes : 104/1696 [00:02<00:36,   43.47it/s]
  7%|7         | cHPI amplitudes : 119/1696 [00:02<00:31,   50.62it/s]
  8%|8         | cHPI amplitudes : 138/1696 [00:02<00:25,   60.10it/s]
  9%|9         | cHPI amplitudes : 158/1696 [00:03<00:22,   68.58it/s]
 10%|#         | cHPI amplitudes : 173/1696 [00:03<00:19,   76.26it/s]
 11%|#1        | cHPI amplitudes : 194/1696 [00:03<00:17,   87.65it/s]
 13%|#2        | cHPI amplitudes : 215/1696 [00:03<00:14,   99.41it/s]
 13%|#2        | cHPI amplitudes : 216/1696 [00:03<00:15,   96.86it/s]
 14%|#3        | cHPI amplitudes : 232/1696 [00:03<00:13,  106.03it/s]
 15%|#4        | cHPI amplitudes : 251/1696 [00:03<00:12,  117.52it/s]
 16%|#5        | cHPI amplitudes : 269/1696 [00:03<00:11,  124.33it/s]
 17%|#6        | cHPI amplitudes : 283/1696 [00:03<00:10,  132.64it/s]
 18%|#7        | cHPI amplitudes : 303/1696 [00:03<00:09,  145.56it/s]
 19%|#8        | cHPI amplitudes : 322/1696 [00:03<00:08,  158.05it/s]
 19%|#9        | cHPI amplitudes : 323/1696 [00:03<00:08,  152.69it/s]
 20%|#9        | cHPI amplitudes : 336/1696 [00:03<00:08,  160.99it/s]
 21%|##        | cHPI amplitudes : 355/1696 [00:03<00:07,  174.43it/s]
 22%|##1       | cHPI amplitudes : 372/1696 [00:03<00:07,  178.74it/s]
 23%|##2       | cHPI amplitudes : 386/1696 [00:03<00:06,  188.15it/s]
 24%|##3       | cHPI amplitudes : 407/1696 [00:03<00:06,  203.91it/s]
 25%|##5       | cHPI amplitudes : 427/1696 [00:03<00:06,  209.36it/s]
 26%|##6       | cHPI amplitudes : 442/1696 [00:03<00:05,  219.87it/s]
 27%|##7       | cHPI amplitudes : 463/1696 [00:03<00:05,  236.21it/s]
 28%|##8       | cHPI amplitudes : 481/1696 [00:03<00:05,  238.14it/s]
 29%|##9       | cHPI amplitudes : 496/1696 [00:03<00:04,  248.80it/s]
 30%|###       | cHPI amplitudes : 515/1696 [00:03<00:04,  263.51it/s]
 31%|###1      | cHPI amplitudes : 533/1696 [00:03<00:04,  263.90it/s]
 32%|###2      | cHPI amplitudes : 545/1696 [00:03<00:04,  271.43it/s]
 33%|###2      | cHPI amplitudes : 559/1696 [00:03<00:04,  281.51it/s]
 34%|###3      | cHPI amplitudes : 573/1696 [00:03<00:04,  276.45it/s]
 35%|###4      | cHPI amplitudes : 586/1696 [00:03<00:03,  285.38it/s]
 35%|###5      | cHPI amplitudes : 600/1696 [00:03<00:03,  295.46it/s]
 36%|###6      | cHPI amplitudes : 613/1696 [00:03<00:03,  288.45it/s]
 37%|###6      | cHPI amplitudes : 627/1696 [00:03<00:03,  298.67it/s]
 38%|###7      | cHPI amplitudes : 642/1696 [00:03<00:03,  310.28it/s]
 39%|###8      | cHPI amplitudes : 656/1696 [00:04<00:03,  302.48it/s]
 39%|###9      | cHPI amplitudes : 669/1696 [00:04<00:03,  311.77it/s]
 40%|####      | cHPI amplitudes : 681/1696 [00:04<00:03,  319.96it/s]
 41%|####1     | cHPI amplitudes : 696/1696 [00:04<00:03,  312.49it/s]
 42%|####1     | cHPI amplitudes : 709/1696 [00:04<00:03,  321.87it/s]
 43%|####2     | cHPI amplitudes : 723/1696 [00:04<00:02,  332.50it/s]
 43%|####3     | cHPI amplitudes : 737/1696 [00:04<00:02,  322.60it/s]
 44%|####4     | cHPI amplitudes : 752/1696 [00:04<00:02,  334.24it/s]
 45%|####5     | cHPI amplitudes : 767/1696 [00:04<00:02,  346.36it/s]
 46%|####6     | cHPI amplitudes : 781/1696 [00:04<00:02,  335.27it/s]
 47%|####6     | cHPI amplitudes : 794/1696 [00:04<00:02,  344.64it/s]
 48%|####7     | cHPI amplitudes : 807/1696 [00:04<00:02,  353.96it/s]
 48%|####8     | cHPI amplitudes : 821/1696 [00:04<00:02,  341.97it/s]
 49%|####9     | cHPI amplitudes : 835/1696 [00:04<00:02,  352.80it/s]
 50%|#####     | cHPI amplitudes : 848/1696 [00:04<00:02,  362.52it/s]
 51%|#####     | cHPI amplitudes : 861/1696 [00:04<00:02,  347.70it/s]
 52%|#####1    | cHPI amplitudes : 874/1696 [00:04<00:02,  357.30it/s]
 52%|#####2    | cHPI amplitudes : 889/1696 [00:04<00:02,  369.39it/s]
 53%|#####3    | cHPI amplitudes : 904/1696 [00:04<00:02,  356.92it/s]
 54%|#####4    | cHPI amplitudes : 917/1696 [00:04<00:02,  366.20it/s]
 55%|#####5    | cHPI amplitudes : 933/1696 [00:04<00:02,  379.82it/s]
 56%|#####5    | cHPI amplitudes : 945/1696 [00:04<00:02,  362.55it/s]
 57%|#####6    | cHPI amplitudes : 960/1696 [00:04<00:01,  374.96it/s]
 58%|#####7    | cHPI amplitudes : 980/1696 [00:04<00:01,  394.30it/s]
 59%|#####8    | cHPI amplitudes : 1000/1696 [00:04<00:01,  385.56it/s]
 60%|#####9    | cHPI amplitudes : 1015/1696 [00:04<00:01,  397.60it/s]
 61%|######1   | cHPI amplitudes : 1035/1696 [00:04<00:01,  416.50it/s]
 62%|######2   | cHPI amplitudes : 1054/1696 [00:04<00:01,  404.41it/s]
 63%|######2   | cHPI amplitudes : 1068/1696 [00:04<00:01,  414.78it/s]
 64%|######4   | cHPI amplitudes : 1088/1696 [00:04<00:01,  433.77it/s]
 65%|######5   | cHPI amplitudes : 1107/1696 [00:05<00:01,  419.72it/s]
 66%|######6   | cHPI amplitudes : 1122/1696 [00:05<00:01,  431.15it/s]
 67%|######7   | cHPI amplitudes : 1142/1696 [00:05<00:01,  449.91it/s]
 68%|######8   | cHPI amplitudes : 1160/1696 [00:05<00:01,  432.88it/s]
 69%|######9   | cHPI amplitudes : 1176/1696 [00:05<00:01,  445.41it/s]
 71%|#######   | cHPI amplitudes : 1197/1696 [00:05<00:01,  465.54it/s]
 72%|#######1  | cHPI amplitudes : 1217/1696 [00:05<00:01,  449.94it/s]
 73%|#######2  | cHPI amplitudes : 1232/1696 [00:05<00:01,  460.93it/s]
 74%|#######3  | cHPI amplitudes : 1252/1696 [00:05<00:00,  479.33it/s]
 75%|#######4  | cHPI amplitudes : 1269/1696 [00:05<00:00,  457.69it/s]
 76%|#######5  | cHPI amplitudes : 1284/1696 [00:05<00:00,  468.41it/s]
 77%|#######6  | cHPI amplitudes : 1305/1696 [00:05<00:00,  488.23it/s]
 78%|#######8  | cHPI amplitudes : 1326/1696 [00:05<00:00,  471.77it/s]
 79%|#######8  | cHPI amplitudes : 1338/1696 [00:05<00:00,  477.68it/s]
 80%|#######9  | cHPI amplitudes : 1351/1696 [00:05<00:00,  485.16it/s]
 80%|########  | cHPI amplitudes : 1364/1696 [00:05<00:00,  457.79it/s]
 81%|########1 | cHPI amplitudes : 1380/1696 [00:05<00:00,  470.05it/s]
 82%|########2 | cHPI amplitudes : 1399/1696 [00:05<00:00,  486.97it/s]
 84%|########3 | cHPI amplitudes : 1418/1696 [00:05<00:00,  467.44it/s]
 84%|########4 | cHPI amplitudes : 1433/1696 [00:05<00:00,  478.25it/s]
 86%|########5 | cHPI amplitudes : 1455/1696 [00:05<00:00,  499.30it/s]
 87%|########6 | cHPI amplitudes : 1475/1696 [00:05<00:00,  480.09it/s]
 88%|########7 | cHPI amplitudes : 1491/1696 [00:05<00:00,  492.24it/s]
 89%|########9 | cHPI amplitudes : 1512/1696 [00:05<00:00,  511.61it/s]
 90%|######### | cHPI amplitudes : 1534/1696 [00:05<00:00,  532.43it/s]
 91%|######### | cHPI amplitudes : 1535/1696 [00:05<00:00,  493.14it/s]
 91%|#########1| cHPI amplitudes : 1551/1696 [00:05<00:00,  505.18it/s]
 93%|#########2| cHPI amplitudes : 1572/1696 [00:05<00:00,  525.12it/s]
 94%|#########3| cHPI amplitudes : 1589/1696 [00:05<00:00,  498.43it/s]
 95%|#########4| cHPI amplitudes : 1605/1696 [00:05<00:00,  510.59it/s]
 96%|#########5| cHPI amplitudes : 1626/1696 [00:05<00:00,  530.66it/s]
 97%|#########7| cHPI amplitudes : 1647/1696 [00:05<00:00,  550.80it/s]
 97%|#########7| cHPI amplitudes : 1649/1696 [00:06<00:00,  509.30it/s]
 98%|#########8| cHPI amplitudes : 1666/1696 [00:06<00:00,  522.98it/s]
 99%|#########9| cHPI amplitudes : 1685/1696 [00:06<00:00,  540.39it/s]
100%|##########| cHPI amplitudes : 1696/1696 [00:06<00:00,  279.26it/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<25:11,    1.12it/s]
  2%|2         | cHPI locations  : 41/1696 [00:00<00:34,   47.42it/s]
  4%|4         | cHPI locations  : 69/1696 [00:00<00:21,   75.00it/s]
  6%|5         | cHPI locations  : 101/1696 [00:01<00:19,   83.02it/s]
  8%|8         | cHPI locations  : 136/1696 [00:01<00:13,  113.34it/s]
 10%|#         | cHPI locations  : 178/1696 [00:01<00:10,  150.86it/s]
 12%|#1        | cHPI locations  : 201/1696 [00:01<00:10,  136.25it/s]
 14%|#3        | cHPI locations  : 234/1696 [00:01<00:09,  152.45it/s]
 16%|#5        | cHPI locations  : 267/1696 [00:01<00:08,  176.56it/s]
 18%|#7        | cHPI locations  : 301/1696 [00:01<00:07,  175.82it/s]
 20%|#9        | cHPI locations  : 333/1696 [00:01<00:06,  197.46it/s]
 20%|#9        | cHPI locations  : 334/1696 [00:01<00:07,  188.07it/s]
 22%|##1       | cHPI locations  : 368/1696 [00:01<00:06,  211.91it/s]
 24%|##3       | cHPI locations  : 401/1696 [00:02<00:06,  206.31it/s]
 26%|##6       | cHPI locations  : 441/1696 [00:02<00:05,  233.05it/s]
 28%|##8       | cHPI locations  : 476/1696 [00:02<00:04,  245.94it/s]
 30%|##9       | cHPI locations  : 501/1696 [00:02<00:05,  228.19it/s]
 32%|###1      | cHPI locations  : 542/1696 [00:02<00:04,  253.76it/s]
 33%|###2      | cHPI locations  : 559/1696 [00:02<00:05,  219.05it/s]
 33%|###3      | cHPI locations  : 568/1696 [00:03<00:06,  181.54it/s]
 34%|###3      | cHPI locations  : 573/1696 [00:03<00:07,  157.44it/s]
 34%|###4      | cHPI locations  : 577/1696 [00:03<00:08,  134.15it/s]
 34%|###4      | cHPI locations  : 581/1696 [00:04<00:09,  112.62it/s]
 35%|###4      | cHPI locations  : 587/1696 [00:04<00:10,  102.60it/s]
 35%|###4      | cHPI locations  : 589/1696 [00:04<00:10,  100.69it/s]
 35%|###5      | cHPI locations  : 600/1696 [00:05<00:11,   94.10it/s]
 38%|###7      | cHPI locations  : 641/1696 [00:05<00:09,  107.37it/s]
 39%|###9      | cHPI locations  : 665/1696 [00:05<00:09,  113.05it/s]
 41%|####1     | cHPI locations  : 697/1696 [00:05<00:08,  123.94it/s]
 41%|####1     | cHPI locations  : 700/1696 [00:05<00:08,  112.58it/s]
 44%|####3     | cHPI locations  : 742/1696 [00:05<00:07,  126.96it/s]
 46%|####6     | cHPI locations  : 784/1696 [00:05<00:06,  141.93it/s]
 47%|####6     | cHPI locations  : 789/1696 [00:05<00:07,  125.69it/s]
 47%|####6     | cHPI locations  : 794/1696 [00:06<00:07,  114.67it/s]
 47%|####7     | cHPI locations  : 800/1696 [00:06<00:08,  102.96it/s]
 47%|####7     | cHPI locations  : 805/1696 [00:06<00:09,   95.37it/s]
 48%|####7     | cHPI locations  : 810/1696 [00:07<00:10,   88.41it/s]
 48%|####8     | cHPI locations  : 815/1696 [00:07<00:10,   80.65it/s]
 48%|####8     | cHPI locations  : 819/1696 [00:07<00:11,   75.40it/s]
 49%|####8     | cHPI locations  : 823/1696 [00:08<00:12,   68.86it/s]
 49%|####8     | cHPI locations  : 827/1696 [00:08<00:13,   62.23it/s]
 49%|####9     | cHPI locations  : 833/1696 [00:09<00:14,   59.36it/s]
 50%|#####     | cHPI locations  : 848/1696 [00:09<00:14,   58.64it/s]
 52%|#####2    | cHPI locations  : 889/1696 [00:09<00:11,   67.85it/s]
 52%|#####2    | cHPI locations  : 890/1696 [00:09<00:12,   67.03it/s]
 54%|#####4    | cHPI locations  : 921/1696 [00:09<00:10,   74.50it/s]
 56%|#####5    | cHPI locations  : 948/1696 [00:09<00:09,   75.74it/s]
 58%|#####8    | cHPI locations  : 989/1696 [00:09<00:08,   85.91it/s]
 60%|######    | cHPI locations  : 1021/1696 [00:09<00:07,   92.69it/s]
 61%|######1   | cHPI locations  : 1040/1696 [00:10<00:07,   92.20it/s]
 62%|######1   | cHPI locations  : 1045/1696 [00:10<00:07,   91.69it/s]
 62%|######1   | cHPI locations  : 1051/1696 [00:10<00:07,   85.93it/s]
 63%|######2   | cHPI locations  : 1062/1696 [00:10<00:07,   82.10it/s]
 63%|######3   | cHPI locations  : 1072/1696 [00:11<00:07,   78.48it/s]
 64%|######4   | cHPI locations  : 1086/1696 [00:11<00:08,   76.09it/s]
 66%|######6   | cHPI locations  : 1127/1696 [00:11<00:06,   86.14it/s]
 68%|######7   | cHPI locations  : 1150/1696 [00:11<00:06,   90.59it/s]
 70%|######9   | cHPI locations  : 1181/1696 [00:11<00:05,   98.68it/s]
 70%|######9   | cHPI locations  : 1186/1696 [00:11<00:05,   92.39it/s]
 72%|#######2  | cHPI locations  : 1224/1696 [00:11<00:04,  102.56it/s]
 75%|#######4  | cHPI locations  : 1266/1696 [00:11<00:03,  114.35it/s]
 75%|#######5  | cHPI locations  : 1278/1696 [00:11<00:03,  115.84it/s]
 76%|#######5  | cHPI locations  : 1286/1696 [00:12<00:03,  110.64it/s]
 76%|#######6  | cHPI locations  : 1296/1696 [00:12<00:03,  101.61it/s]
 77%|#######6  | cHPI locations  : 1301/1696 [00:12<00:04,   94.70it/s]
 77%|#######7  | cHPI locations  : 1306/1696 [00:13<00:04,   88.37it/s]
 77%|#######7  | cHPI locations  : 1311/1696 [00:13<00:04,   82.75it/s]
 78%|#######7  | cHPI locations  : 1315/1696 [00:13<00:04,   77.57it/s]
 78%|#######7  | cHPI locations  : 1319/1696 [00:14<00:05,   72.93it/s]
 78%|#######8  | cHPI locations  : 1325/1696 [00:14<00:05,   69.15it/s]
 78%|#######8  | cHPI locations  : 1331/1696 [00:14<00:05,   64.63it/s]
 79%|#######9  | cHPI locations  : 1341/1696 [00:14<00:05,   62.47it/s]
 81%|########1 | cHPI locations  : 1378/1696 [00:14<00:04,   70.87it/s]
 84%|########3 | cHPI locations  : 1420/1696 [00:15<00:03,   80.88it/s]
 85%|########4 | cHPI locations  : 1441/1696 [00:15<00:03,   80.33it/s]
 85%|########5 | cHPI locations  : 1445/1696 [00:15<00:03,   79.82it/s]
 87%|########7 | cHPI locations  : 1479/1696 [00:15<00:02,   88.32it/s]
 89%|########9 | cHPI locations  : 1515/1696 [00:15<00:01,   97.73it/s]
 91%|######### | cHPI locations  : 1541/1696 [00:15<00:01,   97.36it/s]
 92%|#########2| cHPI locations  : 1565/1696 [00:16<00:01,   93.76it/s]
 93%|#########2| cHPI locations  : 1573/1696 [00:16<00:01,   88.50it/s]
 93%|#########3| cHPI locations  : 1580/1696 [00:16<00:01,   83.81it/s]
 94%|#########3| cHPI locations  : 1586/1696 [00:17<00:01,   79.32it/s]
 94%|#########3| cHPI locations  : 1590/1696 [00:17<00:01,   73.39it/s]
 94%|#########3| cHPI locations  : 1594/1696 [00:17<00:01,   69.35it/s]
 94%|#########4| cHPI locations  : 1599/1696 [00:17<00:01,   65.91it/s]
 95%|#########4| cHPI locations  : 1609/1696 [00:18<00:01,   63.73it/s]
 97%|#########6| cHPI locations  : 1637/1696 [00:18<00:00,   68.74it/s]
 97%|#########7| cHPI locations  : 1652/1696 [00:18<00:00,   67.40it/s]
 99%|#########9| cHPI locations  : 1684/1696 [00:18<00:00,   74.43it/s]
100%|##########| cHPI locations  : 1696/1696 [00:18<00:00,   90.66it/s]

Lastly, compute head positions from the coil locations:

Out:

t=9.000:     5/5 good HPI fits, movements [mm/s] =      0.1 /      0.1 /      0.5 /      0.2 /      0.3
t=10.000:    5/5 good HPI fits, movements [mm/s] =      0.1 /      0.3 /      0.0 /      0.2 /      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.1
t=14.000:    5/5 good HPI fits, movements [mm/s] =      0.0 /      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.9 /     39.9 /     38.1 /     30.4
t=14.720:    5/5 good HPI fits, movements [mm/s] =     48.9 /     47.9 /     60.5 /     59.3 /     44.5
t=14.760:    5/5 good HPI fits, movements [mm/s] =     65.3 /     63.1 /     72.9 /     71.0 /     55.8
t=14.800:    5/5 good HPI fits, movements [mm/s] =     66.7 /     59.2 /     82.9 /     78.0 /     61.4
t=14.860:    5/5 good HPI fits, movements [mm/s] =     54.3 /     52.1 /     57.8 /     61.9 /     47.1
t=14.990:    5/5 good HPI fits, movements [mm/s] =     23.4 /     22.5 /     24.0 /     27.1 /     19.8
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.6 /      3.4 /      2.9 /      3.8 /      3.3
t=16.930:    5/5 good HPI fits, movements [mm/s] =     51.9 /     55.3 /     58.0 /     67.4 /     59.1
t=16.990:    5/5 good HPI fits, movements [mm/s] =     56.9 /     53.7 /     62.2 /     64.8 /     57.8
t=17.040:    5/5 good HPI fits, movements [mm/s] =     53.8 /     50.1 /     60.0 /     61.9 /     49.4
t=17.090:    5/5 good HPI fits, movements [mm/s] =     57.5 /     50.1 /     66.6 /     64.8 /     51.6
t=17.140:    5/5 good HPI fits, movements [mm/s] =     60.5 /     54.7 /     72.6 /     67.3 /     57.6
t=17.180:    5/5 good HPI fits, movements [mm/s] =     63.7 /     61.6 /     74.4 /     72.3 /     61.6
t=17.220:    5/5 good HPI fits, movements [mm/s] =     60.8 /     57.4 /     75.5 /     71.2 /     63.4
t=17.260:    5/5 good HPI fits, movements [mm/s] =     68.0 /     65.5 /     73.4 /     69.0 /     69.3
t=17.320:    5/5 good HPI fits, movements [mm/s] =     49.4 /     50.5 /     55.0 /     54.9 /     52.3
t=17.470:    5/5 good HPI fits, movements [mm/s] =     18.6 /     21.3 /     19.2 /     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.2 /     19.4 /     28.8 /     27.6
t=19.610:    5/5 good HPI fits, movements [mm/s] =     21.2 /     25.6 /     21.8 /     31.7 /     31.5
t=19.710:    5/5 good HPI fits, movements [mm/s] =     21.7 /     20.6 /     23.0 /     29.7 /     27.6
t=19.850:    5/5 good HPI fits, movements [mm/s] =     16.5 /     14.7 /     18.7 /     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.5 /      1.7 /      1.7 /      2.0 /      1.9
t=21.950:    5/5 good HPI fits, movements [mm/s] =     25.8 /     26.9 /     24.1 /     32.0 /     26.3
t=22.000:    5/5 good HPI fits, movements [mm/s] =     65.6 /     59.5 /     46.5 /     64.9 /     52.1
t=22.050:    5/5 good HPI fits, movements [mm/s] =     60.5 /     61.9 /     51.0 /     69.2 /     57.9
t=22.100:    5/5 good HPI fits, movements [mm/s] =     61.0 /     65.9 /     58.5 /     74.9 /     64.5
t=22.140:    5/5 good HPI fits, movements [mm/s] =     74.7 /     74.2 /     62.3 /     80.1 /     67.8
t=22.180:    5/5 good HPI fits, movements [mm/s] =     63.6 /     59.3 /     53.3 /     67.6 /     54.1
t=22.240:    5/5 good HPI fits, movements [mm/s] =     38.6 /     39.0 /     36.7 /     47.7 /     42.1
t=22.300:    5/5 good HPI fits, movements [mm/s] =     41.9 /     40.3 /     33.3 /     47.5 /     39.1
t=22.400:    5/5 good HPI fits, movements [mm/s] =     31.9 /     28.5 /     22.2 /     30.8 /     24.9
t=23.400:    5/5 good HPI fits, movements [mm/s] =      1.8 /      1.8 /      1.1 /      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.5 /     11.5 /     13.1 /     10.9
t=24.720:    5/5 good HPI fits, movements [mm/s] =     30.2 /     33.2 /     31.7 /     38.8 /     35.2
t=24.790:    5/5 good HPI fits, movements [mm/s] =     31.2 /     35.9 /     33.1 /     42.9 /     40.9
t=24.850:    5/5 good HPI fits, movements [mm/s] =     37.6 /     41.1 /     35.7 /     45.2 /     42.1
t=24.890:    5/5 good HPI fits, movements [mm/s] =     50.2 /     51.3 /     49.5 /     59.9 /     53.2
t=24.930:    5/5 good HPI fits, movements [mm/s] =     55.5 /     55.2 /     59.1 /     68.2 /     62.0
t=24.980:    5/5 good HPI fits, movements [mm/s] =     47.4 /     47.6 /     51.1 /     58.8 /     53.8
t=25.080:    5/5 good HPI fits, movements [mm/s] =     23.7 /     19.2 /     23.1 /     28.1 /     26.3
t=25.510:    5/5 good HPI fits, movements [mm/s] =      2.4 /      6.5 /      7.4 /      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.

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

Estimated memory usage: 16 MB

Gallery generated by Sphinx-Gallery