\chapter{Spectral analysis}

\section{The Fourier Transform}
Complex numbers... magnitude and phase

Time domain --- Frequency domain, Fourier Space

\subsection{Fast Fourier transform}

\section{Power spectrum}
\[ S_{x,x} = |X(f)|^2 \]

Parceval theorem:
\[ \int_{-\infty}^{+\infty} x(t)^2 dt = \int_{-\infty}^{+\infty} |X(f)|^2 df \]

Autocorrelation:

Wiener-Kinchin theorem:
\[ {\cal F}\{Corr(x,x)\} = |X(f)|^2 \]

\section{Spectrogram}

\section{Cross spectrum}
\[ S_{x,y} = X(f)Y^*(f) \]
is complex valued (magnitude and phase)!

Correlation theorem:
\[ {\cal F}\{Corr(x,y)\} = X(f)Y^*(f) = S_{x,y} \]

\section{Transfer function}
The complex valued transfer function of a linear, noiseless system
relating stimulus $s(t)$ and response $r(t)$ is
\begin{equation}
  \label{transfer}
  H(\omega) = \frac{R(\omega)}{S(\omega)}
\end{equation}
where $S(\omega)$ and $R(\omega)$ are the Fourier transformed stimulus
and response, respectively. By means of the transfer function, the
response of the system to a stimulus can be predicted according to
\begin{equation}
  R(\omega) = H(\omega) S(\omega)
\end{equation}

Now, if the system is noisy, then the transfer function can only
predict the mean response $\langle R \rangle_n$, averaged over the
noise, i.e. averaged over responses evoked by several presentations
of the same, frozen stimulus:
\begin{equation}
  \langle R(\omega) \rangle_n = H(\omega) S(\omega)
\end{equation}

Both sides of this equation can be multiplied by the complex conjugate
stimulus $S^*(\omega)$. Since the stimulus is always the same,
$S^*(\omega)$ can be pulled into the average over the noise and we get
\begin{equation}
  \langle R(\omega)S^*(\omega) \rangle_n = H(\omega) S(\omega)S^*(\omega)
\end{equation}
The right hand side can also be averaged over the noise, but it makes
no difference, because neither $S(\omega)$ nore $H(\omega)$ depend on
the noise. In addition, we can average both sides over different
realizations of the stimulus. We denote this average by $\langle \cdot
\rangle_s$. Because the transfer function does note depend on the
stimulus it can be pulled out of the stimulus average and we get
\begin{equation}
  \langle\langle R(\omega)S^*(\omega) \rangle_n\rangle_s = H(\omega) \langle \langle S(\omega)S^*(\omega) \rangle_n \rangle_s
\end{equation}

Finally, let's solve for the transfer function and denote both
averages by $\langle \cdot \rangle$:
\begin{equation}
  \label{transfercsd}
  H(\omega)  = \frac{\langle R(\omega)S^*(\omega) \rangle}{\langle S(\omega)S^*(\omega) \rangle}
\end{equation}
The transfer function of a noisy system is estimated by dividing the
cross spectrum by the power spectrum of the stimulus.

Computing the squared gain like this
\begin{equation}
  |H(\omega)|^2 = \frac{R(\omega)R^*(\omega)}{S(\omega)S^*(\omega)}
\end{equation}
is not possible, it again requires to average over the noise
\begin{equation}
  |H(\omega)|^2 = \frac{\langle R(\omega)R^*(\omega) \rangle_n}{S(\omega)S^*(\omega)}
\end{equation}
Subsequent averaging over stimuli leads to
\begin{equation}
  |H(\omega)|^2 = \left\langle\frac{\langle R(\omega)R^*(\omega) \rangle_n}{S(\omega)S^*(\omega)} \right\rangle_s
\end{equation}
which is \emph{not} just the power spectrum $\langle R R^* \rangle$ of
the response devided by the power spectrum $\langle S S^* \rangle$ of
the stimulus
\begin{equation}
  |H(\omega)|^2 \ne \frac{\langle\langle R(\omega)R^*(\omega) \rangle_n\rangle_s}{\langle S(\omega)S^*(\omega)\rangle_s}
\end{equation}
The gain can not be computed by simply dividing the response spectrum
by the stimulus spectrum.

\section{Coherence function}

\subsection{Forward and reverse filter}
