# Constructing spectral components of signals using the Fourier matrix and interpreting coherence using the results

I have an EEG signal of length 2 sec. sampled at a rate of 200 Hz. If $$\vec{x}$$ denotes my signal in $$\mathbb{R}^{400}$$, then I can obtain the DFT by computing $$W\vec{x}$$, where $$W$$ denotes the 400-by-400 DFT Matrix. (I use the convention that columns are normalized.) The signal and its "two-sided ?" amplitude spectrum are the top two graphs shown below

Suppose I focus on bin #7 of 400, which corresponds to 3.5 Hz. My understanding is that, from a linear algebra perspective, I can compute the spectral component of my signal at 3.5 Hz by projecting my signal onto columns 7 and 393 (=400-7) of $$W$$ and adding the two projections together. More specifically,if $$\vec{w}_0$$ and $$\vec{w}_1$$ denote columns 7 and 393 of $$W$$, respectively, then the spectral component of $$\vec{x}$$ at frequency $$f=3.5$$ Hz is merely

$$\begin{equation*} \vec{x}_f=(\vec{x} \bullet \vec{w}_0)\vec{w}_0+(\vec{x} \bullet \vec{w}_1)\vec{w}_1 \end{equation*}$$

(I tested this principle on some simple linear combinations of sinusoids and it worked--please tell me if I'm completely off base here.) The graph of the signal component $$\vec{x}_f$$ is the sinusoid shown in the bottom graph below.

Now suppose I had a second EEG signal of same time length and sampling frequency, $$\vec{y}$$, whose spectral component at $$f=3.5$$ is denoted as $$\vec{y}_f$$. It's graph would also be a sinusoid having the same frequency as $$\vec{x}_f$$, but likely differing in amplitude and phase.

In theory is the coherence at frequency $$f$$ merely a measure describing the extent to which I could obtain the graph of $$\vec{y}_f$$ from $$\vec{x}_f$$ using a linear mapping of sorts?

Nice write-up!

The coherence for two signals $$x$$ and $$y$$ is defined as:

$$\texttt{coh}_{xy}(f) = \frac{|P_{xy}(f)|^2}{P_x(f)P_y(f)}$$ where $$P_{xy}(f)$$ is the Cross Power Spectral Density between $$x$$ and $$y$$, and $$P_x(f), P_y(f)$$ the Auto Power Spectral Densities of $$x$$ and $$y$$ respectively. Note both $$P_x(f)$$ and $$P_y(f)$$ are real functions.

It indeed provides an estimate measure of linearity between two signals $$x$$ and $$y$$ at every frequency, through an input-output lense, and is widely used in audio measurements for example, to rate the linearity of transfer function measurements.

Let's call $$X(f)$$ and $$Y(f)$$ the Fourier transforms of input $$x$$ and output $$y$$, and consider an ideal linear system $$H(f)$$, such that: $$Y(f) = H(f)X(f)$$

Then $$P_{xy} = H(f)P_x(f)$$ and $$P_y = |H(f)|^2 P_x(f)$$, and $$\texttt{coh}_{xy}(f) = \frac{|H(f)P_x(f)|^2}{P_x(f)|H(f)|^2 P_x(f)} = 1\frac{}{}$$

In plain English, if $$x$$ and $$y$$ are ideally linearly related, then the coherence at every frequency $$f$$ is $$1$$.

Of course ideal systems are un-realizable and $$\texttt{coh}$$ is merely an estimate (mainly because of measurement noise, but also less mentioned because of the finite nature of measurements).

In practice, $$\texttt{coh}_{xy}(f) \leq 1$$

• So, I'm familiar with the equation for $Coh_{xy}(f)$ in terms of power- and cross-power spectral densities, but let me ask about the equation $Y(f)=H(f)X(f)$. Is $H$ what's referred to as a "transfer function?" I don't know really much about those but I know about convolution and just learned that the preceding equation is the same as saying $y=h\ast x$ in the time domain, where $h$ is an impulse response function. So, does the ideal situation correspond to the existence of such an impulse response function $h$? Commented Dec 22, 2022 at 19:52
• Yes, $H$ is the transfer function. To be exact, $H(z)$ ($\mathbb{Z}$-transform of $h$) is the transfer function, and $H(f) = H(z = e^{j2\pi f})$ is the frequency response. The ideal situation corresponds to $H(f)$ being an ideal linear frequency response, which in practice is never the case. For example, a common estimate of $H(f)$ is $H_1 = P_{xy}(f) / P_x(f)$. Another one is $H_2 = P_{y}(f) / P_{xy}(f)$. Notice $\texttt{coh} = H1/H2$. If $H(f)$ was ideal, then of course $H_1 = H_2 = H(f)$ and you get back to $\texttt{coh} = 1$.
– Jdip
Commented Dec 22, 2022 at 21:24
• I should correct myself here: $H_2 = P_y(f)/P_{yx}(f)$
– Jdip
Commented Dec 22, 2022 at 21:32
• For clarification, when you say "linearly related," is this in the sense of superposition, $y=mx$, as opposed to the sense of affine transformation, $y=mx+b$? Would a coherence of one at a particular frequency then imply that the spectral components of $x$ and $y$ at that frequency are simply multiples of other, i.e. no phase difference? Commented Dec 23, 2022 at 18:15
• As soon as you take the squared magnitude of $P_{xy}$, all phase information is lost.
– Jdip
Commented Dec 23, 2022 at 19:10