---
title: The discrete-time Fourier transform
heading: The spectrum of a sequence
eyebrow: C9 · Lesson 18 · The discrete-time Fourier transform
xp: 40
---

::: hook
A sequence of samples has a spectrum just as a continuous signal does, and it's what every digital filter, audio codec and radio is designed around. The discrete-time Fourier transform, or DTFT, computes it. It looks like the Fourier transform with the integral replaced by a sum, but with one important difference that follows straight from lesson 1: discrete-time frequencies 2π apart are the same, so the spectrum of every sequence repeats every 2π. All of a sequence's frequency content lives between −π and π.
:::

::: play
- The curve is $\lvert X(e^{j\omega})\rvert$ for a block of N ones, from ω = −π to π. It's tallest at ω = 0, where it equals N, the sum of the samples.
- The nulls fall at multiples of 2π/N. Make the block longer: the main lobe narrows. A longer signal has a narrower spectrum, the time-bandwidth tradeoff again.
- The side lobes never go away: a sudden start and stop always spreads energy across frequency.
:::
:::

```sim plot
view: graph
x: w = -3.1416..3.1416 rad
y: X = 0..33
slider: N = 2..32 = 8 step 1
plot: abs(sin(N*(w + 0.000001)/2)/sin((w + 0.000001)/2)) | samples: 2000 | label: |X|
readout: peak = N | digits: 3
readout: first null, rad = 2*pi/N | digits: 3
```

::: predict
## What is the DTFT of $\delta[n - 3]$, a single 1 at n = 3?

- [ ] A pulse at ω = 3
- [x] Magnitude 1 at every frequency, with phase −3ω
- [ ] Zero except at ω = 0
- [ ] A sinc

::: reveal
$e^{-j3\omega}$: a flat magnitude of 1 and a phase falling linearly with ω. An impulse contains every frequency equally, and the delay of 3 samples shows up only in the phase, as lesson 15's linear phase.
:::
:::

::: nameit
## The transform pair

$$X(e^{j\omega}) = \sum_{n=-\infty}^{\infty} x[n]\,e^{-j\omega n}, \qquad x[n] = \frac{1}{2\pi}\int_{-\pi}^{\pi} X(e^{j\omega})\,e^{j\omega n}\,d\omega$$

X is periodic in ω with period 2π, so one period, −π to π, says everything. Low frequencies are near ω = 0 (and 2π, 4π, …); the highest is ω = π. Two values are easy: $X(e^{j0}) = \sum x[n]$ and $X(e^{j\pi}) = \sum (-1)^n x[n]$.

## Pairs

| x[n] | $X(e^{j\omega})$ |
|---|---|
| $\delta[n - n_0]$ | $e^{-j\omega n_0}$ |
| $a^n u[n]$, $\lvert a\rvert < 1$ | $\dfrac{1}{1 - ae^{-j\omega}}$ |
| 1 for n = 0 to N − 1 | $e^{-j\omega(N-1)/2}\,\dfrac{\sin(N\omega/2)}{\sin(\omega/2)}$ |
| $\dfrac{\sin\omega_c n}{\pi n}$ | 1 for $\lvert\omega\rvert < \omega_c$, 0 out to π |

The block's magnitude is N at ω = 0 with nulls at multiples of 2π/N, so its main lobe is 4π/N wide.

## Properties

- **Shift:** $x[n - n_0] \to e^{-j\omega n_0}X$.
- **Modulation:** $e^{j\omega_0 n}x[n] \to X(e^{j(\omega - \omega_0)})$; multiplying by $\cos\omega_0 n$ moves half the spectrum to $+\omega_0$ and half to $-\omega_0$.
- **Convolution:** $x * h \to XH$; the output spectrum of a filter is the input's times $H(e^{j\omega})$.
- **Parseval:** $\sum \lvert x[n]\rvert^2 = \frac{1}{2\pi}\int_{-\pi}^{\pi}\lvert X\rvert^2 d\omega$.
:::

::: example
## Find the DTFT of x = [1, 2, 1] (n = 0 to 2) and its size at ω = 0, π/2 and π.

::: solution
1. **Sum the samples.**
   $$\begin{aligned} X &= 1 + 2e^{-j\omega} + e^{-2j\omega} \\ &= e^{-j\omega}(e^{j\omega} + 2 + e^{-j\omega}) \\ &= e^{-j\omega}(2 + 2\cos\omega) \end{aligned}$$
2. **Size.**
   $$\lvert X\rvert = 2 + 2\cos\omega$$
   That's 4 at 0, 2 at π/2, and 0 at π.
3. **What it does.** It's a smoothing filter that removes the alternating component completely.

**Answer:** $X = e^{-j\omega}(2 + 2\cos\omega)$, with size 4 at ω = 0, 2 at π/2, and 0 at π.
:::
:::

::: example
## How big is the DTFT of $(0.6)^n u[n]$ at ω = π/2?

::: solution
1. **Evaluate at π/2.**
   $$\begin{aligned} \lvert X\rvert &= 1/\lvert 1 - 0.6e^{-j\pi/2}\rvert \\ &= 1/\lvert 1 + 0.6j\rvert \\ &= 1/\sqrt{1.36} \\ &= 0.857 \end{aligned}$$
2. **Compare the ends.** At ω = 0 it's 1/0.4 = 2.5 and at π it's 1/1.6 = 0.625: a low-pass shape.

**Answer:** its size at π/2 is 0.857, between 2.5 at DC and 0.625 at π.
:::
:::

::: example
## Find the DTFT of a pulse of 8 ones at ω = 0, π/8 and π/4.

::: solution
1. **Size of the DTFT.**
   $$\lvert X\rvert = \lvert\sin(8\omega/2)/\sin(\omega/2)\rvert$$
2. **At 0.** It's 8, the number of samples.
3. **At π/8.**
   $$\begin{aligned} \lvert X\rvert &= \sin(\pi/2)/\sin(\pi/16) \\ &= 1/0.1951 \\ &= 5.13 \end{aligned}$$
4. **At π/4.** Here sin(π) = 0: the first null, at $2\pi/N$.
5. **The trade-off.** A longer pulse has a narrower main lobe, which is the time-frequency trade-off.

**Answer:** its size is 8 at ω = 0, 5.13 at π/8, and 0 at π/4, the first null.
:::
:::

::: check
kind: parts
given: a = 1 | 3; b = 2 | -1; c = 4 | 1; d = -3 | 2

## x = [{a}, {b}, {c}, {d}], starting at n = 0.

::: part
answer: a + b + c + d
tolerance: 0.5%

### What is $X(e^{j0})$?

::: misses
- [any] The sum of the samples.
:::
:::

::: part
answer: a - b + c - d
tolerance: 0.5%

### What is $X(e^{j\pi})$?

::: misses
- [a + b + c + d] At ω = π, $e^{-j\pi n} = (-1)^n$: alternate the signs.
- [any] Not yet. $\sum(-1)^n x[n]$.
:::
:::
:::

::: check
kind: parts
given: N = 5 | 8 | 16 | 25

## x[n] = 1 for n = 0 to {N} − 1, and 0 elsewhere.

::: part
answer: N
tolerance: 0.5%

### What is $\lvert X(e^{j0})\rvert$?

::: misses
- [any] The sum of the samples.
:::
:::

::: part
answer: 2*pi/N
unit: rad
tolerance: 0.5%

### At what ω is the first null?

::: misses
- [pi/N] Nulls are where $\sin(N\omega/2) = 0$: Nω/2 = π.
- [4*pi/N] That's the main lobe's full width, null to null.
- [any] Not yet. ω = 2π/N.
:::
:::
:::

::: check
given: a = 0.3 | 0.6 | -0.8
answer: 1/sqrt(1 + a^2)
tolerance: 0.5%

## What is $\lvert X(e^{j\pi/2})\rvert$ for $x[n] = (\given{a})^n u[n]$?

::: right
Right. $1/\lvert 1 + ja\rvert = 1/\sqrt{1 + a^2}$ = {answer}.
:::

::: misses
- [1/(1 - a)] That's at ω = 0.
- [1/(1 + a)] That's at ω = π.
- [any] Not yet. $e^{-j\pi/2} = -j$.
:::
:::

::: check
given: n0 = 2 | 5 | 10; w = 0.3 | 0.5 | 1
answer: -w*n0*180/pi
unit: °
tolerance: 0.5%

## A sequence is delayed by {n0} samples. How much does its DTFT's phase change at ω = {w} rad, in degrees?

::: right
Right. $-\omega n_0$ = {answer}°.
:::

::: misses
- [-w*n0] That's in radians.
- [w*n0*180/pi] A delay makes the phase more negative.
- [any] Not yet. $e^{-j\omega n_0}$ adds $-\omega n_0$.
:::
:::

::: check
given: a = 0.5 | 0.8 | 0.9
answer: 1/(1 - a^2)
tolerance: 0.5%

## What is $\frac{1}{2\pi}\int_{-\pi}^{\pi}\lvert X(e^{j\omega})\rvert^2 d\omega$ for $x[n] = (\given{a})^n u[n]$?

::: right
Right. By Parseval it's the energy $\sum a^{2n}$ = {answer}.
:::

::: misses
- [1/(1 - a)] Parseval gives the energy, the sum of the squares.
- [any] Not yet. Use Parseval: $\sum\lvert x[n]\rvert^2$.
:::
:::

::: check
given: w0 = 0.5 | 1 | 2
answer: w0
unit: rad
tolerance: 0.5%

## x[n] has a spectrum concentrated near ω = 0. Where are the two copies of that spectrum in $x[n]\cos(\given{w0}n)$? (Give the positive one.)

::: right
Right. Multiplying by $\cos\omega_0 n$ moves half the spectrum to $+\omega_0$ and half to $-\omega_0$.
:::

::: misses
- [2*w0] The cosine's two exponentials each shift by $\omega_0$, one up and one down.
- [any] Not yet. Modulation shifts by $\pm\omega_0$.
:::
:::

::: check
kind: choice

## Why is every DTFT periodic in ω with period 2π?

- [ ] Because sequences are periodic
- [x] Because $e^{-j(\omega + 2\pi)n} = e^{-j\omega n}$ for every whole number n
- [ ] Because the sum has finitely many terms
- [ ] It isn't; only the DFT is periodic

::: misses
- [1] Most sequences aren't periodic; the spectrum is periodic anyway.
- [3] It's true of infinite sums too.
- [4] Every DTFT is periodic in ω, because n only takes whole values.
:::
:::

::: check
kind: parts
given: a = 0.5 | 0.8 | 0.9

## $x[n] = a^n u[n]$ with a = {a}.

::: part
answer: 1/(1 - a)
tolerance: 0.5%

### What is $\lvert X\rvert$ at ω = 0?

::: misses
- [any] $1/(1 - a)$.
:::
:::

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

### And at ω = π?

::: misses
- [any] $e^{-j\pi} = -1$: $1/(1 + a)$.
:::
:::
:::

::: check
kind: parts
given: b = 1 | 3 | -1; w = 0.5 | 1 | 2.5

## x = [1, {b}, 1] for n = 0 to 2.

::: part
answer: abs(b + 2*cos(w))
tolerance: 0.5%

### What is $\lvert X\rvert$ at ω = {w}?

::: misses
- [any] $X = e^{-j\omega}(b + 2\cos\omega)$.
:::
:::

::: part
answer: b + 2
tolerance: 0.5%

### What is X at ω = 0?

::: misses
- [any] The sum of the samples.
:::
:::
:::

::: explain
## A longer block of ones has a narrower DTFT main lobe. Why must a short signal have a wide spectrum?

::: model
To build a signal that is nonzero only for a short time, the sinusoids that make it up have to cancel everywhere outside that time and reinforce inside it. Sinusoids that differ in frequency by Δω drift out of step over about 2π/Δω samples, so to cancel within a short span the spectrum needs frequencies far apart, a wide spread. A long block can be built from frequencies close together, which stay in step over its whole length. The block's main lobe width, 4π/N, makes that tradeoff exact: halving the length doubles the width.
:::
:::

::: practice

::: check
given: a = 2 | 5; b = 1 | -3; c = 3 | 4
answer: a - b + c
tolerance: 0.5%

## $X(e^{j\pi})$ for x = [{a}, {b}, {c}]?

::: misses
- [any] Alternate the signs.
:::
:::

::: check
given: N = 4 | 10 | 20
answer: 2*pi/N
unit: rad
tolerance: 0.5%

## First null of the DTFT of {N} ones?

::: misses
- [any] 2π/N.
:::
:::

::: check
given: a = 0.25 | 0.5 | 0.6 | 0.75 | 0.8 | 0.9
answer: 1/(1 + a)
tolerance: 0.5%

## $\lvert X(e^{j\pi})\rvert$ for $(\given{a})^nu[n]$?

::: misses
- [any] $1/(1 + a)$.
:::
:::
:::
