\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} \label{transfernoise} \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. If we are interested in the gain of the transfer function, i.e. its magnitude, we get starting from Eq.~\eqref{transfernoise} \begin{eqnarray} |\langle R(\omega) \rangle_n| & = & |H(\omega)| |S(\omega)| \\ \langle R(\omega) \rangle_n \langle R(\omega) \rangle_n^* & = & |H(\omega)|^2 S(\omega)S^*(\omega)\\ \langle \langle R(\omega) \rangle_n \langle R(\omega) \rangle_n^* \rangle_s & = & |H(\omega)|^2 \langle S(\omega)S^*(\omega) \rangle_s \\ |H(\omega)|^2 & = & \frac{\langle \langle R(\omega) \rangle_n \langle R(\omega) \rangle_n^* \rangle_s}{\langle S(\omega)S^*(\omega) \rangle_s} \\ |H(\omega)|^2 & \ne & \frac{\langle \langle R(\omega) R^*(\omega) \rangle_n \rangle_s}{\langle S(\omega)S^*(\omega) \rangle_s} \end{eqnarray} For noisy systems, dividing the power spectrum of the response by the power spectrum of the stimulus is not resulting in the squared gain of the transfer function. Only for noise-free systems does this work. \section{Coherence function} \subsection{Forward and reverse filter}