1 Introduction

The human brain is the most complex-organized structure known to exist, and, for us, it is also the most important. There are at least 1010 neurons in the outermost layer of the brain and the cerebral cortex. The electromagnetic brain activity is generated via instantaneous flux of ions in the neurons as a result of intrinsic electrochemical reactions [1]. The neuronal current produces an electric potential which can be measured on the scalp, as well as a small magnetic flux. Measurements of the electric potential on the scalp lead to the Electroencephalography (EEG), while measurements of the magnetic flux outside the head lead to the magnetoencephalography (MEG), which are two of the most important techniques for studying brain neuronal activity in vivo. For both of these modalities, we know the direct mathematical problems of determining the electric potential and the magnetic flux when the interior neuronal sources, and the geometry of the brain-head system, are given, as well as the inverse mathematical problems of identifying the sources once the measured EEG and MEG data are obtained [2,3,4,5]. Hermann von Helmholtz showed in 1853 that this problem has no unique solution. During the last thirty years, direct and inverse problems of EEG and MEG have been studied extensively [1]. The geometry of the head affects the solutions of the mathematical problems of the electromagnetic brain activity since the ellipsoidal shape brings into the problem another more severe difficulty, since solving boundary value problems in ellipsoidal geometry is by far not a trivial analytic procedure. A triaxial ellipsoid with average semi-axes equal to 6 cm, 6.5 cm, and 9 cm provides an approximation of the average human brain which is much better than the most used spherical model. The first effort to solve the direct EEG problems appeared in [6, 7]. Ever since a number of solutions for the EEG and MEG problems, with dipole as well as with continuous source distributions in ellipsoidal geometry, have been published [1, 8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24].

The machinery used in EEG and MEG practical diagnostics uses algorithms which are based on the assumption that the head has spherical shape [25, 26]. Consequently, they record data from an ellipsoidal shape of brain and interpret them as they were coming from a sphere. Thus, an error occurs on the estimation of the location and the moment of a dipole. Since the solutions for the inverse ΜEG dipole problem in spherical and ellipsoidal geometry were known, the challenge was to transfer information from one geometrical system to the other, and anyone who has tried to do something like that immediately recognizes the difficulty of such a task [27]. We need to represent elements of a Hilbert space in spherical and ellipsoidal backgrounds although general representations are not possible at the analytic level [25]. However, as we demonstrate in this work, after some long and tedious calculations, these representations were achieved at least for the needed low degree eigen functions. The final result is the dependence of the error on the values of the principal eccentricities of the ellipsoid.

The paper is organized as follows. In Sect. 2, we provide a brief formulation of the mathematical problem, as well as the necessary information from the theory of ellipsoidal harmonics. That will make the paper readable without having to look at other complementary sources. Section 3 involves the general expansions of the electric potential in spherical and ellipsoidal harmonics, as well as the appropriate connection formulae. This is the core of the present work. For the sake of completeness, we provide a brief proof of Meg inversion algorithm [1, 18, 26, 28] in Sects. 4 and 5. The main results are exposed, and Sect. 6 deals with the numerical implementation of the solution obtained results. The paper closes with concluding remarks in Sect. 7.

2 Mathematical Formulation

Let Ω be a bounded, connected, and homogeneous conductor with a smooth boundary S = ∂Ω. The domain Ω provides a simplified geometrical model of the brain as an isotropic and homogeneous conductor with conductivity σ. The domain Ω is surrounded by the non-conductive exterior space \(\Omega^{c}\). The magnetic permeability μ0 is assumed to be the same both in Ω and in \(\Omega^{c}\). A primary neuronal current \({\varvec{J}}^{P}\) with support in Ω generates the electric and magnetic activity.

The mathematical formulations of the brain-imaging techniques of electroencephalography (EEG) and magnetoencephalography (MEG) are based on the quasi-static theory of electromagnetism. The quasi-static approximation of Maxwell’s equations [1, 26, 29,30,31,32,33,34,35,36] reads

$$\nabla \times \user2{\rm E}\left( {\varvec{r}} \right) = 0,$$
(1)
$$\nabla \times {\varvec{B}}\left( {\varvec{r}} \right) = \mu_{0} \left( {j^{\rho } \left( {\varvec{r}} \right) + \sigma \user2{\rm E}\left( {\varvec{r}} \right)} \right),$$
(2)
$$\nabla \cdot {\varvec{E}}\left( {\varvec{r}} \right) = 0,$$
(3)
$$\nabla \cdot {\varvec{B}}\left( {\varvec{r}} \right) = 0,$$
(4)

where E and B denote the electric and magnetic flux fields, respectively [27, 37].

Since Ε is irrotational, it can be represented by an electric potential u, such that

$${\varvec{E}} = - \nabla u.$$
(5)

In the interior of a homogeneous conductor \(\Omega\), a local neuronal excitation is represented by the equivalent dipole current:

$$J^{p} \left( {\varvec{r}} \right) = Q\delta \left( {{\varvec{r}} - {\varvec{r}}_{0} } \right),$$
(6)

where δ stands for the Dirac measure at a fixed point r0 with a dipole moment equal to Q.

The primary current \({J}^{p}({\varvec{r}})\) induces an electric field E in the interior conductive space, which in turn generates an inductive volume current with density \({J}^{v}\left({\varvec{r}}\right)=\sigma \bullet \boldsymbol{\rm E}({\varvec{r}})\) resulting to the total current density:

$$J\left( {\varvec{r}} \right) = J^{p} \left( {\varvec{r}} \right) + J^{v} \left( {\varvec{r}} \right).$$
(7)

The current J generates an electromagnetic wave, which propagates in the interior as well as in the exterior to the conducting space.

The potential u+ is the field recorded in any electroencephalogram. In particular, we denote the electric potential in the interior space Ω, by u and in the exterior space \(\Omega^{c}\), by u+. Combining Eqs. (2), (5), and (7), we obtain the Poisson equation:

$$\sigma^{ - } \Delta u^{ - } = \nabla \cdot J^{p} \left( {\varvec{r}} \right),\quad {\varvec{r}} \in \Omega$$
(8)

which the interior potential u- must satisfy in Ω.

In the source-free space \(\Omega^{c}\), the potential u+ solves the Laplace equation:

$$\Delta u^{ - } \left( {\varvec{r}} \right) = 0,\quad {\varvec{r}} \in \Omega^{c} .$$
(9)

On the surface S, the following transmission conditions hold:

$$u^{ + } \left( {\varvec{r}} \right) = u^{ - } \left( {\varvec{r}} \right),\quad {\varvec{r}} \in S,$$
(10)
$$\frac{{\partial u^{ - } \left( {\varvec{r}} \right)}}{\partial n} = 0,\quad {\varvec{r}} \in S$$
(11)

where the outward normal differentiation on the surface is considered. Conditions (10) and (11) state the continuity of the potential function as well as the continuity of the normal component of current density on S.

In addition, we assume the asymptotic behavior at infinity:

$$u^{ + } \left( {\varvec{r}} \right) = O\left( \frac{1}{r} \right),\quad r \to \infty .$$
(12)

The relationship between dipole (r0, Q) and B is expressed by the Geselowitz equation:

$${\varvec{B}}\left( {\varvec{r}} \right) = \frac{{\mu_{0} }}{4\pi }{\varvec{Q}} \times \frac{{r - r_{0} }}{{\left| {r - r_{0} } \right|^{3} }} + \frac{{ - \sigma \mu_{0} }}{4\pi }\oint\limits_{S} {u^{ - } \left( {\user2{r^{\prime}}} \right)\hat{n}\left( {\user2{r^{\prime}}} \right) \times \frac{{{\varvec{r}} - \user2{r^{\prime}}}}{{\left| {{\varvec{r}} - \user2{r^{\prime}}} \right|^{3} }}{\text{d}}s\left( {r^{\prime}} \right)}$$
(13)

2.1 Ellipsoidal System

A complete analysis of the material presented in this section can be found in [25].

Let Se denote the triaxial ellipsoid for which rectangular coordinates are provided as follows:

$$\frac{{x_{1}^{2} }}{{\alpha_{1}^{2} }} + \frac{{x_{2}^{2} }}{{\alpha_{2}^{2} }} + \frac{{x_{3}^{2} }}{{\alpha_{3}^{2} }} = 1,\quad 0 < \alpha_{3} < \alpha_{2} < \alpha_{1} < + \infty$$
(14)

where \(\alpha_{1} ,\alpha_{2} ,\alpha_{3}\) are three fixed parameters determining the reference semi-axes.

The basic ellipsoid (14) introduces an ellipsoidal system with coordinates (ρ, μ, ν) and semi-focal distances \(h_{1}^{{}}\),\(h_{2}^{{}}\),\(h_{3}^{{}}\) where

$$\begin{gathered} h_{1} = \sqrt {\alpha_{2}^{2} - \alpha_{3}^{2} } \hfill \\ h_{2} = \sqrt {\alpha_{1}^{2} - \alpha_{3}^{2} } \hfill \\ h_{3} = \sqrt {\alpha_{1}^{2} - \alpha_{2}^{2} } \hfill \\ \end{gathered}$$
(15)

The ellipsoidal coordinates (ρ, μ, ν) involve the ellipsoidal variable \(\rho \in [h_{2} , + \infty )\) and the hyperboloidal variables \(\mu \in [h_{3} ,h_{2} ]\) and \(\nu \in [ - h_{3} ,h_{3} ]\).

The connection between the ellipsoidal and the Cartesian systems is given by

$$\begin{gathered} x_{1}^{2} = \frac{{\rho^{2} \mu^{2} \nu^{2} }}{{h_{2}^{2} h_{3}^{2} }} \hfill \\ x_{2}^{2} = \frac{{\left( {\rho^{2} - h_{3}^{2} } \right)\left( {\mu^{2} - h_{3}^{2} } \right)\left( {h_{3}^{2} - \nu^{2} } \right)}}{{h_{1}^{2} h_{3}^{2} }} \hfill \\ x_{3}^{2} = \frac{{\left( {\rho^{2} - h_{2}^{2} } \right)\left( {h_{2}^{2} - \mu^{2} } \right)\left( {h_{2}^{2} - \nu^{2} } \right)}}{{h_{1}^{2} h_{2}^{2} }} \hfill \\ \end{gathered}$$
(16)

The coordinate ρ plays the role of the radial variable r, while μ and ν correspond to the angular variable θ and φ in spherical coordinates.

The ellipto-spherical coordinate system \(\left( {\rho ,\theta_{\varepsilon } ,\varphi_{\varepsilon } } \right)\) combines the ellipsoidal variable that specifies the family of confocal ellipsoids with the eccentric angular variables of the spherical system. It is defined by

$$\begin{gathered} x_{1} = \rho \cos \theta_{\varepsilon } ,\quad h_{2} \le \rho < + \infty \hfill \\ x_{2} = \sqrt {\rho^{2} - h_{3}^{2} } \sin \theta_{\varepsilon } \cos \varphi_{\varepsilon } ,\quad 0 \le \theta_{\varepsilon } \le \pi \hfill \\ x_{3} = \sqrt {\rho^{2} - h_{2}^{2} } \sin \theta_{\varepsilon } \sin \varphi_{\varepsilon } ,\quad 0 \le \varphi_{\varepsilon } < 2\pi \hfill \\ \end{gathered}$$
(17)

In ellipsoidal coordinates, the surface Se given in (14) corresponds to \(\rho = \alpha_{1}\), and it represents the boundary of the brain. The interior space \(\Omega_{e}^{{}}\) is defined by the interval \(\rho \in [h_{2} ,a_{1} )\), and it is characterized by the conductivity σ. The exterior non-conductive space \(\Omega_{e}^{c}\) is defined by \(\rho \in (a_{1} ,\infty )\).

Separation of variables for Laplace’s Eq. (9) in the ellipsoidal coordinate system leads to the Lamé equation:

$$\left( {x^{2} - h_{3}^{2} } \right)\left( {x^{2} - h_{2}^{2} } \right)E^{\prime\prime}\left( x \right) + x\left( {2x^{2} - h_{3}^{2} - h_{2}^{2} } \right)E^{\prime}\left( x \right) + \left[ {\left( {h_{3}^{2} + h_{2}^{2} } \right)P - n\left( {n + 1} \right)x^{2} } \right]E\left( x \right) = 0$$
(18)

for each one of the factors E(ρ), E(µ), and E(ν) that form the interior harmonic function:

$${\rm I}{\rm E}_{n}^{m} \left( {\rho ,\mu ,\nu } \right) = E_{n}^{m} \left( \rho \right)E_{n}^{m} \left( \mu \right)E_{n}^{m} \left( \nu \right)$$
(19)

In Eq. (18), the parameters P and n are constants that define, in a complicated way, the degree n and the order m of the interior ellipsoidal harmonic (19).

The corresponding exterior ellipsoidal harmonic assumes the form:

$$IF_{n}^{m} \,\left( {\rho ,\mu ,\nu } \right) = \left( {2n + 1} \right)IE_{n}^{m} \left( {\rho ,\mu ,\nu } \right){\rm I}_{n}^{m} \left( \mu \right)$$
(20)

The ρ-dependent functions \({\rm I}_{n}^{m} (\rho )\) are elliptic integrals of the form:

$${\rm I}_{n}^{m} \left( \rho \right) = \int\limits_{\rho }^{\infty } {\frac{{{\text{d}}t}}{{\left[ {E_{n}^{m} \left( t \right)} \right]^{2} \sqrt {\left( {t^{2} - h_{3}^{2} } \right)\left( {t^{2} - h_{2}^{2} } \right)} }}}$$
(21)

for each n = 0, 1, 2, … and m = 1, 2, …, 2n + 1.

The products \(E_{n}^{m} (\mu ),E_{n}^{m} (\nu )\) defined on the surface of any specific ellipsoid, are known as surface ellipsoidal harmonics, and they form a complete orthogonal set of surface eigen functions.

We define the normalization constants \(\gamma_{n}^{m}\) as follows:

$$\gamma_{n}^{m} = \oint\limits_{{\rho = \alpha_{1} }} {\left[ {E_{n}^{m} \left( \mu \right)E_{n}^{m} \left( \nu \right)} \right]^{2} l_{{a_{1} }} (\mu ,\nu ){\text{d}}s} \quad n \, = \, 0,1,2, \ldots {\text{ and }}m \, = \, 1,2, \ldots 2n + 1$$
(22)

where the employed symbol of integration indicates integration over the surface of the ellipsoid \(\rho = \alpha_{1}\).

In the present work, the following normalization constants are to be used:

$$\gamma_{0}^{1} = 4\pi ,\quad n = 0, \, m = 1$$
(23)
$$\gamma_{1}^{m} = \frac{4\pi }{3}\frac{{h_{1}^{2} h_{2}^{2} h_{3}^{2} }}{{h_{m}^{2} }},\quad n = 1,m = 1,2,3$$
(24)
$$\gamma_{2}^{1} = - \frac{8\pi }{5}\left( {\Lambda - \Lambda^{\prime}} \right)\left( {\Lambda - \alpha_{1}^{2} } \right)\left( {\Lambda - \alpha_{2}^{2} } \right)\left( {\Lambda - \alpha_{3}^{2} } \right),\quad n = 2, \, m = 1$$
(25)
$$\gamma_{2}^{2} = \frac{8\pi }{5}\left( {\Lambda - \Lambda^{\prime}} \right)\left( {\Lambda^{\prime} - \alpha_{1}^{2} } \right)\left( {\Lambda^{\prime} - \alpha_{2}^{2} } \right)\left( {\Lambda^{\prime} - \alpha_{3}^{2} } \right),\quad n = 2, \, m = 2$$
(26)
$$\gamma_{2}^{6 - m} = \frac{4\pi }{{15}}h_{1}^{2} h_{2}^{2} h_{3}^{2} h_{m}^{2} ,\quad n = 2,\,m = 1,2,3$$
(27)

where

$$\left. {\begin{array}{*{20}c} \Lambda \\ {\Lambda^{\prime}} \\ \end{array} } \right\} = \frac{1}{3}\sum\limits_{i = 1}^{3} {a_{i}^{2} \pm } \frac{1}{3}\left[ {\sum\limits_{i = 1}^{3} {\left( {a_{i}^{4} - \frac{{a_{1}^{2} a_{2}^{2} a_{3}^{2} }}{{a_{i}^{2} }}} \right)} } \right]^{1/2}$$
(28)

2.2 Spherical System

Next, we restrict our consideration to the case where the domain \(\Omega_{s}^{{}}\) is a sphere of radius α centered at the origin. The domain \(\Omega_{s}^{{}}\) is bounded by the spherical surface Ss for which rectangular coordinates are provided as follows:

$$x_{1}^{2} + x_{2}^{2} + x_{3}^{2} = \alpha^{2}$$
(29)

In spherical coordinates, the surface Ss given in (30) corresponds to \(r=\alpha\) and it represents the boundary of the brain. The interior space \(\Omega_{s}^{{}}\) is defined by the interval \(r \in [0,a)\), and it is characterized by the conductivity σ. The exterior to Ss, non-conductive space \(\Omega_{s}^{c}\) is defined by \(r \in (\alpha ,\infty )\).

The connection between the spherical and the Cartesian systems is given by

$$x_{1} = r\sin \theta \cos \varphi ,\quad x_{2} = r\sin \theta \sin \varphi ,\quad x_{3} = r\cos \theta$$
(30)

3 Connection Between Algorithms

In this section, we express the exterior magnetic field in spherical and ellipsoidal harmonics. The basic notation for the spectral decomposition of the Laplace operator in ellipsoidal coordinates can be found in [25], where the ellipsoidal harmonics \({IE}_{n}^{m}(\rho ,\mu ,\nu )\) and \({IF}_{n}^{m}(\rho ,\mu ,\nu )\) that are used in this work, as well as useful relations connecting them are explored.

The radial component of the exterior magnetic field satisfies the following relations:

In spherical harmonics:

$$\frac{1}{{\mu_{0} }}r \cdot B_{s}^{ + } \left( {{\varvec{r}}:{\varvec{r}}_{0} } \right) = \mathop \sum \limits_{n = 0}^{\infty } \mathop \sum \limits_{m = - n}^{n} D_{n}^{m} \frac{1}{{r^{n + 1} }}Y_{n}^{m} \left( {\hat{\user2{r}}} \right),\quad r > \alpha$$
(31)

In ellipsoidal harmonics:

$$\frac{1}{{\mu_{0} }}\rho \cdot B_{e}^{ + } \left( {\rho ,\mu ,\nu } \right) = \mathop \sum \limits_{n = 1}^{\infty } \mathop \sum \limits_{m = 1}^{2n + 1} B_{n}^{m} IF_{n}^{m} \left( {\hat{\user2{r}}} \right),\quad \rho > \alpha_{1}$$
(32)

where \(\left( {a_{1} \cdot a_{2} \cdot a_{3} } \right)^{1/3} = a\) and the constants \({D}_{n}^{m},{\rm B}_{n}^{m}\) denote the values of the integrals

$$D_{n}^{m} = \oint\limits_{\left| r \right| = 1} {B_{s}^{ - } \left( {r,\theta ,\varphi } \right)Y_{n}^{{m^{*} }} \left( {\hat{\user2{r}}} \right){\text{d}}s\left( r \right)}$$
(33)
$${\rm B}_{n}^{m} = \frac{1}{{\gamma_{n}^{m} }}\oint\limits_{{\rho = \alpha_{1} }} {{\rm B}_{e}^{ - } \left( {\rho ,\mu ,\nu } \right){\rm E}_{n}^{m} \left( \mu \right){\rm E}_{n}^{m} \left( \nu \right){\text{d}}\Omega \left( {\mu ,\nu } \right)}$$
(34)

Equation (31) expressed in spherical coordinates, at a fixed point A (γ, θ, ϕ), γ > max{α,\({a}_{1}\)} gives

$$\begin{aligned} \frac{1}{{\mu_{0} }}r & \cdot B_{s}^{ + } \left( {\gamma ,\theta ,\varphi } \right) \\ & = \mathop \sum \limits_{n = 0}^{\infty } \mathop \sum \limits_{m = - n}^{n} D_{n}^{m} \frac{1}{{\gamma^{n + 1} }}Y_{n}^{m} \left( {\theta ,\varphi } \right) \\ & = Y_{0}^{0} \left( {\theta ,\varphi } \right)\frac{1}{\gamma } D_{0}^{0} + Y_{1}^{ - 1} \left( {\theta ,\varphi } \right)\frac{1}{{\gamma^{2} }}D_{1}^{ - 1} + Y_{1}^{1} \left( {\theta ,\varphi } \right)\frac{1}{{\gamma^{2} }}D_{1}^{1} + Y_{1}^{0} \left( {\theta ,\varphi } \right)\frac{1}{{\gamma^{2} }}D_{1}^{0} \\ & \quad + Y_{2}^{ - 2} \left( {\theta ,\varphi } \right)\frac{1}{{\gamma^{3} }}D_{2}^{ - 2} + Y_{2}^{ - 1} \left( {\theta ,\varphi } \right)\frac{1}{{\gamma^{3} }}D_{2}^{ - 1} + Y_{2}^{1} \left( {\theta ,\varphi } \right)\frac{1}{{\gamma^{3} }}D_{2}^{1} + Y_{2}^{0} \left( {\theta ,\varphi } \right)\frac{1}{{\gamma^{3} }}D_{2}^{0} \\ & \quad + Y_{2}^{2} \left( {\theta ,\varphi } \right)\frac{1}{{\gamma^{3} }}D_{2}^{2} + {\rm O}\left( {\frac{1}{{\gamma^{4} }}} \right) \\ \end{aligned}$$
(35)

in Cartesian form:

$$\begin{aligned} \frac{1}{{\mu_{0} }}r &\cdot B_{s}^{ + } \left( {x_{1} ,x_{2} ,x_{3} } \right) \\ & = \frac{1}{{\sqrt {4\pi } }}\frac{1}{\gamma }D_{0}^{0} + \frac{\sqrt 3 }{{\sqrt {4\pi } }}\frac{1}{{\gamma^{3} }}D_{1}^{ - 1} x_{2} + \frac{\sqrt 3 }{{\sqrt {4\pi } }}\frac{1}{{\gamma^{3} }}D_{1}^{1} x_{1} + \frac{\sqrt 3 }{{\sqrt {4\pi } }}\frac{1}{{\gamma^{3} }}D_{1}^{0} x_{3} \\ & \quad + \frac{{\sqrt {15} }}{{\sqrt {4\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{ - 2} x_{1} x_{2} + \frac{{\sqrt {15} }}{{\sqrt {4\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{ - 1} x_{2} x_{3} \\ &\quad + \frac{\sqrt 5 }{{\sqrt {16\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{0} \left( {3x_{3}^{2} - \gamma^{2} } \right) + \frac{{\sqrt {15} }}{{\sqrt {4\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{1} x_{1} x_{3} \\ & \quad + \frac{{\sqrt {15} }}{{\sqrt {16\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{2} \left( {x_{1}^{2} - x_{2}^{2} } \right) + {\rm O}\left( {\frac{1}{{\gamma^{4} }}} \right) \\ \end{aligned}$$
(36)

And finally in ellipto-sphericalFootnote 1 form:

$$\begin{aligned} \frac{1}{{\mu_{0} }}r &\cdot B_{s}^{ + } \left( {\rho ,\theta_{\varepsilon } ,\varphi_{\varepsilon } } \right) \\ & = \frac{1}{{\sqrt {4\pi } }}\frac{1}{\gamma }D_{0}^{0} + \frac{\sqrt 3 }{{\sqrt {4\pi } }}\frac{1}{{\gamma^{3} }}D_{1}^{ - 1} \sqrt {\rho^{2} - h_{3}^{2} } \sin \theta_{\varepsilon } \cos \varphi_{\varepsilon } \\ & \quad + \frac{\sqrt 3 }{{\sqrt {4\pi } }}\frac{1}{{\gamma^{3} }}D_{1}^{1} \rho \cos \theta_{\varepsilon } + \frac{\sqrt 3 }{{\sqrt {4\pi } }}\frac{1}{{\gamma^{3} }}D_{1}^{0} \sqrt {\rho^{2} - h_{2}^{2} } \sin \theta_{\varepsilon } \sin \varphi_{\varepsilon } \\ & \quad + \frac{{\sqrt {15} }}{{\sqrt {4\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{ - 2} \rho \cos \theta_{\varepsilon } \sqrt {\rho^{2} - h_{3}^{2} } \sin \theta_{\varepsilon } \cos \varphi_{\varepsilon } \\ &\,\quad + \frac{{\sqrt {15} }}{{\sqrt {4\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{ - 1} \sqrt {\rho^{2} - h_{3}^{2} } \sin \theta_{\varepsilon } \cos \varphi_{\varepsilon } \sqrt {\rho^{2} - h_{2}^{2} } \sin \theta_{\varepsilon } \sin \varphi_{\varepsilon } \\ & \quad + \frac{\sqrt 5 }{{\sqrt {16\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{0} \left( {3\left( {\rho^{2} - h_{2}^{2} } \right)\sin^{2} \theta_{\varepsilon } \sin^{2} \varphi_{\varepsilon } - \gamma^{2} } \right) \\ & \quad + \frac{{\sqrt {15} }}{{\sqrt {4\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{1} \sqrt {\rho^{2} - h_{2}^{2} } \sin \theta_{\varepsilon } \sin \varphi_{\varepsilon } \rho \cos \theta_{\varepsilon } \\ & \quad + \frac{{\sqrt {15} }}{{\sqrt {16\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{2} \left( {\left( {\rho^{2} \cos^{2} \theta } \right) - \left( {\rho^{2} - h_{3}^{2} } \right)\sin^{2} \theta_{\varepsilon } \cos^{2} \varphi_{\varepsilon } } \right) \\ & \quad + {\rm O}\left( {\frac{1}{{\gamma^{4} }}} \right) \\ \end{aligned}$$
(37)

for each n = 0,1,2 and m = − 2,0,1,2.

Similarly from (32), we arrive at the relative expression in ellipsoidal coordinates at a fixed point A (γ, θ, ϕ), γ > max{α,\({a}_{1}\)}

$$\begin{aligned} \frac{1}{{\mu_{0} }}\rho &\cdot B_{e}^{ + } \left( {\rho ,\mu ,\nu } \right) \\ & = \mathop \sum \limits_{n = 0}^{\infty } \mathop \sum \limits_{m = 1}^{2n + 1} k_{n}^{m} IF_{n}^{m} \left( {\rho ,\mu ,\nu } \right) \\ & = {\rm B}_{0}^{1} IF_{0}^{1} \left( {\rho ,\mu ,\nu } \right) + {\rm B}_{1}^{1} IF_{1}^{1} \left( {\rho ,\mu ,\nu } \right) + {\rm B}_{1}^{2} IF_{1}^{2} \left( {\rho ,\mu ,\nu } \right) + {\rm B}_{1}^{3} IF_{1}^{3} \left( {\rho ,\mu ,\nu } \right) \\ & \quad + {\rm B}_{2}^{1} IF_{2}^{1} \left( {\rho ,\mu ,\nu } \right) + {\rm B}_{2}^{2} IF_{2}^{2} \left( {\rho ,\mu ,\nu } \right) + {\rm B}_{2}^{3} IF_{2}^{3} \left( {\rho ,\mu ,\nu } \right) + {\rm B}_{2}^{4} IF_{2}^{4} \left( {\rho ,\mu ,\nu } \right) \\ & \quad + {\rm B}_{2}^{5} IF_{2}^{5} \left( {\rho ,\mu ,\nu } \right) \\ & \quad + {\rm O}\left( {\frac{1}{{\rho^{4} }}} \right) \\ \end{aligned}$$
(38)

in Cartesian form:

$$\begin{aligned} & \frac{1}{{\mu_{0} }}\rho \cdot B_{e}^{ + } \left( {x_{1} ,x_{2} ,x_{3} } \right) \\ & \quad = {\rm B}_{0}^{1} I_{0}^{1} \left( \rho \right) + 3{\rm B}_{1}^{1} I_{1}^{1} \left( \rho \right)h_{2} h_{3} x_{1} + 3{\rm B}_{1}^{2} I_{1}^{2} \left( \rho \right)h_{1} h_{3} x_{2} + 3{\rm B}_{1}^{3} I_{1}^{3} \left( \rho \right)h_{1} h_{2} x_{3} \\ & \quad \quad + 5{\rm B}_{2}^{1} I_{2}^{1} \left( \rho \right){\rm I}L\left( {\mathop \sum \limits_{n = 1}^{3} \frac{{x_{n}^{2} }}{{\Lambda - \alpha_{n}^{2} }} + 1} \right) + 5{\rm B}_{2}^{2} I_{2}^{2} \left( \rho \right){\rm I}L^{\prime}\left( {\mathop \sum \limits_{n = 1}^{3} \frac{{x_{n}^{2} }}{{\Lambda^{\prime} - \alpha_{n}^{2} }} + 1} \right) \\ & \quad \quad + 5{\rm B}_{2}^{3} I_{2}^{3} \left( \rho \right)h_{1} h_{2} h_{3}^{2} x_{1} x_{2} + 5{\rm B}_{2}^{4} I_{2}^{4} \left( \rho \right)h_{1} h_{3} h_{2}^{2} x_{1} x_{3} + 5{\rm B}_{2}^{5} I_{2}^{5} \left( \rho \right)h_{3} h_{2} h_{1}^{2} x_{3} x_{2} \\ & \quad \quad + {\rm O}\left( {\frac{1}{{\rho^{4} }}} \right) \\ \end{aligned}$$
(39)

and in ellipto-spherical form:

$$\begin{aligned} \frac{1}{{\mu_{0} }}\rho &\cdot B_{e}^{ + } \left( {\rho ,\theta_{\varepsilon } ,\varphi_{\varepsilon } } \right) \\ & = {\rm B}_{0}^{1} I_{0}^{1} \left( \rho \right) + 3{\rm B}_{1}^{1} I_{1}^{1} \left( \rho \right)h_{2} h_{3} \rho \cos \theta_{\varepsilon } \\ & \quad + 3{\rm B}_{1}^{2} I_{1}^{2} \left( \rho \right)h_{1} h_{3} \sqrt {\rho^{2} - h_{3}^{2} } \sin \theta_{\varepsilon } \cos \varphi_{\varepsilon } + 3{\rm B}_{1}^{3} I_{1}^{3} \left( \rho \right)h_{1} h_{2} \sqrt {\rho^{2} - h_{2}^{2} } \sin \theta_{\varepsilon } \sin \varphi_{\varepsilon } \\ & \quad + 5{\rm B}_{2}^{1} I_{2}^{1} \left( \rho \right){\rm I}L\left( {\frac{{\rho^{2} \cos^{2} \theta_{\varepsilon } }}{{\Lambda - \alpha_{1}^{2} }} + \frac{{\left( {\rho^{2} - h_{3}^{2} } \right)\sin^{2} \theta_{\varepsilon } \cos^{2} \varphi_{\varepsilon } }}{{\Lambda - \alpha_{2}^{2} }} + \frac{{\left( {\rho^{2} - h_{2}^{2} } \right)\sin^{2} \theta_{\varepsilon } \sin^{2} \varphi_{\varepsilon } }}{{\Lambda - \alpha_{3}^{2} }} + 1} \right) \\ & \quad + 5{\rm B}_{2}^{2} I_{2}^{2} \left( \rho \right){\rm I}L^{\prime}\left( {\frac{{\rho^{2} \cos^{2} \theta_{\varepsilon } }}{{\Lambda^{\prime} - \alpha_{1}^{2} }} + \frac{{\left( {\rho^{2} - h_{3}^{2} } \right)\sin^{2} \theta_{\varepsilon } \cos^{2} \varphi_{\varepsilon } }}{{\Lambda^{\prime} - \alpha_{2}^{2} }} + \frac{{\left( {\rho^{2} - h_{2}^{2} } \right)\sin^{2} \theta_{\varepsilon } \sin^{2} \varphi_{\varepsilon } }}{{\Lambda^{\prime} - \alpha_{3}^{2} }} + 1} \right) \\ & \quad + 5{\rm B}_{2}^{3} I_{2}^{3} \left( \rho \right)h_{1} h_{2} h_{3}^{2} \rho \cos \theta_{\varepsilon } \sqrt {\rho^{2} - h_{3}^{2} } \sin \theta_{\varepsilon } \cos \varphi_{\varepsilon } \\ & \quad + 5{\rm B}_{2}^{4} I_{2}^{4} \left( \rho \right)h_{1} h_{3} h_{2}^{2} \rho \cos \theta_{\varepsilon } \sqrt {\rho^{2} - h_{2}^{2} } \sin \theta_{\varepsilon } \sin \varphi_{\varepsilon } \\ & \quad + 5{\rm B}_{2}^{5} I_{2}^{5} \left( \rho \right)h_{3} h_{2} h_{1}^{2} \rho \cos \theta_{\varepsilon } \sqrt {\rho^{2} - h_{3}^{2} } \sin \theta_{\varepsilon } \cos \varphi_{\varepsilon } \sqrt {\rho^{2} - h_{2}^{2} } \sin \theta_{\varepsilon } \sin \varphi_{\varepsilon } + {\rm O}\left( {\frac{1}{{\rho^{4} }}} \right) \\ \end{aligned}$$
(40)

for each n = 0,1,2 and m = 1, 2, …, 2n + 1

Next, we identify the spherical with the ellipsoidal expansions at every point A, outside the brain. The point A, from (16), (17) and (19), is uniquely expressed in any coordinate system we use: A(r,θ,φ) = Α(ρ,μ,ν) = Α(ρ,\({{\theta }_{\varepsilon },\varphi }_{\varepsilon })\),

$${\rm B}_{s,A}^{ + } \left( {\gamma ,\theta ,\varphi } \right) = {\rm B}_{e,A}^{ + } \left( {\rho ,\mu ,\nu } \right)$$
(41)

Under this assumption and performing the necessary calculations in order to express every term appeared, in Cartesian coordinates, we arrive at the following connection relations:

$$\frac{1}{{\sqrt {4\pi } }}\frac{1}{\gamma }D_{0}^{0} - \frac{\sqrt 5 }{{\sqrt {16\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{0} = B_{0}^{1} I_{0}^{1} \left( \rho \right) + 5B_{2}^{1} I_{2}^{1} \left( \rho \right){\rm I}L + 5B_{2}^{2} I_{2}^{2} \left( \rho \right){\rm I}L^{\prime}$$
(42)
$$\frac{\sqrt{3}}{\sqrt{4\pi }}\frac{1}{{\gamma }^{3}}{D}_{1}^{1}={3B}_{1}^{1}{I}_{1}^{1}\left(\rho \right){h}_{2}{h}_{3}$$
(43)
$$\frac{\sqrt{3}}{\sqrt{4\pi }}\frac{1}{{\gamma }^{3}}{D}_{1}^{-1}={3B}_{1}^{2}{I}_{1}^{2}\left(\rho \right){h}_{1}{h}_{3}$$
(44)
$$\frac{\sqrt{3}}{\sqrt{4\pi }}\frac{1}{{\gamma }^{3}}{D}_{1}^{0}={3B}_{1}^{3}{I}_{1}^{3}\left(\rho \right){h}_{2}{h}_{1}$$
(45)
$$\frac{\sqrt{15}}{\sqrt{4\pi }}\frac{1}{{\gamma }^{5}}{D}_{2}^{-1}={5B}_{2}^{5}{I}_{2}^{5}\left(\rho \right){h}_{2}{h}_{3}{h}_{1}^{2}$$
(46)
$$\frac{\sqrt{15}}{\sqrt{4\pi }}\frac{1}{{\gamma }^{5}}{D}_{2}^{1}={5B}_{2}^{4}{I}_{2}^{4}\left(\rho \right){h}_{1}{h}_{3}{h}_{2}^{2}$$
(47)
$$\frac{\sqrt{15}}{\sqrt{4\pi }}\frac{1}{{\gamma }^{5}}{D}_{2}^{-2}={5B}_{2}^{3}{I}_{2}^{3}\left(\rho \right){h}_{1}{h}_{2}{h}_{3}^{2}$$
(48)
$$3\frac{\sqrt 5 }{{\sqrt {16\pi } }}\frac{1}{{\gamma^{5} }}D_{2}^{0} = 5B_{2}^{1} I_{2}^{1} \left( \rho \right)IL\frac{1}{{\Lambda - \alpha_{3}^{2} }} + 5B_{2}^{2} I_{2}^{2} \left( \rho \right)IL^{\prime}\frac{1}{{\Lambda^{\prime} - \alpha_{3}^{2} }}$$
(49)
$$D_{2}^{2} = \frac{10\sqrt \pi }{{\sqrt {15} }}h_{3}^{2} \gamma^{5} \left( {B_{2}^{1} I_{2}^{1} \left( \rho \right)\left( {\Lambda - \alpha_{3}^{2} } \right) + B_{2}^{2} I_{2}^{2} \left( \rho \right)\left( {\Lambda^{\prime} - \alpha_{3}^{2} } \right)} \right)$$
(50)

4 Inversion MEG Problem

Let \({\varvec{Q}}\left({{\varvec{r}}}_{0}\right)\) be the moment of a dipole at the point \({{\varvec{r}}}_{0}\) with \(0<{{\varvec{r}}}_{0}<{c}_{1}\).

Then, the corresponding magnetic field B at the exterior domain \({\Omega }_{\varepsilon }\) satisfies [28]:

$$\frac{4\pi }{{\mu_{0} }}r \cdot {\varvec{B}}\left( {\varvec{r}} \right) = - \left[ {{\varvec{Q}} \times {\varvec{r}}_{0} } \right] \cdot \nabla_{{{\mathbf{r}}_{0} }} \frac{1}{{\left| {{\varvec{r}} - {\varvec{r}}_{0} } \right|}}, r \in \Omega_{\varepsilon } \quad 0 < r_{0} < c_{1}$$
(51)

Proof

Recall that [36]:

$$- \frac{4\pi }{{\mu_{0} }}r \cdot {\varvec{B}}\left( {\varvec{r}} \right) = r \cdot \left( {{\varvec{Q}} \times \nabla_{{\varvec{r}}} \frac{1}{{\left| {{\varvec{r}} - {\varvec{r}}_{0} } \right|}}} \right),\quad r \in \Omega_{\varepsilon }$$
(52)

Since \(0 < r_{0} < c_{1}\), B(r) is obviously in \(C^{\infty } (\Omega {}_{\varepsilon })\).

Using the identity

$$\nabla_{{\varvec{r}}} \frac{1}{{\left| {{\varvec{r}} - {\varvec{r}}_{0} } \right|}} = - \nabla_{{{\varvec{r}}_{0} }} \frac{1}{{\left| {{\varvec{r}} - {\varvec{r}}_{0} } \right|}}$$
(53)

Equation (52) becomes

$$\begin{gathered} \frac{4\pi }{{\mu_{0} }}r \cdot {\varvec{B}}\left( {\varvec{r}} \right) = r \cdot {\varvec{Q}} \times \nabla_{{{\text{r}}_{0} }} \frac{1}{{\left| {{\mathbf{r}} - {\mathbf{r}}_{0} } \right|}}, r \in \Omega_{\varepsilon } \Rightarrow \hfill \\ \frac{4\pi }{{\mu_{0} }}r \cdot {\varvec{B}}\left( {\varvec{r}} \right) = r \cdot {\varvec{Q}} \times \frac{{\left( {{\mathbf{r}} - {\mathbf{r}}_{0} } \right)}}{{\left| {{\mathbf{r}} - {\mathbf{r}}_{0} } \right|^{3} }}, r \in \Omega_{\varepsilon } \Rightarrow \hfill \\ \frac{4\pi }{{\mu_{0} }}r \cdot {\varvec{B}}\left( {\varvec{r}} \right) = {\varvec{r}}_{0} \cdot {\varvec{Q}} \times \nabla_{{r_{0} }} \frac{{\left( {{\varvec{r}} - {\varvec{r}}_{0} } \right)}}{{\left| {{\varvec{r}} - {\varvec{r}}_{0} } \right|^{3} }}, r \in \Omega_{\varepsilon } \Rightarrow \hfill \\ \frac{4\pi }{{\mu_{0} }}r \cdot {\varvec{B}}\left( {\varvec{r}} \right) = {\varvec{r}}_{0} \cdot {\varvec{Q}} \times \nabla_{{r_{0} }} \frac{1}{{\left| {{\varvec{r}} - {\varvec{r}}_{0} } \right|}}, r \in \Omega_{\varepsilon } \Rightarrow \hfill \\ \frac{4\pi }{{\mu_{0} }}r \cdot {\varvec{B}}\left( {\varvec{r}} \right) = - \left[ {{\varvec{Q}} \times {\varvec{r}}_{0} } \right] \cdot \nabla_{{{\varvec{r}}_{0} }} \frac{1}{{\left| {{\varvec{r}} - {\varvec{r}}_{0} } \right|}}, r \in \Omega_{\varepsilon } \hfill \\ \end{gathered}$$
(54)

Finally using the relation,

$$\frac{1}{{\left| {{\varvec{r}} - {\varvec{r}}_{0} } \right|}} = \mathop \sum \limits_{n = 0}^{\infty } \mathop \sum \limits_{m = - n}^{n} 4\pi \frac{{{\varvec{r}}_{0}^{{\varvec{n}}} }}{2n + 1}\frac{1}{{r^{n + 1} }}Y_{n}^{m*} \left( {\hat{\user2{r}}_{0} } \right)Y_{n}^{m} \left( {\hat{\user2{r}}} \right)$$
(55)

Equation (54) becomes

$$\frac{1}{{\mu_{0} }}r \cdot {\varvec{B}}\left( {\varvec{r}} \right) = \left( {{\varvec{r}}_{0} \times {\varvec{Q}}} \right) \cdot \nabla_{{{\varvec{r}}_{0} }} \mathop \sum \limits_{n = 0}^{\infty } \mathop \sum \limits_{m = - n}^{n} \frac{{{\varvec{r}}_{0}^{{\varvec{n}}} }}{2n + 1}\frac{1}{{r^{n + 1} }}Y_{n}^{m*} \left( {\hat{\user2{r}}_{0} } \right)Y_{n}^{m} \left( {\hat{\user2{r}}} \right)$$
(56)

5 Inversion MEG Algorithm in Spherical Geometry

We assume that the magnetic field generated by a single dipole \({({\varvec{r}}}_{0},\boldsymbol{ }{\varvec{Q}})\). Then the magnetic field in the exterior of the brain is provided by [1, 18, 26]

$$\frac{1}{{\mu_{0} }}r \cdot {\varvec{B}}\left( {\varvec{r}} \right) = \mathop \sum \limits_{n = 0}^{\infty } \mathop \sum \limits_{m = - n}^{n} \left( {{\varvec{r}}_{0} \times {\varvec{Q}}} \right)\frac{1}{2n + 1}\frac{1}{{r^{n + 1} }}\nabla_{{{\varvec{r}}_{0} }} \left( {{\varvec{r}}_{0}^{{\varvec{n}}} Y_{n}^{m*} \left( {\hat{\user2{r}}_{0} } \right)} \right)Y_{n}^{m} \left( {\hat{\user2{r}}} \right)$$
(57)

or

$$\frac{1}{{\mu_{0} }}r \cdot B(r) = \sum\limits_{n = 0}^{\infty } {\sum\limits_{m = - n}^{n} {D_{n}^{m} \frac{1}{{r^{n + 1} }}Y_{n}^{m} (\hat{r})} }$$
(58)

where

$$D_{n}^{m} = \frac{1}{2n + 1}\left( {{\varvec{r}}_{0} \times {\varvec{Q}}} \right) \cdot \nabla_{{{\varvec{r}}_{0} }} \left( {{\varvec{r}}_{0}^{{\varvec{n}}} Y_{n}^{m*} \left( {\hat{\user2{r}}_{0} } \right)} \right)$$
(59)

For each n = 1, 2,….και m = − n,…,n. And r0, Q unknown.

From the first 8 terms, we have

$$D_{1}^{ - 1*} = D_{1}^{1} = \frac{1}{{\sqrt {24\pi } }}(r_{0} \times Q)(\hat{x}_{1} + i\hat{x}_{2} )$$
(60)
$$D_{1}^{0} = \frac{1}{{\sqrt {12\pi } }}(r_{0} \times Q)(\hat{x}_{3} )$$
(61)
$$D_{2}^{ - 2*} = D_{2}^{2} = \frac{\sqrt 3 }{{\sqrt {40\pi } }}(r_{0} \times Q)[(x_{01} \hat{x}_{1} - ix_{02} \hat{x}_{2} ) + i(x_{02} \hat{x}_{1} + x_{01} \hat{x}_{2} )]$$
(62)
$$D_{2}^{ - 1*} = D_{2}^{1} = \frac{\sqrt 3 }{{\sqrt {40\pi } }}(r_{0} \times Q)[(x_{03} \hat{x}_{1} - ix_{01} \hat{x}_{3} ) + i(x_{03} \hat{x}_{2} + x_{02} \hat{x}_{3} )]$$
(63)
$$D_{2}^{0} = \frac{1}{{\sqrt {80\pi } }}\left( {r_{0} \times Q} \right)\left[ {2x_{03} \hat{x}_{3} - x_{01} \hat{x}_{1} - x_{02} \hat{x}_{2} } \right]$$
(64)

Equation (59) shows that for a single dipole, since Β involves \({{\varvec{r}}}_{0}\times {\varvec{Q}}\), the component of Q in the r direction does not contribute to the magnetic field. Thus, measurements of B yield information about the two components \(Q_{{\theta_{0} }}\) and \(Q_{{\varphi_{0} }}\). Hence, we ‘lose information,’ i.e., we go from two functions to a single function, as a result of Gauss’s theorem.

From relations (60) and (61), we obtain

$$r_{0} \times Q = \sqrt {6\pi } \left( {D_{1}^{ - 1} + D_{1}^{1} ,i\left( {D_{1}^{ - 1} - D_{1}^{1} } \right),\sqrt 2 D_{1}^{0} } \right)$$
(65)

Substituting (65) into (62)–(64), we have

$$D_{2}^{ - 2*} = D_{2}^{2} = \frac{3}{\sqrt 5 }D_{1}^{1} (x_{01} + ix_{02} ),$$
(66)
$$D_{2}^{ - 1*} = D_{2}^{1} = \frac{3}{{\sqrt {10} }}\left[ {D_{1}^{0} \left( {x_{01} + ix_{02} } \right) + \sqrt 2 D_{1}^{1} x_{03} } \right],$$
(67)
$$D_{2}^{0} = \frac{\sqrt 3 }{{\sqrt 5 }}D_{1}^{0} x_{03} - \frac{\sqrt 3 }{{2\sqrt {10} }}D_{1}^{1} \left( {x_{01} - ix_{02} } \right) - \frac{\sqrt 3 }{{2\sqrt {10} }}D_{1}^{ - 1} \left( {x_{01} + ix_{02} } \right).$$
(68)

From (66)–(68), we obtain

$$x_{03} = \frac{\sqrt 5 }{3}\frac{{D_{2}^{1} }}{{D_{1}^{1} }} - \frac{\sqrt 5 }{{3\sqrt 2 }}\frac{{D_{1}^{0} }}{{D_{1}^{1} }}\frac{{D_{2}^{2} }}{{D_{1}^{1} }}$$
(69)

and

$$x_{01} = \frac{\sqrt 5 }{6}\left[ {\frac{{D_{2}^{ - 2} }}{{D_{1}^{ - 1} }} + \frac{{D_{2}^{2} }}{{D_{1}^{1} }}} \right]$$
(70)
$$x_{02} = i\frac{\sqrt 5 }{6}\left[ {\frac{{D_{2}^{ - 2} }}{{D_{1}^{ - 1} }} - \frac{{D_{2}^{2} }}{{D_{1}^{1} }}} \right].$$
(71)

By expressing the dipolar moment in spherical components, i.e.,

$$Q = Q_{{r_{0} }} \hat{r}_{0} + Q_{{\theta r_{0} }} \hat{\theta }_{0} + Q_{{\varphi_{0} }} \hat{\varphi }_{0}$$
(72)

We obtain

$$r_{0} \times Q = r_{0} (Q_{{\theta r_{0} }} \hat{\varphi }_{0} - Q_{{\varphi_{0} }} \hat{\theta }_{0} )$$
(73)

where

$$\hat{\theta }_{0} = (\cos \theta_{0} \cos \varphi_{0} ,\cos \theta_{0} \sin \varphi_{0} , - \sin \theta_{0} )$$
(74)
$$\hat{\varphi }_{0} = ( - \sin \varphi_{0} ,\cos \varphi_{0} ,0)$$
(75)

Substituting (74), (75), into (72) and using (65), we have

$$- Q_{{\varphi_{0} }} r_{0} \cos \theta_{0} \cos \varphi_{0} - Q_{{\theta_{0} }} r_{0} \sin \varphi_{0} = \sqrt {6\pi } (D_{1}^{ - 1} + D_{1}^{1} )$$
(76)
$$- Q_{{\varphi_{0} }} r_{0} \cos \theta_{0} \sin \varphi_{0} + Q_{{\theta_{0} }} r_{0} \cos \varphi_{0} = i\sqrt {6\pi } (D_{1}^{ - 1} - D_{1}^{1} )$$
(77)
$$Q_{{\varphi_{0} }} r_{0} \sin \theta_{0} = \sqrt {12\pi } D_{1}^{0}$$
(78)

Equations (76)–(78) imply

$$Q_{{\theta_{0} }} = - \sqrt {6\pi } \frac{{D_{1}^{ - 1} + D_{1}^{1} }}{{r_{0} \sin_{{}} \varphi_{0} }} - \sqrt {12\pi } \frac{{D_{1}^{0} }}{{r_{0} \tan \theta_{0} \tan \varphi_{0} }}$$
(79)
$$Q_{{\varphi_{0} }} = \sqrt {12\pi } \frac{{D_{1}^{0} }}{{r_{0} \sin \theta_{0} }}$$
(80)

Let the brain be represented by the reference sphere (30) and let a localized neuronal current represented by a dipole located at the point r0, inside the brain, having moment Q.

The unique solution for the inverse EEG problem with a current dipole inside a sphere is given in (69)–(71), (79) and (80).

At this point, we use the inversion algorithm for the sphere not with its intrinsic spherical data \(D_{n}^{m}\), but with the ellipsoidal data \(B_{n}^{m}\) as they are expressed in terms of \(D_{n}^{m}\).

We obtain

$$\hat{Q}_{{\theta_{0} }} = \frac{{ - 6\sqrt 2 \pi \gamma^{3} h_{3} \left( {B_{1}^{1} I_{1}^{1} h_{2} + B_{1}^{2} I_{1}^{2} h_{1} } \right)}}{{r_{0} \sin \varphi_{0} }} - \frac{{12\pi \gamma^{3} h_{2} h_{1} B_{1}^{3} I_{1}^{3} }}{{r_{0} \tan \varphi_{0} \tan \theta_{0} }}$$
(81)
$$\hat{Q}_{{\varphi_{0} }} = \frac{{12\pi \gamma^{3} {\rm B}_{1}^{3} I_{1}^{3} h_{2} h_{1} }}{{r_{0} \sin \theta_{0} }}$$
(82)
$$\hat{x}_{01} = \frac{{5\gamma^{2} B_{2}^{3} I_{2}^{3} h_{2} h_{3} }}{{18B_{1}^{2} I_{1}^{2} }} + \frac{{5\gamma^{2} h_{3} }}{{18B_{1}^{1} I_{1}^{1} h_{2} }}\left( { B_{2}^{1} I_{2}^{1} \left( {\Lambda - \alpha_{3}^{2} } \right) + B_{2}^{2} I_{2}^{2} \left( {\Lambda^{\prime} - \alpha_{3}^{2} } \right)} \right)$$
(83)
$$\hat{x}_{02} = i\left( {\frac{{5\gamma^{2} B_{2}^{3} I_{2}^{3} h_{2} h_{3} }}{{18B_{1}^{2} I_{1}^{2} }} - \frac{{5\gamma^{2} h_{3} }}{{18B_{1}^{1} I_{1}^{1} h_{2} }}\left( { B_{2}^{1} I_{2}^{1} \left( {\Lambda - \alpha_{3}^{2} } \right) + B_{2}^{2} I_{2}^{2} \left( {\Lambda^{\prime} - \alpha_{3}^{2} } \right)} \right)} \right)$$
(84)
$$\hat{x}_{03} = \frac{{5\gamma^{2} B_{2}^{4} I_{2}^{4} h_{2} h_{1} }}{{9B_{1}^{1} I_{1}^{1} }} - \frac{{5B_{1}^{3} I_{1}^{3} h_{1} \gamma^{2} \left( { B_{2}^{1} I_{2}^{1} \left( {\Lambda - \alpha_{3}^{2} } \right) + B_{2}^{2} I_{2}^{2} \left( {\Lambda^{\prime} - \alpha_{3}^{2} } \right)} \right)}}{{9\sqrt 2 B_{1}^{1} I_{1}^{1} B_{1}^{1} I_{1}^{1} h_{2} }}$$
(85)

6 Numerical Implementation

In the presented section, we describe what the algorithms (81)–(85), imply when we consider different values for semi-axes in order to understand the sensitivity of our analytic algorithms.

We consider an ellipsoid with semi-axes \({\alpha }_{1}{,\alpha }_{2},{\alpha }_{3}\) and a sphere with radius r = α with volumes equal to that of the ellipsoid i.e \({V}_{e}=\frac{4\pi }{3}{\alpha }_{1}{\alpha }_{2}{\alpha }_{3}={V}_{s}\). The conductivity is taken to be σ = 0.3 (Ωm)−1.

Case I We assume that there is a dipole (6) inside the ellipsoid (14) with semi-axes,

$$\alpha_{1} = 9\,{\text{cm}} = a_{2} = 6.5\,{\text{cm}},a_{3} = \,6\,{\text{cm}}$$

Therefore, the dipole source should be inside the sphere where radius is 7.054 cm but in certain directions in order to be inside the ellipsoid as well in any case.

$$r = \alpha = \left( {\alpha_{1} \cdot \alpha_{2} \cdot \alpha_{3} } \right)^{1/3} = 7.054\,{\text{cm}}$$

At the point,

$$A\left( {r,\theta ,\phi } \right) = A\left( {15,45,45} \right)$$

or equivalently from (17) and (31), at

$$A\left( {r, \, \theta , \, \phi } \right) = {\rm A}\left( {\rho , \, \theta_{\varepsilon } ,\varphi_{\varepsilon } } \right) = \left( {16.081,62.199, \, 63.421} \right)$$

where, \(\rho >{\alpha }_{1}\), we assume that

$$u_{s,A}^{ + } \left( {r,\theta ,\varphi } \right) = u_{e,A}^{ + } \left( {\rho ,\mu ,\nu } \right) = c_{1} \left( A \right)$$

From (69)–(71), (79), and (80) we obtain

$$Q_{s} = \left( {31.7795ic_{1} , \, 35.5306c_{1} } \right)$$
$$r_{s} = \left( {0.4167, \, 0.4167i, \, 1.1785} \right)$$

From (81)–(85) we obtain

$$Q_{{{\text{sap}}}} = \left( {\left( { - 9.1410 \, + \, 67.0487i} \right), 77.3265} \right)$$
$$r_{{{\text{sap}}}} = \left( {0.3388, \, 0.3635i, \, 1.2605} \right)$$

In the above graphs, we observe that when the semi-axes approach the realistic semi- axes of the brain, i.e., α1 = 9 cm, α2 = 6.5 cm, α3 = 6 cm, the error calculated from algorithms (51)–(55) for Q and r0 gives relatively good results. As the semi-axes grow, the errors become bigger and there is a large difference between the exact and the approximate data (Figs. 1, 2).

Fig. 1
figure 1

Graph shows how the error of Qs grows as the semi-axes increase

Fig. 2
figure 2

Graph shows how the error of r0 grows as the semi-axes increase

7 Conclusions

For the identification of an active dipole within the brain from MEG recordings, inversion algorithms are already well known both for the spherical and the ellipsoidal model of the brain–head system. In medical practice, the developed algorithms are based on the assumption that the brain is a sphere [32]. However, the realistic model of the shape of the brain is more similar to an ellipsoid. Consequently, that generates an error on the medical practice due to the interpretation of the data, which are obtained on an ellipsoidal figure and are processed as they were obtained on a sphere. The estimation of this error is the goal of the present work. We developed the appropriate analytic formulae that connect the spherical and ellipsoidal eigenfunction expansions. Numerical calculations of the obtained results reveal that error is not significant for small eccentricities. This characteristic is clearly depicted in Figs. 1 and 2 (Tables 1, 2).

Table 1 Each line of this table shows the error of Qs, for different values of semi-axes with \({\alpha }_{1}{\alpha }_{2}{\alpha }_{3}=351\)
Table 2 Each line of this table shows the error of r0, for different values of semi-axes with \({\mathrm{\alpha }}_{1}{\mathrm{\alpha }}_{2}{\mathrm{\alpha }}_{3}=351\). First line is the case I