# Using Parseval's theorem to check for energy conservation between the time and frequency domain

Parseval's theorem refers to that information is not lost in Fourier transform. In this example, we verify energy conservation between time and frequency domain results from an FDTD simulation using Parseval's theorem. This is done by evaluating the energy carried by a short pulse both in the time and frequency domain. In this example, we employ the "power" rawdata returned by both planar time and frequency monitor for calculation.

Note: Energy conservation - nonorm state This example only applies to the nonom state. In nonorm, the source is a pulse by default. The pulse carries a finite amount of energy, in Joule. If there is no loss in Fourier transform, the amount of energy has to be exactly the same in time and frequency domain. Unlike a CW source, the amount of energy accumulated is a function of time. This example does not apply when CWnorm is on. |

Suppose that e(t) and E(f) are the fields in the time and frequency domain respectively, where E(f) is obtained by the fourier transform of e(t). According to Parseval's theorem, the following equation holds,

$$\int_{-\infty}^{\infty}|e(t)|^2dt= \int_{-\infty}^{\infty}|E(f)|^2df$$

For a simple plane wave, the Poynting vector(\(P\)) is directly proportional to \(|E|^2\), where E is the electric field. This relation holds in both time and frequency domain. For a short pulse in the nonorm state (without time averaging),

$$Power\underline\ time(t)=\int real(P_\bot(t))dS=n\sqrt{\frac{\epsilon_0}{\mu_0}}\int |e(t)^2|dS$$

$$Energy\underline\ spectrum(f)=\int real(P_\bot(t))dS=n\sqrt{\frac{\epsilon_0}{\mu_0}}\int |E(f)^2|dS$$

In other words, for the same area dS, the theorem can be written as a form of conservation of energy. Note that Energy_spectrum(f) has a unit of Watt/Hz^2, while power_time(t) has a unit of Watt.

$$Energy=\int_{-\infty}^{\infty} power(t)dt=\int_{-\infty}^{\infty}Energy\underline\ spectrum(f)df$$

To verify the above equation, a simple simulation with a plane wave and planar monitors (both time and frequency) is performed in the nonorm state. Download the above associated files and run the script. The script contains two parts: 1) the "power" returned by the monitors and 2) Poynting vector integration.

First, it extracts the "power" recorded by the time and frequency monitor accordingly. The reason for this step is because the returned "power" is not computational expensive since it's just a 1D vector. One can integrate power_time(t) and energy_spectrum(f) to calculate the amount of energy carried by a pulse, in Joule. Note that, the "power" returned by the time monitor is the instantaneous power, while the "power" returned by the frequency monitor is the time averaged power (therefore needs a factor of 2 to compensate the 0.5 set by default, see the sourcepower command). The sourcepower command is also used for comparison, where another factor of 2 is introduced from the integration of the negative frequencies due to Fourier transform.

By integrating the area under the above curves,

Ratio of energy_time to energy_f = 1.00111

Ratio of energy_time to energy_f_sourcepower = 0.99886

Second, an integration of Poynting vector is performed. Note that, this step could be quite computational expensive since the field data is usually a 3D matrix, especially the time domain data. Pz is used to calculate power in the both domains, using the above equation.

Ratio of energy_time_manual to energy_f_manual = 1.00111

This is an example to show that the time and frequency domain monitors record the same data without losing information during Fourier transform.