Skip to content

Frequency response of discrete-time systems

Probe a discrete-time system with test sines, read its gain and phase from the difference equation, and tell straight phase from bent phase.

Before this11.3 · 12.3 · 6 more
Chapter 12 · Lesson 4 of 4

First, the picture

The leaky integrator of Difference equations (6.1) gets four test sines, one after another. Watch the gain fall as the frequency Ω\Omega grows, and the output squares lag the input dots by less and less.

Test sines through the leaky integrator

y[n] = 0.5y[n−1] + 0.5x[n], from 6.1. Each test sine has been playing for a long time.

Ω = 0.25π: the output is the same wave, 0.679 times as big and 28.7° late.

test frequency Ω
0.25π rad/sample
gain
0.679
phase
−28.7°
0.00 / 15.00 s
Describe this picture

Three panels for the leaky integrator y[n]=0.5y[n−1]+0.5x[n]y[n]=0.5y[n-1]+0.5x[n], fed test sines that have been playing for a long time. The top panel shows the test sine x[n]x[n] as stems with dot heads and the output y[n]y[n] as stems with square heads, side by side at each sample. Below it, a gain panel, ∣H∣\lvert H\rvert, and a phase panel, ∠H\angle H in degrees, share the axis Ω\Omega in rad/sample. Each test leaves a filled dot in the gain panel and a filled diamond in the phase panel, labelled with its value. There is no control.

The readouts are the test frequency, the gain and the phase. At Ω=0.25π\Omega=0.25\pi they read 0.679 and −28.7°: the output is the same wave, 0.679 times as big and 28.7° late. At 4.75 s, 0.5π0.5\pi gives 0.447 and −26.6°. At 8.25 s, 0.75π0.75\pi gives 0.357 and −14.6°. At 11.25 s, π\pi gives 0.333 and no shift: the input alternates, and the output alternates at a third of its size. At the end a thin curve in each panel, labelled “from the equation”, passes through the stamped marks, and the caption says the four tests lie on H(ejΩ)=0.5/(1−0.5e−jΩ)H(e^{j\Omega})=0.5/(1-0.5e^{-j\Omega}), read straight off the difference equation.

A test sine goes in, a scaled and shifted sine comes out

On the page Properties of LTI systems (5.4) you found that an arrow ejΩne^{j\Omega n} goes through a linear time-invariant system and comes out as the same arrow times one number. That number is H(ejΩ)=∑kh[k]e−jΩkH(e^{j\Omega})=\sum_kh[k]e^{-j\Omega k}, the DTFT of the impulse response hh from The DTFT (12.2). It is the system’s frequency response. This page measures it, reads it off a difference equation, and then asks what its angle does to a signal.

A real signal is not a single arrow. From Properties of the DTFT (12.3), a cosine is two half arrows, at +Ω+\Omega and at −Ω-\Omega, and a real hh gives H(e−jΩ)=H∗(ejΩ)H(e^{-j\Omega})=H^*(e^{j\Omega}). The two outputs are therefore a pair of conjugates, and they add to a cosine:

cos⁡(Ωn) → ∣H∣cos⁡(Ωn+∠H),\cos(\Omega n)\ \to\ \lvert H\rvert\cos(\Omega n+\angle H),

where ∣H∣\lvert H\rvert and ∠H\angle H are the size and angle of H(ejΩ)H(e^{j\Omega}) at that Ω\Omega. This holds once the test sine has been playing for a long time, so that the start-up part of the output has died away. I call that the steady state. A negative ∠H\angle H means the output crests come later than the input crests.

To get HH from a difference equation, put x[n]=ejΩnx[n]=e^{j\Omega n} and y[n]=HejΩny[n]=He^{j\Omega n} into the leaky integrator, y[n]=0.5y[n−1]+0.5x[n]y[n]=0.5y[n-1]+0.5x[n]. The delayed output is HejΩ(n−1)=e−jΩHejΩnHe^{j\Omega(n-1)}=e^{-j\Omega}He^{j\Omega n}, so

H=0.5e−jΩH+0.5⇒H(ejΩ)=0.51−0.5e−jΩ.H=0.5e^{-j\Omega}H+0.5 \quad\Rightarrow\quad H(e^{j\Omega})=\frac{0.5}{1-0.5e^{-j\Omega}}.

In general, with a0=1a_0=1, the response is ∑kbke−jΩk\sum_kb_ke^{-j\Omega k} divided by ∑kake−jΩk\sum_ka_ke^{-j\Omega k}. That is what SciPy’s freqz(b, a) computes. Its size is ∣H∣=0.5/1.25−cos⁡Ω\lvert H\rvert=0.5/\sqrt{1.25-\cos\Omega}, because ∣1−0.5e−jΩ∣2=1+0.25−cos⁡Ω\lvert1-0.5e^{-j\Omega}\rvert^2=1+0.25-\cos\Omega.

The four tests in the picture at the top lie on this H(ejΩ)H(e^{j\Omega}), and the picture ends by drawing it through them. The last test, at Ω=π\Omega=\pi, is the sine cos⁡(πn)=(−1)n\cos(\pi n)=(-1)^n, which alternates between +1+1 and −1-1. The phase is 0°0° at Ω=0\Omega=0, dips to a minimum of −30.0°-30.0° at π/3\pi/3, and returns to 0°0° at π\pi.

The gain falls from 1 at Ω=0\Omega=0 to 13\tfrac13 at Ω=π\Omega=\pi, so the leaky integrator keeps slow waves and weakens fast ones. In decibels (1.3, How big is a signal) the four tests read −3.37-3.37, −6.99-6.99, −8.94-8.94 and −9.54-9.54 dB.

A moving average, probed

A moving average replaces each sample by the mean of the last few. The 4-point version is y[n]=14(x[n]+x[n−1]+x[n−2]+x[n−3])y[n]=\tfrac14\bigl(x[n]+x[n-1]+x[n-2]+x[n-3]\bigr). If a sine fits a whole number of cycles into those four samples, the four values always cancel. So I expect the output to be exactly zero for some test sines, and nearly the input for slow ones. Watch the output go flat at 0 for two of the five tests.

A moving average, probed

y[n] = (x[n] + x[n−1] + x[n−2] + x[n−3])/4. Gain only.

Ω = 0.125π, a slow wave: the average of four samples is nearly the sample itself. Gain 0.906.

test frequency Ω
0.13π rad/sample
gain
0.906
0.00 / 16.00 s
Describe this picture

Two stacked panels for y[n]=(x[n]+x[n−1]+x[n−2]+x[n−3])/4y[n]=(x[n]+x[n-1]+x[n-2]+x[n-3])/4: the signals, as in the picture at the top, and the gain, with no phase panel. The readouts are the test frequency and the gain. The 16 s clip plays five tests and then holds on its end frame.

At Ω=0.125π\Omega=0.125\pi, a slow wave, the average of four samples is nearly the sample itself: gain 0.906 (the readout shows 0.13π rad/sample). At 0.25π0.25\pi the gain is 0.653. At 0.5π0.5\pi, one cycle every 4 samples, the four samples in the average always add to 0: gain 0. At 0.75π0.75\pi the gain is 0.271, and a little comes through. At π\pi, +1+1 and −1-1 pairs cancel: gain 0. The final caption reads “A low-pass: gain 1 at Ω = 0, and 0 wherever a whole number of cycles fits in the 4 samples, at 0.5π and π.”

When the clip has finished, a slider named “Test frequency Ω” chooses any test frequency from 0 to π\pi: drag across the gain panel, or use the arrow keys. An open ring labelled “from the formula” marks your test on the curve, and the caption gives its gain, for example “Ω = 0.30π: gain 0.524.”

Notice that the output is flat at 0 for 0.5π0.5\pi and π\pi. When the clip has finished, drag across the gain panel to try any test frequency from 0 to π\pi.

Now the formula. Each term is a delay, so H=14(1+e−jΩ+e−j2Ω+e−j3Ω)H=\tfrac14\bigl(1+e^{-j\Omega}+e^{-j2\Omega}+e^{-j3\Omega}\bigr). This is a short geometric sum, and it folds into

H(ejΩ)=e−j1.5Ω sin⁡(2Ω)4sin⁡(Ω/2).H(e^{j\Omega})=e^{-j1.5\Omega}\,\frac{\sin(2\Omega)}{4\sin(\Omega/2)}.

The fraction is the pulse spectrum of 12.2, and the factor e−j1.5Ωe^{-j1.5\Omega} is its centre shifted by 1.5 samples. The numerator is zero at Ω=0.5π\Omega=0.5\pi and π\pi, where the denominator is not. For NN points the zeros sit at Ω=2πk/N\Omega=2\pi k/N.

That is why a 12-month rolling mean removes a yearly pattern completely. One cycle per year is 2π/122\pi/12 rad per month, which is the first zero. A 7-day mean puts its first zero at 2π/72\pi/7 rad per day, and removes the weekly cycle from daily counts.

One more system, the first difference y[n]=x[n]−x[n−1]y[n]=x[n]-x[n-1] from Oversampling and noise shaping (11.3). There you fed it four test sines and plotted the dots. Its frequency response is

H=1−e−jΩ=e−jΩ/2(ejΩ/2−e−jΩ/2)=2jsin⁡(Ω/2) e−jΩ/2,H=1-e^{-j\Omega}=e^{-j\Omega/2}\bigl(e^{j\Omega/2}-e^{-j\Omega/2}\bigr)=2j\sin(\Omega/2)\,e^{-j\Omega/2},

so ∣H∣=2∣sin⁡(Ω/2)∣\lvert H\rvert=2\lvert\sin(\Omega/2)\rvert. This is the curve that page promised. The four dots of 11.3 sit on it.

00.25π0.5π0.75ππ0120.1571.0001.4141.994Ω (rad/sample)size out ÷ size in2|sin(Ω/2)|
Fig. The four test sines of 11.3, measured, on the curve 2|sin(Ω/2)| that the formula gives.

The squared curve is the power gain: 0.02460.0246, 11, 22, 3.97543.9754 and 44 at π/20\pi/20, π/3\pi/3, π/2\pi/2, 19π/2019\pi/20 and π\pi. The curve rises with Ω\Omega, so the first difference is a high-pass system, the opposite of the moving average.

The ideal low-pass cannot be built

What would a perfect low-pass look like? It would keep every frequency below a cutoff Ωc\Omega_c at gain 1 and remove all the others. In discrete time it is repeated every 2π2\pi, so on (−π,π](-\pi,\pi] it is H=1H=1 for ∣Ω∣<Ωc\lvert\Omega\rvert < \Omega_c and 0 elsewhere. Its impulse response is the inverse DTFT (12.2),

h[n]=12π∫−ΩcΩcejΩn dΩ=sin⁡(Ωcn)πn,h[0]=Ωcπ.h[n]=\frac1{2\pi}\int_{-\Omega_c}^{\Omega_c}e^{j\Omega n}\,d\Omega=\frac{\sin(\Omega_cn)}{\pi n},\qquad h[0]=\frac{\Omega_c}{\pi}.
-16-80816-0.100.10.2sample n0.25h[n]
Fig. h[n] = sin(0.25πn)/(πn): 0.25 at n = 0, zero at every other multiple of 4, and never zero for good on either side.

The stems are drawn for Ωc=0.25π\Omega_c=0.25\pi. They shrink as 1/n1/n but never stop, in either direction. So hh is not causal and not FIR (5.4): a system that responds before the input arrives, and with infinitely many taps, cannot be run. This is the discrete twin of the brick wall in Frequency response and Bode plots (8.4).

Delay hh and cut it off, and you get a filter you can run. The cut produces a ripple at the edge of the passband, the same overshoot as cutting a series short in Convergence and the Gibbs phenomenon (7.3). Designing with that trade is the subject of Window-method FIR design (19.1).

Straight phase, bent phase

Phase is a delay in disguise. In Frequency response and Bode plots (8.4, “Two delays”) you measured it in seconds. In samples, the phase delay is

τp(Ω)=−∠H(ejΩ)Ω,\tau_p(\Omega)=-\frac{\angle H(e^{j\Omega})}{\Omega},

the lateness of the crests inside a signal. The group delay is

τg(Ω)=−d∠H(ejΩ)dΩ,\tau_g(\Omega)=-\frac{d\angle H(e^{j\Omega})}{d\Omega},

the lateness of the envelope. Both use the unwrapped phase, the angle drawn without its jumps of 2π2\pi (12.2). The leaky integrator, for example, has τp=0.870\tau_p=0.870, 0.6370.637, 0.2950.295 and 0.1080.108 samples at 0.125π0.125\pi, 0.25π0.25\pi, 0.5π0.5\pi and 0.75π0.75\pi.

A pure delay of n0n_0 samples has H=e−jΩn0H=e^{-j\Omega n_0}. Its phase is the straight line −Ωn0-\Omega n_0, so τg=n0\tau_g=n_0 at every Ω\Omega and the shape passes through unchanged. A filter whose phase is a straight line is linear phase.

Two short FIR filters show the difference. The triangle (1,2,3,2,1)/9(1,2,3,2,1)/9 is the one from 12.3. Its response is

H=e−j2Ω(1+2cos⁡Ω3)2.H=e^{-j2\Omega}\left(\frac{1+2\cos\Omega}{3}\right)^2.

The bracket is squared, so it is never negative, and the phase is exactly −2Ω-2\Omega. The ramp (1,2,3)/6(1,2,3)/6 is not symmetric, and its phase bends. Watch the two group delays, minus the slopes of the phases: the triangle’s stays at 2.00 samples, and the ramp’s does not.

Straight phase, bent phase

Unwrapped phase of the triangle (1, 2, 3, 2, 1)/9 and the ramp (1, 2, 3)/6. Group delay τ_g is minus the slope.

At Ω = 0 both phases start at 0. The triangle's slope gives τ_g = 2 samples, the ramp's 1.33.

τ_g, triangle
2.00 samples
τ_g, ramp
1.33 samples
0.00 / 13.00 s
Describe this picture

One panel: the unwrapped phase ∠H\angle H in degrees against Ω\Omega in rad/sample, for the triangle (1,2,3,2,1)/9(1,2,3,2,1)/9 and the ramp (1,2,3)/6(1,2,3)/6. The triangle is a solid straight line and the ramp a dashed curve, each labelled. A dotted vertical line marks the current Ω\Omega, and on each curve a short thick segment touches it, solid on the triangle and dashed on the ramp. The readouts are the group delay τg\tau_g of each.

At Ω=0\Omega=0 both phases start at 0, and the delays read 2.00 samples for the triangle and 1.33 for the ramp. At 4.75 s, at 0.25π0.25\pi, they read 2.00 and 1.43. At the end, at 0.75π0.75\pi, they read 2.00 and 2.93, and the caption says “A straight phase delays every frequency equally; a bent one delays each by its own amount, and a mix of them changes shape.” When the clip has finished, a slider named “Frequency Ω” moves the dotted line: drag it, or use the arrow keys. At 0.6π0.6\pi the caption reads “Ω = 0.60π: triangle 2.00, ramp 2.61 samples.”

The ramp’s principal angle jumps from −180°-180° to +180°+180° at 0.608π0.608\pi. Unwrapped, it runs on smoothly to −255.4°-255.4° at 0.75π0.75\pi. When the clip has finished, drag the dotted line to read both delays at any Ω\Omega; at 0.6π0.6\pi the ramp delays by 2.61 samples.

A bent phase delays each frequency by its own amount, so a signal made of several frequencies comes out reshaped. This is phase distortion. Picture runners who all keep the same pace: they cross the line in formation. Give each a different pace and the formation breaks up.

Linear phase comes from a symmetric hh, and Linear-phase systems (17.3) builds on that. You can check it on the triangle. Its output for cos⁡(0.25πn)\cos(0.25\pi n) equals 0.648 x[n−2]0.648\,x[n-2] exactly, from n=4n=4 on. The gain 0.6480.648 is the bracket squared at 0.25π0.25\pi, and the delay is the 2 samples of the straight line.

Worked example

Take the leaky integrator and read its response at Ω=0.5π\Omega=0.5\pi by hand. Here e−j0.5π=−je^{-j0.5\pi}=-j, so H=0.5/(1+0.5j)H=0.5/(1+0.5j). Multiply top and bottom by 1−0.5j1-0.5j: H=0.5(1−0.5j)/1.25=0.4−0.2jH=0.5(1-0.5j)/1.25=0.4-0.2j. Its size is 0.16+0.04=0.4472\sqrt{0.16+0.04}=0.4472, and its angle is −arctan⁡(0.5)=−26.57°-\arctan(0.5)=-26.57°. This matches the second test in the picture at the top.

Now run the 4-point moving average from rest on cos⁡(0.5πn)\cos(0.5\pi n). The samples are 1,0,−1,0,1,…1,0,-1,0,1,\dots, so the outputs are 0.250.25, 0.250.25, then 00 from n=2n=2 on. The start-up part lasts only while the four-sample window is filling. After that the output is exactly the steady-state value, 0, which the gain of 0 predicted.

For the first difference at Ω=π/3\Omega=\pi/3, ∣H∣=2sin⁡(π/6)=1\lvert H\rvert=2\sin(\pi/6)=1, so a sine at that frequency comes out the same size. At Ω=19π/20\Omega=19\pi/20 the gain is 2sin⁡(19π/40)=1.9942\sin(19\pi/40)=1.994, close to the largest value, 2, at π\pi.

The ramp (1,2,3)/6(1,2,3)/6 at Ω=0.75π\Omega=0.75\pi has gain 0.2730.273 and group delay 2.9252.925 samples. Its largest group delay, 3.0613.061 samples, is at 0.699π0.699\pi. The triangle delays everything by exactly 2.

Where you will meet this

Every filter datasheet in discrete time is a plot of this page, a gain curve and a phase or delay curve against Ω\Omega. The moving average is the simplest smoother, and Simple smoothing filters (18.2) compares it with others. The poles and zeros that shape such curves come in Transfer functions, poles & zeros (16.3). The ideal low-pass returns, cut down to a usable length, in Window-method FIR design (19.1).

The maths behind it · eigenvalues

The frequency response is the list of a system’s eigenvalues, one for each arrow ejΩne^{j\Omega n} (5.4). In The DFT as a matrix (13.5), the DFT turns the system’s matrix, for signals of NN points, into a diagonal matrix holding these numbers.

The maths behind it · rolling means

A rolling mean of NN points in a time series is this moving average. Its zeros at 2πk/N2\pi k/N are why a 12-month rolling mean removes a yearly pattern exactly, and why a 7-day mean removes the weekly cycle from daily counts.

Reference card

QuantityFormulaNotes
Frequency responseH(ejΩ)=∑kh[k]e−jΩkH(e^{j\Omega})=\sum_kh[k]e^{-j\Omega k}the DTFT of hh
Test sinecos⁡(Ωn)→∣H∣cos⁡(Ωn+∠H)\cos(\Omega n)\to\lvert H\rvert\cos(\Omega n+\angle H)real hh, steady state
From a difference equationH=∑kbke−jΩk∑kake−jΩkH=\dfrac{\sum_kb_ke^{-j\Omega k}}{\sum_ka_ke^{-j\Omega k}}, a0=1a_0=1SciPy freqz(b, a)
Leaky integrator0.51−0.5e−jΩ\dfrac{0.5}{1-0.5e^{-j\Omega}}gain 1 at 0, 13\tfrac13 at π\pi
NN-point moving averagee−jΩ(N−1)/2sin⁡(NΩ/2)Nsin⁡(Ω/2)e^{-j\Omega(N-1)/2}\dfrac{\sin(N\Omega/2)}{N\sin(\Omega/2)}low-pass, zeros at 2πk/N2\pi k/N
First difference1−e−jΩ1-e^{-j\Omega}, size 2∣sin⁡(Ω/2)∣2\lvert\sin(\Omega/2)\rvert11.3’s curve
Ideal low-passH=1H=1 for ∣Ω∣<Ωc\lvert\Omega\rvert < \Omega_c; h[n]=sin⁡Ωcnπnh[n]=\dfrac{\sin\Omega_cn}{\pi n}never ends either way: not buildable
Phase delayτp(Ω)=−∠H/Ω\tau_p(\Omega)=-\angle H/\Omegasamples; the crests
Group delayτg(Ω)=−d∠HdΩ\tau_g(\Omega)=-\dfrac{d\angle H}{d\Omega}samples; unwrapped phase; the envelope
Linear phase∠H=−Ωn0\angle H=-\Omega n_0τg=n0\tau_g=n_0 for all Ω\Omega; symmetric hh

End of lesson 12.4

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look