README This repository contains Matlab scripts and data necessary to reproduce the results described in the paper: “Localizing On-scalp MEG Sensors using an Array of Magnetic Dipole Coils” by Christoph Pfeiffer, Lau Møller Andersen, Daniel Lundqvist, Matti Hämäläinen, Justin F. Schneiderman, and Robert Oostenveld. Abstract: Accurate estimation of the neural activity underlying magnetoencephalography (MEG) signals requires co-registration i.e., determination of the position and orientation of the sensors with respect to the head. In modern MEG systems, an array of hundreds of low-Tc SQUID sensors is used to localize a set of small, magnetic dipole-like (head-position indicator, HPI) coils that are attached to the subject’s head. With accurate prior knowledge of the positions and orientations of the sensors with respect to one another, the HPI coils can be localized with high precision, and thereby the positions of the sensors in relation to the head. With advances in magnetic field sensing technologies, e.g., high-Tc SQUIDs and optically pumped magnetometers (OPM), that require less extreme operating temperatures than low-Tc SQUID sensors, on-scalp MEG is on the horizon. To utilize the full potential of on-scalp MEG, flexible sensor arrays are preferable. Conventional co-registration is impractical for such systems as the relative positions and orientations of the sensors to each other are subject-specific and hence not known a priori. Herein, we present a method for co-registration of on-scalp MEG sensors. We propose to invert the conventional co-registration approach and localize the sensors relative to an array of HPI coils on the subject’s head. We show that given accurate prior knowledge of the positions of the HPI coils with respect to one another, the sensors can be localized with high precision. We simulated our method with realistic parameters and layouts for sensor and coil arrays. Results indicate co-registration is possible with sub-millimeter accuracy, but the performance strongly depends upon a number of factors. Accurate calibration of the coils and precise determination of the positions and orientations of the coils with respect to one another are crucial. Finally, we propose methods to tackle practical challenges to further improve the method. (submitted to PLOS one; DOI: unknown). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Instructions: To run the simulation execute “HpiLoc_runAll.m”. Due to the high computational effort it is advisable to execute the different “hpiloc_”-functions in separate runs by commenting the functions that are not to be executed. The simulation requires the toolbox “FieldTrip”. A zipped version of the of FieldTrip version used to generate the results presented in the paper is provided (“fieldtrip-master.zip”).