Magnetic field compensation coil design for magnetoencephalography

While optically pumped magnetometers (OPMs) can be attached to the head of a person and allow for highly sensitive recordings of the human magnetoencephalogram (MEG), they are mostly limited to an operational range of approximately 5 nT. Consequently, even inside a magnetically shielded room (MSR), movements in the remnant magnetic field disable the OPMs. Active suppression of the remnant field utilizing compensation coils is therefore essential. We propose 8 compensation coils on 5 sides of a cube with a side length of approximately 2 m which were optimized for operation inside an MSR. Compared to previously built bi-planar compensation coils, the coils proposed in this report are more complex in geometry and achieved smaller errors for simulated compensation fields. The proposed coils will allow for larger head movements or smaller movement artifacts in future MEG experiments compared to existing coils.

Magnetoencephalography (MEG) acquires magnetic fields produced by neurons, directly and in real-time. Conventional MEG devices utilize superconducting quantum interference devices (SQUIDs) to measure magnetic fields with femtotesla sensitivity. To achieve super conductivity, these extremely sensitive devices are cooled with liquid helium. Hence, the SQUIDs and the helium are housed in a heavy and well insulated container. The housing of SQUIDs renders their arrangement rigid and creates an inhomogeneous distance, on the order of a few centimeters, between sensors and participants' heads. Recent achievements in optically pumped magnetometry bring a different type of sensor into play for MEG. Zero field optically pumped magnetometers (OPMs) currently achieve a sensitivity level comparable with SQUID systems 1 . In our lab, we use generation 2 QuSpin zero-field magnetometers. The distance between OPM sensors and participants heads is thereby reduced to less than 1 cm and the sensor arrangement is flexible 2 . Due to the smaller distance between sensors and brain sources, the spatial resolution of multi-channel OPM recordings will likely be superior to that of conventional multi-channel SQUID recordings 3,4 . OPM sensor caps or helmets allow participants to move their heads naturally during experiments 2 . It is possible that we will see a shift from fixed cryogenic MEG devices to wearable, motion robust OPM systems in the coming years 5 . This would open up the possibility of expanding MEG research to new participant groups, like infants or specific patient groups, and to new paradigms where head movements are necessary or encouraged 6,7 .
A limitation of current high sensitivity zero field OPMs is their small operational range. For example, the OPMs of our lab have an operational range of approximately ±5 nT . Due to the small operational range it is required that OPMs are operated inside a magnetically shielded room (MSR), to suppress the static earth magnetic field at the sensor positions. Inside an MSR each sensor can generate its own magnetic field by means of internal Helmholtz coils, to meet its operational range around absolute zero field. However, this internal field of each sensor is initially fixed before switching to its sensitive measurement mode. Small head movements in the range of a few millimeters in the remnant magnetic field inside an MSR can already disable the OPMs 2 . To address this head movement problem, compensation coils were built to actively suppress dominant field components of the remnant magnetic field in a volume for all OPMs simultaneously inside an MSR [8][9][10] . We describe an enhancement of previously built compensation coils. In the following, shielding refers to a passive field reduction by means of deflecting materials, whereas compensation refers to active field suppression by means of electric current driven coils. Large, high quality compensation coils for OPM recordings have previously been designed www.nature.com/scientificreports/ as bi-planar coils 2,8,10 . Bi-planar coils can reduce the remnant magnetic field sufficiently to even allow OPM recordings during head movement 8 . In a second report 10 , a simplified bi-planar system was designed and the effects of magnetic shielding on magnetic field compensation was investigated. It was found, that the magnetic fields of their coils were considerably effected by the presence of their MSR. This effect did not equally impact the field suppression performance of their coils, because coil interactions are modeled and taken into account during field suppression. In practice, their coils showed good field suppression performance. In contrast to 8,10 , we propose a coil design that is optimized for operation inside a magnetically shielded environment. To accomplish this we use a direct stream function discretization. With a more complex geometry, we aim at a better compensation in larger target volumes at the expense of a heavier and more elaborate construction compared to 8,10 . Direct stream function discretization provides more freedom in coil geometry and shield modeling. For example, contrary to 8,10 , symmetry is not a requirement. We aimed at compensation errors of ≤ 1% inside a sphere with diameter 0.6 m in simulations where magnetic shielding was taken into account. Consequently, we require accurate modeling of shielding effects with errors clearly below our compensation errors.

Coil design and evaluation
Preface. The starting point of our coil development was the bi-planar design described in 8 . We identified two potential enhancements, a more surrounding coil geometry and incorporation of the effect of an MSR on the magnetic field in coil optimization. For the geometry enhancement, we considered a cubic design because it allows simple construction. We decided to remove the front face of the cube to provide an easy entrance and exit and to avoid a locked in atmosphere for participants. In favor of a simple construction, we also decided to avoid coil wires over the complete lengths of the edges.
For the incorporation of magnetic shielding we followed up on a method described in 10 and implemented a method of images. Reference 10 did not incorporate magnetic shielding in their coil design. We implemented a different magnetic field modeling approach compared to 8,10 to model our coils. In the following sections, the details of designing and evaluating our compensation coils are described. The term compensation coil refers to one wire with one input and one output contact for electric current.
Our design methods were based on a magnetostatic approximation and we estimated its accuracy in our application. We defined a surface stream function discretization to express the magnetic field in a target grid as a matrix product. The shielding effects were taken into account by virtually mirroring our mesh on the MSR walls. Our coils were constrained to surfaces which were defined on five-sided cuboid meshes with a total side length of approximately 2 m. Our target volume for compensation was a sphere with diameter 0.6 m in the center of the cuboid. Optimization was computed by a regularized least squares regression of the stream function for a specified target field in a grid inside our target volume. Wiring paths of each coil were computed as contour lines of the optimized stream function. From the wiring paths, errors were computed against the target fields.
Magnetostatic approximation. We were aiming at manufacturing coils from enameled copper wire with diameter 1 mm , similar to 8,10 . The magnetic field components, that we were suppressing contain only frequencies below 100 Hz. For this frequency range, we simulated our fields in a magnetostatic approximation where B is the magnetic flux density and J is a quasi-stationary current density. For a time-dependent current density J(t) in copper wires, we derived an approximation error based on where E is the electric field. We assumed the electric field amplitude was maximal between two wire segments of opposing current direction close to the current supply of a coil loop, where the two segments are very close to each other. At the center between these segments, we estimate the electric field amplitude as where ρ = 1.72 × 10 −8 � m is the resistivity of copper at 20 • C , ℓ is the wire length, A its cross section and L is the coil inductance. In our coils, wire length was ℓ < 1 × 10 4 m and inductance was L < 1 × 10 −1 H . Our copper wire cross section was A ≈ 1 × 10 −6 m 2 . For a harmonic current density with a frequency of 100 Hz we set ∂ ∂t = 2π100 Hz. Finally, we estimated a worst-case gradient ∇ of 1 × 10 5 /m for two wires with only a coating of 1 × 10 −5 m between them. The relative magnetostatic approximation error δ stat resulted: Compared to our compensation error goal of 1%, δ stat is small. Hence, the magnetostatic approximation was sufficiently accurate for our application.

Stream function solution.
We planned to put our wires inside wooden boards where each coil is constrained to a given surface. This idea follows 8,10 , who glued the wire to their boards. We planned to increase accuracy in this manufacturing step by milling traces with a computer numerical control and putting the wire Scientific Reports | (2021) 11:22650 | https://doi.org/10.1038/s41598-021-01894-z www.nature.com/scientificreports/ inside. Wire paths for coils constrained to a surface and in the magnetostatic regime can be expressed as contour lines of a scalar stream function. We derive this relation in the following paragraph. For a current density J in magnetostatics, the continuity equation ∇ � J = 0 holds. In the xy-plane (for simplicity) this is A solution of this partial differential equation (5) follows from symmetry of second derivatives as j x = ∂S ∂y and j y = − ∂S ∂x , where S is a scalar function in the xy-plane. This can be expressed as which defines a scalar stream function S 11 . This stream function concept can be generalized to arbitrary surfaces, where ∇ is replaced by the tangential gradient operator on the surface and e z is replaced by the unit surface normal vector 12 . Stream lines of the surface current density J are, by definition, parallel to ∇S × � e z and hence perpendicular to ∇S . That means, contour lines of S are stream lines of J 12 . Since wire paths are stream lines of a current density, contour lines of S defined our coil wire paths. We used a quadrilateral mesh to discretize stream function surfaces. For each element, the stream function was described by a bilinear function which was determined by the values at the four vertices. However, the continuity equation for current density holds for any twice continuously differentiable function S. Considering a standard square with side length l = 1 m in a Cartesian coordinate system (x, y, z). For z = 0 and x, y ∈ [0, l] × [0, l] and a stream function S ∝ xy , the magnetic field can be expressed as (Biot-Savart): where a is the thickness of the volume on the z axis, which approaches zero, dV ′ = dx ′ dy ′ dz ′ and is the volume element, S ′ is the stream function in that volume, ∇ ′ operates on x ′ , y ′ . Although all integrals in (8) can be expressed in closed-form, we faced numerical problems in their expressions. We decided to use a 4 × 4 point Gauss-Legendre quadrature rule for these integrals instead. At a target point r the magnetic field was computed for each single vertex of our quadrilateral mesh with a stream function value of 1 A/m at that vertex and zero at all other vertices. This allowed us to compute the magnetic field at M target points r 1 . . . r M as a matrix product of a matrix B , denoted as a forward matrix, containing the solutions of (8) and a vector s containing the stream function values of all N vertices: A part of an example stream function vector is depicted in Fig. 1.

Geometry and mesh.
Constraining surfaces of our coils were derived from a base cube surface of 2 m side length. One face of the cube was removed for coil surfaces, specifically the front where participants can enter the cube. This front side faced the door of the MSR. The remaining surface, with 5 faces, was subdivided in 20 × 20 square elements on each face of the cube. Elements at the 8 edges of this mesh were removed in favor of a simpler construction. Only the 4 center elements of those edges were kept allowing the current to go from one face to another. In Fig. 3 our final mesh is depicted inside and mirrored on the MSR walls. The dimensions of our MSR were 3.002 m × 4.002 m × 2.452 m and our mesh was centered inside on the x and z axes and shifted off-center 0.65 m negatively on the y axis (to the front). We planned to arrange 8 coils in our 5 boards. Practically, it is not possible to lay 8 coils on a single depth in the boards. We decided to lay 4 coils in the inside and 4 in the outside of our boards and to allocate one depth for 2 coils in our boards. Hence, we had 4 depths −7.5 mm, −4.5 mm, 4.5 mm and 7.5 mm for our coils around the base cube of side length 2 m. The different depths were realized by scaling the base cube side lengths from 2 to 1.9925 m, 1.9955 m, 2.0045 m and 2.0075 m. This is implemented in according shifts of the base mesh and results in 4 slightly different meshes for our computation. The mesh for one coil consisted of 1905 vertices and 1724 square elements. Columns of the forward matrix were only defined for the 1537 non-boundary vertices. This is because stream function contour lines must not cross the boundary and hence the stream function must be constant at a boundary. from coil geometries, the sides of our MSR are referred to as walls. The walls of the MSR consisted of two sheets of µ-metal to shield the static and low frequency components of the magnetic field (mainly the earth's magnetic field). Relative permeability µ r of µ-metal is high, typically > 8 × 10 4 , while that of air is approximately 1. The effect of an abrupt change in permeability from air to µ-metal on the magnetic field can be described by the following two differential equations and the material equation � B = µ r µ 0 � H , where J f is the free current density, which is zero in µ-metal and air. According to Gauss's law in (10), there is no discontinuity in the normal component of magnetic flux density B across the boundary between air and µ-metal. There is also no discontinuity in the tangential component of H across this boundary according to Ampere's law in (11). Both differential equations, together with the material equation, require an abrupt change of magnetic field direction across the boundary of air and µ-metal. The magnetic field enters the µ-metal boundary nearly perpendicular from the air side and is nearly tangential to that boundary inside the µ-metal 13 . To simulate the effect of µ-metal on the magnetic field at the air side, a method of images can be applied 8 . That is, currents inside the MSR are mirrored on the MSR walls. The sensitivity of this method to the value of µ r is small here since the simulation errors scale with µ −1 r , which is negligible for µ -metal 10 .
Since µ-metal is mounted on all 6 walls of the MSR, mirroring of a current across one wall requires mirroring of the mirrored current across the other walls and so on. Theoretically, the mirroring proceeds to infinity for an accurate simulation. Practically, it can be truncated at a certain level of accuracy because the distance r of the mirrored currents to the target volume increases with each level and hence the effect on the magnetic field decreases with r −1 . To determine the level of truncation, we introduced a set of indices L for a level of mirroring. Elements of L are triples of integer numbers representing the number of sequential mirroring along one of the three spatial axes. The sign of a number indicated the direction on the axis. For example, the element (0, 1, −2) represented a mirroring across the wall in positive y direction followed by a mirroring across the wall in positive z direction, and a second mirroring across the wall in negative z direction. A set of mirrorings, up to a total order of P, was defined as where (k, l, m) are the mirroring indices on x, y, z axes for the stream function mesh. Table 1 lists the total number of mirrorings for different levels n and the number of additional mirroring compared to the preceding level n − 1 in columns 2 and 3 respectively. That is, column 3 reveals the increase in total mirrorings from one level to the next. Figure 3 depicts level 1 mirroring of a surface mesh on the MSR. Target field. An equidistant grid of points was defined within a centered cube and all grid points within the centered sphere of diameter d defined the target set. This method defined a volumetric equidistant sampling of a spherical volume. For stream function optimization, a target grid T opt was defined with a diamater of 0.7 m and sampling distance of 0.045 m. Similarly for validation T val was defined with 0.6 m and sampling distance of 0.025 m. T opt and T val were disjoint sets in order to avoid inverse crime. T val was more fine grained than T opt to validate the interpolation of our optimization. The number of grid points in the two sets were |T opt | = 1904 , |T val | = 7088 . Cross sections of the target grids are depicted in Fig. 4.
The actual target fields for optimization were defined for all � r ∈ T opt = {� r 1 . . . � r M } as     Stream function optimization and wire paths. As defined in (13) a forward matrix B L n was computed for all target points � r ∈ T and for all non-boundary vertices of our stream function discretization, with a level n mirroring. Coil wires must not cross the border of the mesh and hence for each target field vector b target , a regularized least squares solution of the stream function vector ŝ was found from a pseudoinverse B + : where α is a weighting parameter, is a regularization parameter, I is an identity matrix, with its diagonal length equal to the length of the non-boundary stream function vector, here 1537. The weighting parameter α was set such that Boundary stream function values were set to zero. Contour lines of the so found stream function formed the wire paths on our meshes. The pseudoinverse in (23) was computed from a singular value decomposition of the forward matrix. For reproducibility the number of contour lines and regularization parameters of our coil optimization are listed in Table 2. Wire paths of one coil ( C z, hom ) are depicted in Fig. 5.
Error estimates. The relative difference measure (RDM) measures differences in field topography 14 . It is defined as As a second informative topography difference measure, which was also reported in 8,10 , the maximum relative difference was computed as To quantify field magnitudes of different levels of mirroring i, j, we computed the magnification (MAG) as Efficiency. Coil efficiency was computed for each coil as where b(I) is the magnetic field vector at the target points dependent on the current I in a coil and b target is a unit-less target field vector derived from one right hand side of Eqs. (14) to (21). It is the averaged field or gradient at the target points per coil current.

Results
Convergence of the magnetic field at target points with increasing levels of mirroring is depicted in Fig. 6a,b. For each level of mirroring, the RDM and MAG was computed against the preceding level for each field component, x, y, z. Boxes labeled as k a , depict the RDM k n a or MAG k n a over all n = 1 . . . N surface vertices, where k is the level of mirroring and a is one of the axes x, y, z. Formally these RDMs were computed as RDM k n a = RDM b k n a , b k−1 n a , where b k n a = b n #a L k , b n #a+3 L k . . . is every third element of the nth row of B L k , #x = 1, #y = 2, #z = 3 . Corresponding expressions apply for MAGs. For a level of mirroring of 7, the maximum RDM to the preceding level was 0.8% and according median values were ≈ 0.01%. These values represented the accuracy we were aiming for. The MAGs for a level of mirroring of 7 were between 98.8 and 100.0%. In contrast, single mirroring on each wall, level 1, compared to no mirroring at all resulted in a maximum RDM of 70% and a maximum MAG of 312%. Figure 7 demonstrates the reliability of the mirroring approach in terms of field boundary conditions. Therefore, the field vectors were evaluated at 100 points on each MSR wall. The evaluation points were placed at the 9th order Gauss-Legendre quadrature points in each wall.
The fields of our coils in the validation grid were compared against a boundary element method (BEM) solution. For the BEM computation, the boundary between air the inner µ-metal sheet was triangulated with 14,506 triangles. The relative permeability of the µ-metal was set to 80,000 and the Neumann boundary conditions were  www.nature.com/scientificreports/ modeled with discontinuous constant shape functions on the triangles. In Fig. 8 a comparison of coil mirroring and BEM is depicted over the mirroring level. Table 3 lists compensation errors, RDMs and maximum relative differences (MRDs), for our 8 coils in our validation target volume T val with diameter 0.6 m. RDMs and MAGs were computed over all target grid points and all spatial field components x, y, z for each coil. For a mirroring level of 7, RDMs were between 0.03 and 0.77%, MRDs between 0.05 and 1.10%. For a level of 7 the errors were small because the coils were optimized     Table 4 the efficiency and wire length are listed for each coil. The efficiency is the average field or gradient in the target volume T val per coil current. There were correlations of 99% and 91% between efficiency and wire length for homogeneous and gradient coils, respectively. After correcting for direct proportionality between efficiency and wire length, gradient coils optimized for a gradient on the y axis were less efficient compared to other gradient coils. An explanation for this might be that, to the y axis, only one coil surface side was perpendicular whereas to the x and z axes, two sides were perpendicular.

Discussion
We developed a framework to design compensation coils of arbitrary shape with quadrilateral meshes of coil surfaces. In this framework, shielding effects are incorporated by a method of images in coil optimization. Our design is based on a cuboid surface with 5 faces and a side length of approximately 2 m. However, our design methods can be applied to bi-planar coils or any wire distributions constrained to surfaces. The maximum MRD in T val was 1%, which matches our compensation error goal.
Our simulations of shielding effects by mirroring of currents converged with an increasing mirroring level. Fields in our target grid resulting from different levels of mirroring were compared. Between mirroring levels 6 and 7, their RDMs were clearly below our compensation error goal of 1%, with upper quartiles below 0.1%. The boundary conditions on the boundary between air and µ-metal in our MSR require almost perpendicular magnetic field vectors to the boundary surface. This condition was evaluated for 600 points on the boundary surface. The deviation from this boundary condition was reduced by an increasing mirroring level. For a mirroring level of 7, it was found that this condition was well fulfilled for field vectors with large magnitudes. For small magnitudes, the angle is not well defined numerically and the effect of deviations from the boundary condition on the target field is small. The results of the mirroring approach in our target volume were further confirmed by a corresponding BEM computation. With increasing mirroring level, the RDMs of fields from the mirroring approach and BEM in the target grid converged to values below 0.1%. A limitation of this method of images is that it cannot account for the second µ-metal sheets, which are at different distances from a point inside the MSR. It also does not account for the thickness of µ-metal sheets. A theoretical requirement of this method is that the shielding surface is closed, which was not entirely the case in practice. There were several holes and discontinuities in the µ-metal sheets of our MSR, for example holes for cables, ventilation, video projector light, a helium tube, and discontinuities in the door frame. Effects of these limitations and unmet requirements are a study on their own and are not part of this paper. To account for the mentioned conditions, other numerical methods like boundary element or finite element methods can be applied and validated against empirical data.
The difference between our shielding effect simulations and the methods described in 10 is that we incorporated these simulations in coil optimizations. That is, our coils were optimized for a specific magnetically shielded environment, our MSR. Reference 10 reported simulated and measured shielding effects on coil performances whereas their coils were optimized for an unshielded environment. To simulate shielding effects on their coil performances, they used a method of images with a mirroring level of 3. Their MSR is of the same dimensions as ours, in fact it is the same model, produced by the same company. They compared shielding simulations with empirically measured data inside their MSR and found good agreement between simulation and measurement. Once the coils are build and in place, we will also compare our simulations with measured data.
Compared to 10 , we evaluated the effect of shielding on our coil performance in reverse. That is, for our coils, which were optimized for a position inside our MSR, compensation errors were computed for an unshielded environment, as listed in the last two columns in Table 3. This revealed the importance of incorporating shielding effects in coil designs. These error values are comparable to the reverse findings of 10 with coils optimized for an unshielded environment and error computation with shielding.
Recently, an open source software was released that is able to model arbitrary coil surface geometries and incorporate magnetic shielding in coil designs 15 . In this paper, we describe and evaluate specific coils whereas 15 implemented a generic tool for coil designs. In retrospect, the methods of 15 could be applied to our modeling problem but were unavailable to us at that time. We expect that it is straightforward to reproduce our coils and results from our description by using this software and to end up with similar coils. However, this has not been tested yet. In contrast to 15 , we use quadrilaterals instead of triangles for surface discretization and we model www.nature.com/scientificreports/ magnetic shielding by a method of images instead of using collocation points for a scalar potential close to the shielding surface. Quadrilaterals are a natural discretization choice for our cuboid geometry. Compared to a scalar potential method, a method of images does not have to deal with singularities at the shielding surface.

Conclusion
We proposed compensation coil designs that achieved higher accuracy in a larger target volume compared to reported results for similar dimensions 8,10 . Improved compensation compared to 8,10 came at the price of a more complex construction. We will compare our simulations with empirically measured fields inside our MSR in the future.