---
title: Gaussian random vectors
heading: Correlated noise, error ellipses and the envelope of I/Q noise
eyebrow: A11 · Lesson 23 · Gaussian random vectors
xp: 40
---

::: hook
Two sensors share a power supply, so their noise rises and falls together. A radio receiver's noise has an in-phase part and a quadrature part, and what you see on a scope is their combined size. A GPS fix comes with an error ellipse, not a single error bar. Each case is a vector of Gaussian variables, and a vector of jointly Gaussian variables is described completely by its means and its **covariance matrix**, the table of lesson 22's covariances. Linear algebra then does the rest: sums, differences, rotations and whitening are all matrix products.
:::

::: play
- The shading is the joint density of two Gaussian variables with standard deviations $\sigma_1$, $\sigma_2$ and correlation $\rho$. The curve is the 2σ ellipse, $\mathbf{x}^TC^{-1}\mathbf{x} = 4$, drawn as twice the Cholesky factor applied to a unit circle.
- Correlation tilts and stretches the ellipse, but it always holds the same 86% of the draws.
:::

```sim plot
view: flow
x: x1 = -6..6
y: x2 = -6..6
aspect: equal
slider: s1 = 0.5..2.5 step 0.1 = 1.5
slider: s2 = 0.5..2.5 step 0.1 = 1
slider: r = -0.9..0.9 step 0.1 = 0.6
shade: exp(-((x1/s1)^2 - 2*r*(x1/s1)*(x2/s2) + (x2/s2)^2)/(2*(1 - r^2))) | contours: 6
path: 2*s1*cos(2*pi*u), 2*s2*(r*cos(2*pi*u) + sqrt(1 - r^2)*sin(2*pi*u)) | over: u = 0..1 | color: ch3
readout: chance inside the 2σ ellipse = 1 - exp(-2) | digits: 3
readout: long half-axis of the 1σ ellipse = sqrt((s1^2 + s2^2 + sqrt((s1^2 - s2^2)^2 + 4*(r*s1*s2)^2))/2) | digits: 3
```

::: predict
## A receiver's noise has independent in-phase and quadrature parts, each Gaussian with standard deviation 1 mV. How often does the noise envelope, $\sqrt{I^2 + Q^2}$, exceed 3 mV?

- [ ] 0.27% of the time, like a single Gaussian beyond 3σ
- [x] About 1.1% of the time
- [ ] About 10% of the time
- [ ] Never

::: reveal
About 1.1%: $e^{-3^2/2} = e^{-4.5} = 0.011$. The envelope of two independent Gaussians is **Rayleigh**, with tail $e^{-r^2/2\sigma^2}$, which falls more slowly than one Gaussian's because two components each contribute. It's four times as likely to cross 3σ as a single Gaussian's size, which matters when a detector's threshold is set against noise.
:::
:::

::: nameit
## The covariance matrix

For a random vector $\mathbf{X} = (X_1, \ldots, X_n)$ with mean $\boldsymbol{\mu}$, the covariance matrix is $C_{ij} = \text{Cov}(X_i, X_j)$: variances on the diagonal, covariances off it. It's symmetric, and positive semidefinite, since every weighted sum has a variance that can't be negative:

$$\text{Var}(\mathbf{a}^T\mathbf{X}) = \mathbf{a}^TC\mathbf{a} \ge 0$$

For two variables, $\text{Var}(aX + bY) = a^2\sigma_X^2 + b^2\sigma_Y^2 + 2ab\rho\sigma_X\sigma_Y$.

## Jointly Gaussian vectors

$\mathbf{X}$ is **jointly Gaussian** when every weighted sum $\mathbf{a}^T\mathbf{X}$ is Gaussian. Then:
- $\boldsymbol{\mu}$ and $C$ say everything about it;
- a linear transform $\mathbf{Y} = A\mathbf{X} + \mathbf{b}$ is jointly Gaussian with mean $A\boldsymbol{\mu} + \mathbf{b}$ and covariance $ACA^T$;
- **uncorrelated means independent**, which is false for variables that aren't jointly Gaussian.

## Making and undoing correlation

Factor $C = LL^T$ (Cholesky). If $\mathbf{Z}$ holds independent standard Gaussians, $\mathbf{X} = \boldsymbol{\mu} + L\mathbf{Z}$ has covariance $C$: that's how simulations make correlated noise. Running it backward, $L^{-1}(\mathbf{X} - \boldsymbol{\mu})$ **whitens** it: independent, unit variance.

## Ellipses

The density is constant on the ellipses $(\mathbf{x} - \boldsymbol{\mu})^TC^{-1}(\mathbf{x} - \boldsymbol{\mu}) = k^2$. Their axes point along $C$'s eigenvectors, with half-lengths $k\sqrt{\lambda_i}$. In two dimensions the chance of landing inside is $1 - e^{-k^2/2}$: 39% inside $k = 1$, 86% inside $k = 2$, 99% inside $k = 3$.

## The envelope: Rayleigh and Rice

If $I$ and $Q$ are independent, each $N(0, \sigma^2)$, the envelope $R = \sqrt{I^2 + Q^2}$ has

$$P(R > r) = e^{-r^2/2\sigma^2} \qquad E[R] = \sigma\sqrt{\pi/2}$$

and the phase is uniform. Add a steady carrier and the envelope becomes **Rician**, the distribution behind a receiver's signal-plus-noise and fading with a direct path.
:::

::: example
## Two sensors have noise of 1 mV and 2 mV, correlated with $\rho$ = 0.5. What noise is on their sum, and on their difference?

::: solution
1. **The sum.**
   $$\begin{aligned} \text{Var}(X + Y) &= 1 + 4 + 2(0.5)(1)(2) \\ &= 7\ \text{mV}^2 \end{aligned}$$
   so 2.65 mV.
2. **The difference.**
   $$\begin{aligned} \text{Var}(X - Y) &= 1 + 4 - 2 \\ &= 3\ \text{mV}^2 \end{aligned}$$
   so 1.73 mV.
3. **Why the difference is quieter.** With positive correlation the difference is quieter than the sum and, here, than the larger sensor alone: shared noise cancels. That's why differential measurements, and the driven-right-leg trick in ECGs, work.

**Answer:** 2.65 mV of noise on the sum and 1.73 mV on the difference.
:::
:::

::: example
## A receiver's I and Q noise are independent with 1 mV each. Find the envelope's mean and the chance it exceeds 3 mV.

::: solution
1. **The envelope's distribution.** The envelope is Rayleigh with $\sigma$ = 1 mV.
2. **Mean.**
   $$\begin{aligned} E[R] &= \sqrt{\pi/2}\ \text{mV} \\ &= 1.25\ \text{mV} \end{aligned}$$
3. **Tail above 3 mV.**
   $$\begin{aligned} P(R > 3\text{ mV}) &= e^{-9/2} \\ &= 0.011 \end{aligned}$$
4. **Setting a threshold.** A threshold detector watching the envelope needs its threshold set from the Rayleigh tail. Set from a single Gaussian's tail instead, its false-alarm rate comes out four times too high.

**Answer:** the envelope averages 1.25 mV and exceeds 3 mV with chance 0.011.
:::
:::

::: example
## A GPS position error, east and north, has covariance $C = \begin{bmatrix}4 & 1.2\\1.2 & 1\end{bmatrix}$ m². Find its 1σ error ellipse and the chance the error falls within twice that ellipse.

::: solution
1. **Eigenvalues.** $C$'s eigenvalues satisfy
   $$\lambda^2 - 5\lambda + 2.56 = 0$$
   so $\lambda$ = 4.42 and 0.579 m².
2. **Half-axes.** The 1σ ellipse has half-axes
   $$\sqrt{4.42} = 2.10\ \text{m}$$
   $$\sqrt{0.579} = 0.76\ \text{m}$$
3. **Tilt.** Its long axis is tilted north of east by
   $$\frac12\arctan\frac{2(1.2)}{4 - 1} = 19.3^\circ$$
4. **Within twice the ellipse.**
   $$1 - e^{-2} = 0.865$$
5. **Why the ellipse matters.** Quoting "±2 m east, ±1 m north" separately would miss both the tilt and the true 86%.

**Answer:** the 1σ ellipse has half-axes of 2.10 m and 0.76 m, with its long axis 19.3° north of east, and the error falls within twice that ellipse with chance 0.865.
:::
:::

::: check
given: a = 2 | 3; b = -1 | 2 | 3; sx = 1 | 2; sy = 2 | 3; r = -0.5 | 0.3 | 0.8
answer: a^2*sx^2 + b^2*sy^2 + 2*a*b*r*sx*sy
tolerance: 0.5%

## $X$ and $Y$ have standard deviations {sx} and {sy} and correlation {r}. What is the variance of $\given{a}X + \given{b}Y$?

::: right
Right. $a^2\sigma_X^2 + b^2\sigma_Y^2 + 2ab\rho\sigma_X\sigma_Y$ = {answer}.
:::

::: misses
- [a^2*sx^2 + b^2*sy^2] That ignores the correlation. The cross term is $2ab\rho\sigma_X\sigma_Y$.
- [a*sx^2 + b*sy^2 + 2*a*b*r*sx*sy] The weights are squared in the variances.
- [any] Not yet. Use $\text{Var}(aX + bY) = a^2\sigma_X^2 + b^2\sigma_Y^2 + 2ab\rho\sigma_X\sigma_Y$.
:::
:::

::: check
given: s = 0.5 | 1 | 2; r = 1 | 2 | 4
answer: exp(-r^2/(2*s^2))
tolerance: 0.5%

## I/Q noise has independent components with standard deviation {s} mV each. What's the chance its envelope exceeds {r} mV?

::: right
Right. The envelope is Rayleigh: $P(R > r) = e^{-r^2/2\sigma^2}$ = {answer}.
:::

::: misses
- [erfc(r/(s*sqrt(2)))] That's a single Gaussian's two-sided tail. The envelope of two components is Rayleigh.
- [exp(-r^2/s^2)] The exponent is $r^2/2\sigma^2$.
- [any] Not yet. Use the Rayleigh tail, $e^{-r^2/2\sigma^2}$.
:::
:::

::: check
given: k = 1 | 1.5 | 2 | 3
answer: 1 - exp(-k^2/2)
tolerance: 0.5%

## A pair of jointly Gaussian variables is drawn many times. What fraction of the draws lands inside the ellipse $\mathbf{x}^TC^{-1}\mathbf{x} = \given{k}^2$?

::: right
Right. In two dimensions, $\mathbf{x}^TC^{-1}\mathbf{x}$ has the distribution of a sum of two squared standard Gaussians, so the fraction is $1 - e^{-k^2/2}$ = {answer}.
:::

::: misses
- [erf(k/sqrt(2))] That's the one-dimensional fraction within $\pm k\sigma$. In two dimensions it's $1 - e^{-k^2/2}$, which is less.
- [any] Not yet. Use $1 - e^{-k^2/2}$.
:::
:::

::: check
kind: parts
given: a = 4 | 9; b = 1 | 2; c = 1 | 4

## A position error has covariance $\begin{bmatrix}\given{a} & \given{b}\\\given{b} & \given{c}\end{bmatrix}$ m².

::: part
answer: sqrt(((a + c) + sqrt((a - c)^2 + 4*b^2))/2)
unit: m
tolerance: 0.5%

### What is the half-length of the 1σ ellipse's long axis?

::: misses
- [sqrt(a)] That's the east standard deviation alone. The correlation tilts and stretches the ellipse: use the larger eigenvalue.
- [((a + c) + sqrt((a - c)^2 + 4*b^2))/2] That's the eigenvalue, a variance. The half-axis is its square root.
- [any] Not yet. Find the larger eigenvalue of the matrix and take its square root.
:::
:::

::: part
answer: sqrt(((a + c) - sqrt((a - c)^2 + 4*b^2))/2)
unit: m
tolerance: 0.5%

### And of the short axis?

::: misses
- [sqrt(c)] Use the smaller eigenvalue, not the north variance.
- [any] Not yet. Take the square root of the smaller eigenvalue.
:::
:::

::: right
Right. The eigenvalues of the covariance matrix are the variances along the ellipse's own axes, and their product equals the determinant, $\given{a}\given{c} - \given{b}^2$.
:::
:::

::: check
kind: python
given: s1 = 1 | 2; s2 = 1 | 3; r = -0.7 | 0.4 | 0.9

## Build the covariance matrix `C` for standard deviations `s1` = {s1}, `s2` = {s2} and correlation `r` = {r}. Using `L = np.linalg.cholesky(C)` and `rng = np.random.default_rng(0)`, draw 200 000 correlated pairs as `X = (L @ rng.standard_normal((2, 200000))).T`. Set `Chat` to their sample covariance (`np.cov(X.T)`), and `inside` to the fraction with $\mathbf{x}^TC^{-1}\mathbf{x} < 4$.

```python starter
import numpy as np
C = np.eye(2)
X = np.random.default_rng(0).standard_normal((200000, 2))
Chat = np.cov(X.T)
inside = 0
print(Chat, inside)
```

```python solution
import numpy as np
C = np.array([[s1**2, r * s1 * s2], [r * s1 * s2, s2**2]])
L = np.linalg.cholesky(C)
rng = np.random.default_rng(0)
X = (L @ rng.standard_normal((2, 200000))).T
Chat = np.cov(X.T)
Ci = np.linalg.inv(C)
q = np.einsum("ni,ij,nj->n", X, Ci, X)
inside = np.mean(q < 4)
print(Chat, inside)
```

```python tests
import numpy as np
CC = np.array([[s1**2, r * s1 * s2], [r * s1 * s2, s2**2]])
assert np.allclose(C, CC), "C has s1², s2² on the diagonal and r·s1·s2 off it."
assert np.allclose(Chat, CC, rtol=0.02, atol=0.02 * s1 * s2), "The sample covariance should match C to within sampling error."
assert abs(inside - (1 - np.exp(-2))) < 0.005, "About 1 − e^(-2) = 86.5% of the draws should fall inside the 2σ ellipse."
```

::: right
Right. Multiplying independent unit Gaussians by the Cholesky factor gives exactly the covariance you asked for, and the 2σ ellipse holds 86.5% whatever the correlation. This is how every Monte Carlo of correlated noise starts.
:::
:::

::: check
kind: derivation
vars: sx = 0.5..3, sy = 0.5..3, r = -0.9..0.9

## Derive the variance of $X + Y$ for two variables with standard deviations $\sigma_X$, $\sigma_Y$ (written `sx`, `sy`) and correlation $\rho$ (written `r`).

::: step
answer: sx^2 + sy^2 + 2*r*sx*sy

### Expand $E[(X - \mu_X + Y - \mu_Y)^2]$ and use $\text{Cov}(X, Y) = \rho\sigma_X\sigma_Y$. What is it?
:::

::: step
answer: sx^2 + sy^2 - 2*r*sx*sy

### What is the variance of $X - Y$?
:::

::: right
Right. The sum and difference variances differ by $4\rho\sigma_X\sigma_Y$: positively correlated noise grows in a sum and cancels in a difference.
:::
:::

::: check
kind: choice

## $X$ and $Y$ are uncorrelated. When can you conclude they're independent?

- [x] When they're jointly Gaussian
- [ ] Always: uncorrelated means independent
- [ ] Never
- [ ] When they have equal variances

::: right
Right. For jointly Gaussian variables the covariance describes all the dependence, so zero covariance means none. In general it doesn't: $X$ uniform on $[-1, 1]$ and $Y = X^2$ are uncorrelated, yet $Y$ is fixed by $X$.
:::

::: misses
- [2] Correlation only measures linear dependence. $Y = X^2$ with $X$ symmetric is uncorrelated with $X$ but completely determined by it.
- [3] For jointly Gaussian variables you can.
- [4] Equal variances have nothing to do with it.
:::
:::

::: explain
## Why does a differential measurement, taking the difference of two sensors, reduce noise that both sensors pick up from the same source?

::: model
Noise from a shared source appears in both sensors with the same sign, so it's positively correlated. The variance of a difference is $\sigma_1^2 + \sigma_2^2 - 2\rho\sigma_1\sigma_2$, and a positive $\rho$ makes the cross term subtract: the shared part cancels and only the independent parts remain. If the two sensors see the shared noise equally and nothing else, $\rho$ is 1 and the difference is noise-free. The signal, meanwhile, is arranged to appear with opposite signs, so it adds in the difference.
:::
:::

::: practice

::: check
given: s = 1..12 int
answer: s*sqrt(pi/2)
tolerance: 0.5%

## I and Q noise are independent with standard deviation {s} each. What is the envelope's mean?

::: misses
- [s] The Rayleigh mean is $\sigma\sqrt{\pi/2}$, about 1.25σ.
- [any] $E[R] = \sigma\sqrt{\pi/2}$.
:::
:::

::: check
given: sx = 2 | 3; sy = 1 | 3; r = 0.5 | -0.5
answer: r*sx*sy
tolerance: 0.5%

## Two variables have standard deviations {sx} and {sy} and correlation {r}. What is the off-diagonal entry of their covariance matrix?

::: misses
- [r] The covariance is $\rho\sigma_X\sigma_Y$, not $\rho$ itself.
- [any] $\text{Cov}(X, Y) = \rho\sigma_X\sigma_Y$.
:::
:::
:::
