*This jupyter notebook is part of a collection of notebooks on various topics discussed during the Time Domain Astrophysics course delivered by Stefano Covino at the [Università dell'Insubria](https://www.uninsubria.eu/) in Como (Italy). Please direct questions and suggestions to [stefano.covino@inaf.it](mailto:stefano.covino@inaf.it).*
- What we want to be able to do is to detect variability and measure the period in the face of both noisy and incomplete data. Instead we'll use Fourier decomposition to get a more useful tool for actual data analysis.
- For a periodic signal we have:
$$y(t+P)=y(t),$$ where $P$ is the period.
- We can create a *phased light curve* that plots the data as function of phase:
- Let's take the case where the data are drawn from a single sinusoidal signal:
$$y(t)=A \sin(\omega t+\phi)+\epsilon$$
- and determine whether or not the data are indeed consistent with periodic variability and, if so, what is the period.
- This model is **non-linear** in the frequency term, $\omega$ and the phase, $\phi$ and therefore We rewrite the argument as $\omega(t−t_0)$ (reexpressing the phase term) and use trigonometrics identies to rewrite the model as:
$$y(t)=a \sin(\omega t)+b \cos(\omega t)$$
- where
$$A=(a^2+b^2)^{1/2} \text{ and } \phi=\tan^{−1}(b/a)$$
- The model is now linear with respect to coefficients $a$ and $b$ (and nonlinear only with respect to frequency, $\omega$).
- where $y_i$ is the measurement (e.g., the brightness of a star) taken at time $t_i$.
- With a lof of math we do not report here, and assuming uniform priors on $a, b, \omega$, and $\sigma$ (which gives nonuniform priors on $A$ and $\phi$), the posterior distribution of parameters can be simplified to:
- To determine if our source is variable or not, we first compute $P_{\rm LS}(\omega)$ and then model the odds ratio for our variability model vs. a no-variability model.
- If our variability model is "correct", then the peak of $P(\omega)$ gives the best $\omega$ and the $\chi^2$ at $\omega = \omega_0$ is $N$.
This notebook is provided as [Open Educational Resource](https://en.wikipedia.org/wiki/Open_educational_resources). Feel free to use the notebook for your own purposes. The text is licensed under [Creative Commons Attribution 4.0](https://creativecommons.org/licenses/by/4.0/), the code of the examples, unless obtained from other properly quoted sources, under the [MIT license](https://opensource.org/licenses/MIT). Please attribute the work as follows: *Stefano Covino, Time Domain Astrophysics - Lecture notes featuring computational examples, 2025*.
"- A time-series is any sequene of observation such that the distribution of a given value depends on the previous values.\n",
"- Time is an exogeneous (outside the model) variable that is directional - measuremets only depend on the past.\n",
" - This is a statement of causality.\n",
"\n",
"- However, the exogenous variable can be anything.\n",
"\n",
"- Let'assume to have a set of data extracted from $y(t) = A \\sin(\\omega t)$ with homoscedastic variance $V = \\sigma^2 + A^2/2$.\n",
" - This is easy to prove if you compute the variance as $\\sum (y-\\lt y \\gt)^2 / N$. Since the average value is zero, this turns out to be $V = \\frac{A^2}{N} \\sum \\sin^2 (\\omega t)$ giving the $A^2/2$ term.\n",
"\n",
"- We can compute the $\\chi^2$ for this toy model:\n",
"- With no variability ($A \\sim 0$) the expectation value of the $\\chi^2_{\\rm dof} \\sim 1$ with standard deviation $\\sqrt{2/N}$, while it'll be larger in case of variability.\n",
"- Therefore, in order to have $\\chi^2_{\\rm dof} > 1 + 3 \\sqrt{2/N}$ we need $A > \\sigma \\sqrt[4]{72/N}$, which shows that with $N$ sufficiently large we can detect variability well below the uncetainty of the single points.\n"
- A time-series is any sequene of observation such that the distribution of a given value depends on the previous values.
- Time is an exogeneous (outside the model) variable that is directional - measuremets only depend on the past.
- This is a statement of causality.
- However, the exogenous variable can be anything.
- Let'assume to have a set of data extracted from ``y(t) = A \sin(\omega t)`` with homoscedastic variance ``V = \sigma^2 + A^2/2``.
- This is easy to prove if you compute the variance as ``\sum (y-\lt y \gt)^2 / N``. Since the average value is zero, this turns out to be ``V = \frac{A^2}{N} \sum \sin^2 (\omega t)`` giving the ``A^2/2`` term.
- We can compute the ``\chi^2`` for this toy model:
- With no variability (``A \sim 0``) the expectation value of the ``\chi^2_{\rm dof} \sim 1`` with standard deviation ``\sqrt{2/N}``, while it'll be larger in case of variability.
- Therefore, in order to have ``\chi^2_{\rm dof} > 1 + 3 \sqrt{2/N}`` we need ``A > \sigma \sqrt[4]{72/N}``, which shows that with ``N`` sufficiently large we can detect variability well below the uncetainty of the single points.
"""
# ╔═╡ 882fc480-b132-45a8-906a-db157059b92c
md"""
# Fourier Analysis
@@ -1107,6 +1130,7 @@ This notebook is provided as [Open Educational Resource](https://en.wikipedia.or