Skip to main content
NIHPA Author Manuscripts logoLink to NIHPA Author Manuscripts
. Author manuscript; available in PMC: 2025 Apr 22.
Published in final edited form as: Brain Stimul. 2025 Jan 2;18(1):128–130. doi: 10.1016/j.brs.2024.11.011

A BEM-FMM TMS Coil Designer Using MATLAB Platform

Dexuan Tang a, William Wartman a, Aapo Nummenmaa b, Mohammad Daneshzand b, Gregory M Noetscher a, Hanbing Lu c, Zhi-De Deng d, Sergey N Makaroff a,b,e
PMCID: PMC12013522  NIHMSID: NIHMS2070520  PMID: 39755366

Dear Editor,

Simulations are used alongside experimental measurements in designing transcranial magnetic stimulation (TMS) coils. Software such as SimNIBS [1] are limited to predefined conductor paths. Tools like Kl/Codein Box [2] support user defined centerlines but lack flexibility and easy ways to convert a surface mesh of a coil into such centerlines. While computer-aided-engineering programs (e.g., Ansys Maxwell, FreeCAD EM Workbench) offer the ability to generate both CAD models and models for finite element analysis, require the user to possess advanced knowledge of the software. To simplify CAD-to-TMS modeling, we developed a standalone MATLAB-based program that simulates fields and inductances for coils and arrays, using user-defined centerlines, surface meshes, and outputs the simulated magnetic vector potentials as a NIfTI file for compatibility with other tools. Our software has been compared with experimental results and serves as a flexible platform for new coil designs and computational models of existing coils. Our toolbox does not simulate AC effects, which may impact simulation results of coils with magnetic cores, and coils with exceptionally large copper cross sections [11].

Our graphical user interface (GUI) offers two workflows with detailed demonstration videos in the supplementary material A:

  1. Definition of a coil in terms of one or more conductor centerlines and a wire cross-section. Current source models are distributed uniformly throughout the wire cross-section at each point on the centerline to create a high-fidelity model [5].

  2. Skeletonization of imported CAD coil models to create conductor centerlines, reconstructing the computational mesh with user-defined cross-sections (Fig. 1a).

Figure 1.

Figure 1.

a). Typical workflow with centerline extraction; b). E-field magnitude just inside a sphere center by an H-Coil in V/m c). Plane fields set up for a three-axis coil radiator; d). The resulting E-field magnitude in the plane defined in Fig. 1c in V/m; e). Example of coil array import into full-scale TMS software. Center of a 5 cm wide ROI is marked by a blue sphere; f)-i). Electric field magnitude within the ROI when X (red in Fig. 1e) and Y (green in Fig. 1e) windings of radiator #1 and #2, respectively, are driven independently and with the same current strength; j). Experimental comparison setup with the NKI E-field probe under a MagVenture C-B60 coil; k). Observation points over the sphere; l). Dominant field component for each observation point.

In addition to computing fields in air, a conductive sphere can be placed to visualize the electric field just inside its surface and the magnetic field on its surface, computed by the boundary element fast multipole method (BEM-FMM) [4]. For multi-coil arrays, the electric and magnetic field computed is the sum of the fields produced by each coil, with the current and its time derivative defined for each individual coil. The mutual inductances of multi-coil arrays are computed by solving the Neumann formula using FMM [5].

The ability to extract centerlines from coil surface meshes is based on the Laplacian smoothing mesh contraction method from Ref. [3]. The extracted centerlines along with a cross-section are used to reconstruct current dipoles for electromagnetic modeling [5].

The coil models designed with the present software can be straightforwardly imported into existing software packages (e.g., [4],[7]) to perform TMS computations with head models created from MRI scans with 1M computational surface elements or more. Coil design data files generated by our tool can be imported into an iterative BEM-FMM solver [4], a fast direct BEM-FMM solver [7], or other software such as SimNIBS in NIfTI format.

Fig. 1a demonstrates a MagVenture C-B60 coil, extracted from a CAD model, positioned above a 70mm sphere (experimental setup in Fig. 1j). Fig. 1k shows electric field just inside the sphere. We compared our model to a physical coil through inductance measurement without the coil cable using an LCR meter (NF Corporation ZM2376) at 1 kHz, and electric field sampled at 1,000 points on the surface of the 70mm-radius hemisphere, positioned 20mm from the coil base using the NKI triangular E-field probe [6] (Fig. 1j) and the procedure in [7]. A MagPro X100 stimulator was used to drive the coil with a current rate of change of 75×106A/s.

The measured inductance of the C-B60 coil was 12.76μH compared to 12.60μH simulated, only 1.25% lower. Fig. 1l compares the dominant component, Eθ, of the measured and simulated E-field for all points. Strong correlation is visible and the 2-norm relative field error for the entire upper hemisphere does not exceed 13%.

An H1-coil CAD mesh was imported into the software to test centerline extraction. The difference in the self-inductance between the original and extracted coil models was negligible (17.42μH vs 17.40μH). When compared against ANSYS Maxwell 3D 2022 R1, the resultant inductance was found to be 17.649 μH - a relative error of 0.83% from the FMM result. Similar results have been obtained with other coils tested.

A practical example in Fig. 1c shows a three-axis coil radiator [8] with three independent orthogonal windings (X, Y, and Z). Fig. 1d demonstrates electric field magnitude results simulated by our tool. All windings were driven with equal currents. The self-inductances of the three-axis coil array in μH are Lxx = 13.3, Lyy = 12.2, Lzz = 14.6, which is in good agreement with experimental results [8]. Mutual inductance results for several simple arrays of concentric rings agreed with theoretical predictions [9] to within 0.1%.

Fig. 1e shows an array of two three-axis coil radiators imported into the software in [4]. Then, the electric field on a mid-surface between gray and white matter for Connectome subject 110411 [10], segmented with SimNIBS software, was computed for a 5cm wide region of interest (ROI) with the center marked by a blue sphere, shown in Fig. 1e. Figs. 1f1i demonstrate electric field magnitude within ROI when X (red in Fig. 1e) and Y (green in Fig. 1e) windings of both radiators are driven independently with equal current.

Compared to Kl/Codein Box, our software offers higher fidelity by modeling the current distribution throughout the conductor cross-section as opposed to only on the centerline. It also offers greater flexibility in centerline extraction, conductor cross-section customization, and visualization with user-definable ROIs and resolutions. Our toolbox’s computation time for a C-B60 coil with 10,021 centerline points on an Intel Xeon Gold 5317 CPU is 3.069 seconds with cross-section compared to Kl/Codein’ s 39.69 seconds for centerline only. The relative 2-norm difference between the toolboxes is 2% when our software is permitted to distribute current throughout the cross-section, and the error decreases to 0.84% for the same case when our toolbox uses an artificially thin conductor to emulate Kl/Codein Box’s method.

Our software aims to simplify CAD-to-TMS simulations by providing users with a flexible GUI for TMS modeling using the BEM-FMM solution engine. Our software has been experimentally compared and could become a useful resource for advancing TMS modeling and exploring novel coil configurations in brain stimulation research.

Supplementary Material

Supplementary Video #1
Download video file (1.3MB, mp4)
Supplementary Video #2
Download video file (3.4MB, mp4)
Supplementary Video #3
Download video file (3.3MB, mp4)

Acknowledgements

This study has received support from the NIMH grant R01MH130490 (SNM), NIDCD grant R01DC020891 (ARN), as well as the Intramural Research Program of NIH, NIMH ZIAMH002955 (Z-DD), and Intramural Research Program of NIH, NIDA ZIADA000638 (HL)

Footnotes

Conflict of interest statement:

There are no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Data availability statement

  1. The software package along with video examples are available on GitHub: https://github.com/dexuantang/BEM-FMM-CoilDesigner

  2. Supplement A: Video examples of workflow i). and ii)., as well as NIfTI saving feature.

References:

  • [1].Drakaki M, Mathiesen C, Siebner HR, Madsen K, and Thielscher A. Database of 25 validated coil models for electric field simulations for TMS. Brain Stimulation 2022;15:697–706. doi: [DOI] [PubMed] [Google Scholar]
  • [2].Köhler M and Götz S. TMS coil design instrument (Kl/Codein Box): A toolbox for creating user-defined coils from conductor path data. Brain Stimulation 2023;16:698–700. doi: 10.1016/j.brs.2023.02.011. [DOI] [PubMed] [Google Scholar]
  • [3].Au O KC, Tai C-L, Chu H-K, Cohen-Or D, Lee T-Y. 2008. Skeleton extraction by mesh contraction. ACM Trans. Graph. 27, 3 (August 2008), 1–10. 10.1145/1360612.1360643 [DOI] [Google Scholar]
  • [4].Makarov SN, Wartman WA, Daneshzand M, Fujimoto K, Raij T, Nummenmaa A. A software toolkit for TMS electric-field modeling with boundary element fast multipole method: an efficient MATLAB implementation. J Neural Eng. 2020. Aug 4;17(4):046023. doi: 10.1088/1741-2552/ab85b3. . [DOI] [PubMed] [Google Scholar]
  • [5].Morales L, Wartman WA, Ferreira J, Miles A, Daneshzand M, Lu H, Nummenmaa AR, Deng ZD, Makaroff SN. Software Package for Transcranial Magnetic Stimulation Coil and Coil Array Analysis and Design. bioRxiv [Preprint]. 2023. Aug 21:2023.08.20.554037. doi: 10.1101/2023.08.20.554037. . [DOI] [Google Scholar]
  • [6].Makaroff SN, Qi Z, Rachh M, Wartman WA, Weise K, Noetscher GM, Daneshzand M, Deng ZD, Greengard L, Nummenmaa AR. A fast direct solver for surface-based whole-head modeling of transcranial magnetic stimulation. Sci Rep. 2023. Oct 31;13(1):18657. doi: 10.1038/s41598-023-45602-5. . [DOI] [PMC free article] [PubMed] [Google Scholar]
  • [7].Nieminen JO, Koponen LM, Ilmoniemi RJ. Experimental Characterization of the Electric Field Distribution Induced by TMS Devices. Brain Stimul. 2015. May-Jun;8(3):582–9. doi: 10.1016/j.brs.2015.01.004. Epub 2015 Jan 12. . [DOI] [PubMed] [Google Scholar]
  • [8].Navarro de Lara LI, Daneshzand M, Mascarenas A, Paulson D, Pratt K, Okada Y, Raij T, Makarov SN, Nummenmaa A. A 3-axis coil design for multichannel TMS arrays. Neuroimage. 2021. Jan 1;224:117355. doi: 10.1016/j.neuroimage.2020.117355. et al. . [DOI] [PMC free article] [PubMed] [Google Scholar]
  • [9].Snow C. The mutual inductance of two parallel circles. Feb. 1929. National Institute of Standards and Technology (NIST). Online: https://nvlpubs.nist.gov/nistpubs/jres/3/jresv3n2p255_A2b.pdf. [Google Scholar]
  • [10].Van Essen DC, Ugurbil K, Auerbach E, Barch D, Behrens TE, Bucholz R, Chang A, Chen L, Corbetta M, Curtiss SW, Della Penna S, Feinberg D, Glasser MF, Harel N, Heath AC, Larson-Prior L, Marcus D, Michalareas G, Moeller S, Oostenveld R, Petersen SE, Prior F, Schlaggar BL, Smith SM, Snyder AZ, Xu J, Yacoub E; WU-Minn HCP Consortium. The Human Connectome Project: a data acquisition perspective. Neuroimage. 2012. Oct 1;62(4):2222–31. doi: 10.1016/j.neuroimage.2012.02.018. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • [11].Stenroos M; Koponen LM Effect of coil model detail on computed electric field in TMS. International Journal of Bioelectromagnetism. Aug 2021. 23 (2): 15/1-5. [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Supplementary Materials

Supplementary Video #1
Download video file (1.3MB, mp4)
Supplementary Video #2
Download video file (3.4MB, mp4)
Supplementary Video #3
Download video file (3.3MB, mp4)

Data Availability Statement

  1. The software package along with video examples are available on GitHub: https://github.com/dexuantang/BEM-FMM-CoilDesigner

  2. Supplement A: Video examples of workflow i). and ii)., as well as NIfTI saving feature.

RESOURCES