---
title: Normed and inner-product spaces
heading: Length, angle and projection, for signals as well as vectors
eyebrow: A14 · Lesson 37 · Normed and inner-product spaces
xp: 40
---

::: hook
A matched-filter receiver correlates the incoming waveform with a template; a Fourier coefficient correlates a signal with a sinusoid; least-squares fitting finds the closest combination of basis signals. All three are the same geometry: an **inner product** that measures how much two signals point the same way, a **norm** that measures size (for signals, the square root of energy), and **orthogonal projection**, which finds the best approximation. Once signals are vectors in an inner-product space, everything from A7's linear algebra applies to them, with integrals in place of sums.
:::

::: play
- The solid line is f(x) = x on [−π, π]; the dashed curve is $a\sin x$. The readout is the squared error $\lVert f - a\sin x\rVert^2 = \int_{-\pi}^\pi(x - a\sin x)^2dx$.
- Move a: the error is a parabola in a, smallest at a = 2. That's the projection coefficient $\frac{\langle f, \sin\rangle}{\langle\sin, \sin\rangle} = \frac{2\pi}{\pi}$.
- At the best a, the leftover error is orthogonal to sin x: nothing more of it can be explained by that direction.
:::
:::

```sim plot
view: graph
x: x = -3.1416..3.1416
y: y = -4..4
slider: a = 0..4 step 0.05 = 1
plot: x | label: f(x) = x
plot: a*sin(x) | dashed | label: a sin x
readout: squared error = 2*pi^3/3 - 4*pi*a + pi*a^2
readout: best a = 2
```

::: predict
## Over one period T, two tones $\cos(2\pi f_1t)$ and $\cos(2\pi f_2t)$ have inner product $\int_0^T\cos(2\pi f_1t)\cos(2\pi f_2t)\,dt$. When is it zero?

- [ ] Only when $f_1 = f_2$
- [x] When $(f_1 - f_2)T$ and $(f_1 + f_2)T$ are both multiples of ½, for instance a difference of exactly 1/T
- [ ] Never
- [ ] Always

::: reveal
The product is half the sum of cosines at $f_1 - f_2$ and $f_1 + f_2$, and each integrates to 0 over T when its frequency is a multiple of $\frac{1}{2T}$ (with the tones' sum large, that's the difference that matters). That's why FSK tones are spaced by multiples of $\frac{1}{2T}$: orthogonal signals don't interfere in a correlation receiver.
:::
:::

::: nameit
## Norms

A **norm** on a vector space assigns a length $\lVert v\rVert \ge 0$ with $\lVert v\rVert = 0$ only for v = 0, $\lVert cv\rVert = \lvert c\rvert\lVert v\rVert$, and $\lVert u + v\rVert \le \lVert u\rVert + \lVert v\rVert$. It gives a metric $d(u, v) = \lVert u - v\rVert$. A complete normed space is a **Banach space**.

## Inner products

An **inner product** $\langle u, v\rangle$ is linear in each slot (for real spaces), symmetric, and positive: $\langle v, v\rangle > 0$ for v ≠ 0. It defines a norm $\lVert v\rVert = \sqrt{\langle v, v\rangle}$. For functions on [a, b]:

$$\langle f, g\rangle = \int_a^bf(x)g(x)\,dx, \qquad \lVert f\rVert^2 = \int_a^bf^2 = \text{energy}$$

A complete inner-product space is a **Hilbert space**; $L^2$ (lesson 40) is the one for signals.

## Geometry

- **Cauchy–Schwarz:** $\lvert\langle u, v\rangle\rvert \le \lVert u\rVert\lVert v\rVert$, so $\cos\theta = \frac{\langle u, v\rangle}{\lVert u\rVert\lVert v\rVert}$ defines an angle.
- **Orthogonal:** $\langle u, v\rangle = 0$; then $\lVert u + v\rVert^2 = \lVert u\rVert^2 + \lVert v\rVert^2$ (Pythagoras).
- **Projection:** the multiple of e closest to f is $\frac{\langle f, e\rangle}{\langle e, e\rangle}e$, and the error is orthogonal to e. For an orthogonal set $e_1, \ldots, e_n$, project onto each separately and add: that's how Fourier coefficients are computed.

## In receivers

A correlator computes $\langle r, s\rangle$ between the received signal and a template; by Cauchy–Schwarz it's largest when r is a multiple of s, which is why the matched filter maximizes the output signal-to-noise ratio.
:::

::: example
## Project f(x) = x onto $\sin(kx)$ on [−π, π].

::: solution
1. **Inner product with $\sin kx$.**
   $$\begin{aligned} \langle x, \sin kx\rangle &= \int_{-\pi}^\pi x\sin kx\,dx \\ &= \frac{2\pi(-1)^{k+1}}{k} \end{aligned}$$
2. **Norm of $\sin kx$.**
   $$\langle\sin kx, \sin kx\rangle = \pi$$
3. **The coefficient.** Dividing gives
   $$\frac{2(-1)^{k+1}}{k}$$
   which is 2, −1, $\frac23$, ... These are the Fourier sine coefficients of x.
4. **The error with $\sin x$ alone.** The best approximation by $\sin x$ alone leaves a squared error of
   $$\frac{2\pi^3}{3} - 4\pi = 8.10$$

**Answer:** the coefficient of $\sin kx$ is $\frac{2(-1)^{k+1}}{k}$ (2, −1, $\frac23$, ...), the Fourier sine coefficients of x.
:::
:::

::: example
## Find the angle between u = (1, 2, 2) and v = (2, 0, 1).

::: solution
1. **Inner product.**
   $$\begin{aligned} \langle u, v\rangle &= 2 + 0 + 2 \\ &= 4 \end{aligned}$$
2. **Lengths.** $\lVert u\rVert = 3$ and $\lVert v\rVert = \sqrt5$.
3. **Angle.**
   $$\begin{aligned} \cos\theta &= \frac{4}{3\sqrt5} \\ &= 0.596 \end{aligned}$$
   so θ = 53.4°.

**Answer:** the angle is 53.4°.
:::
:::

::: example
## On [−1, 1] with $\langle f, g\rangle = \int fg$, orthogonalize 1, x, x² by Gram–Schmidt.

::: solution
1. **1 and x.** They're already orthogonal, since $\int_{-1}^1x\,dx = 0$.
2. **Project $x^2$ on 1.** $\langle x^2, 1\rangle = \frac23$ and $\langle 1, 1\rangle = 2$, so the component along 1 is
   $$\frac{2/3}{2} = \frac13$$
3. **Project $x^2$ on x.** $\langle x^2, x\rangle = 0$, so there's nothing to remove.
4. **Subtract.** What's left is
   $$x^2 - \frac13$$
5. **Recognize it.** That's $\frac23P_2(x)$, a multiple of the Legendre polynomial.
6. **In general.** Gram–Schmidt on the powers of x always produces the orthogonal polynomials for the chosen inner product: Legendre for this one, Chebyshev with the weight $\frac{1}{\sqrt{1 - x^2}}$.

**Answer:** the orthogonal set is 1, x and $x^2 - \frac13$.
:::
:::

::: check
given: k = 2 | 4 | 6 | 8
answer: 2*(-1)^(k + 1)/k
tolerance: 0.1%

## What's the coefficient of the best approximation of x by $c\sin(\given{k}x)$ on [−π, π]?

::: right
Right. $\frac{\langle x, \sin kx\rangle}{\langle\sin kx, \sin kx\rangle} = \frac{2(-1)^{k+1}}{k}$ = {answer}.
:::

::: misses
- [2/k] Mind the sign: $\int x\sin kx$ alternates with k.
- [any] Not yet. Divide the inner product by $\lVert\sin kx\rVert^2 = \pi$.
:::
:::

::: check
given: a = 1 | 2; b = 2 | -1; c = 2 | 3; d = 5 | 1
answer: (a*c + b*d)/(sqrt(a^2 + b^2)*sqrt(c^2 + d^2))
tolerance: 0.1%

## What's $\cos\theta$ for the vectors ({a}, {b}) and ({c}, {d})?

::: right
Right. $\frac{\langle u, v\rangle}{\lVert u\rVert\lVert v\rVert}$ = {answer}.
:::

::: misses
- [a*c + b*d] Divide by the two lengths.
- [any] Not yet. $\cos\theta = \frac{\langle u, v\rangle}{\lVert u\rVert\lVert v\rVert}$.
:::
:::

::: check
given: A = 1 | 3; T = 0.01 | 2
answer: A^2*T/2
unit: J
tolerance: 0.1%

## What's the energy $\int_0^Tx(t)^2dt$ of $x(t) = \given{A}\sin(2\pi t/T)$ over one period, T = {T} s? (Treat x as volts across 1 Ω.)

::: right
Right. $\frac{A^2T}{2}$ = {answer} J.
:::

::: misses
- [A^2*T] The average of $\sin^2$ is ½.
- [any] Not yet. $\lVert x\rVert^2 = A^2\int_0^T\sin^2 = \frac{A^2T}{2}$.
:::
:::

::: check
given: T = 1 | 0.001 | 0.0002
answer: 1/(2*T)
unit: Hz
tolerance: 0.1%

## Two tones lasting T = {T} s are to be orthogonal. What's the smallest frequency spacing that achieves it (for tones well above that spacing, starting in phase)?

::: right
Right. $\frac{1}{2T}$ = {answer} Hz.
:::

::: misses
- [1/T] That works too, but half of it is enough when the tones start in phase.
- [any] Not yet. The difference frequency must complete half a cycle in T.
:::
:::

::: check
given: u = 3 | 5; v = 4 | 2
answer: u*v
tolerance: 0.1%

## Vectors have lengths {u} and {v}. What's the largest their inner product can be?

::: right
Right. By Cauchy–Schwarz, $\lVert u\rVert\lVert v\rVert$ = {answer}, reached when they point the same way.
:::

::: misses
- [u + v] That's the triangle-inequality bound on the length of their sum.
- [any] Not yet. Cauchy–Schwarz.
:::
:::

::: check
kind: choice

## A correlation receiver compares the received signal with a template by computing their inner product. Why does the matched template give the largest output for a given signal energy?

- [ ] Because it's the longest template
- [x] By Cauchy–Schwarz, $\lvert\langle r, s\rangle\rvert \le \lVert r\rVert\lVert s\rVert$, with equality when r is a multiple of s
- [ ] Because noise is orthogonal to everything
- [ ] Because of Pythagoras

::: misses
- [1] Length is fixed by the energy.
- [3] Noise isn't orthogonal; its correlation is random.
- [4] Pythagoras concerns orthogonal vectors.
:::
:::

::: check
kind: parts
given: m = 1 | 2 | 3

## Project $x^{\given{m}}$ onto the constants in $L^2[0, 1]$.

::: part
answer: 1/(m + 1)
tolerance: 0.5%

### What is the best constant?

::: misses
- [any] The average, $\int_0^1x^m\,dx$.
:::
:::

::: part
answer: sqrt(1/(2*m + 1) - 1/(m + 1)^2)
tolerance: 0.5%

### What is the norm of the residual?

::: misses
- [any] $\lVert x^m\rVert^2 - c^2$ with $c = \frac{1}{m + 1}$, by Pythagoras.
:::
:::
:::

::: check
kind: derivation
vars: a = 0.5..3, b = 0.5..3, t = 0..3

## Vectors u and v have lengths a and b and the angle t between them.

::: step
answer: a^2 + 2*a*b*cos(t) + b^2

### What is $\lVert u + v\rVert^2$?
:::

::: step
answer: sqrt(a^2 + 2*a*b*cos(t) + b^2)

### What is $\lVert u + v\rVert$?
:::

::: right
Right. The law of cosines, from $\langle u + v, u + v\rangle$.
:::
:::

::: explain
## Why is the best approximation of f by a multiple of e given by the projection $\frac{\langle f, e\rangle}{\langle e, e\rangle}e$?

::: model
The squared error $\lVert f - ce\rVert^2 = \lVert f\rVert^2 - 2c\langle f, e\rangle + c^2\lVert e\rVert^2$ is a parabola in c, smallest where its derivative $-2\langle f, e\rangle + 2c\lVert e\rVert^2$ is zero, which gives $c = \frac{\langle f, e\rangle}{\langle e, e\rangle}$. At that c the error $f - ce$ is orthogonal to e: its inner product with e is $\langle f, e\rangle - c\langle e, e\rangle = 0$. Geometrically, the shortest line from a point to a line is perpendicular to it. For signals, that means the leftover after the best fit contains none of e, and with an orthogonal set each coefficient can be found separately.
:::
:::

::: practice

::: check
given: k = 1..10 int
answer: 2*(-1)^(k + 1)/k
tolerance: 0.1%

## Best coefficient of $\sin(\given{k}x)$ for x on [−π, π]?

::: misses
- [any] $\frac{2(-1)^{k+1}}{k}$.
:::
:::

::: check
given: A = 2 | 0.5; T = 0.1 | 5
answer: A^2*T/2
unit: J
tolerance: 0.1%

## Energy of $\given{A}\sin(2\pi t/T)$ over one period, T = {T} s?

::: misses
- [any] $\frac{A^2T}{2}$.
:::
:::

::: check
given: T = 0.1 | 0.02 | 0.001 | 0.0005 | 0.0001 | 0.00005
answer: 1/(2*T)
unit: Hz
tolerance: 0.1%

## Minimum orthogonal tone spacing for T = {T} s?

::: misses
- [any] $\frac{1}{2T}$.
:::
:::
:::
