Every signal is a sum of sines. A filter decides which ones stay.
Ten minutes of reading. Move the sliders, then the code of the lab will read like plain sentences.
The Fourier transform
A pulse of height 1 from −T/2 to T/2 has a sinc shaped spectrum. Its value at f = 0 is the area of the pulse, T, and its zeros fall at every multiple of 1/T. Time and frequency trade against each other: a shorter pulse has a wider spectrum. That is why fast data needs a wide channel.
Output of a linear system
A linear time invariant system obeys superposition, so it treats every frequency on its own: it scales it by |H(f)| and shifts its phase by the angle of H(f). Multiplying the spectra gives Y(f); the inverse transform gives the output y(t). In the lab the inverse transform is done numerically by trapz, one value of t at a time. The same result in time is the convolution y(t) = x(t) * h(t).
Butterworth filters
The Butterworth response is maximally flat: no ripple in the passband, a smooth fall after it. butter(n, Wn, 's')designs the analog filter and returns the coefficients b and a of H(s) = B(s)/A(s); Wn is the cut off in rad/s, so 300 Hz is 2*pi*300. freqs(b, a, w) gives H at the frequencies w (rad/s). Add 'high' for a high pass filter.
Filtering in time
tf(b, a) turns the coefficients into a transfer function, and lsim(H, x, t) runs the input x through it. With 100 Hz plus 500 Hz at the input and a cut off of 300 Hz, the output is the 100 Hz tone alone, once the start is over.
The first few milliseconds are the transient: the filter starts from rest and needs time to settle. After that comes the steady state, a sine at the input frequency, scaled by |H| and delayed by the filter.
Group delay and phase delay
θ(ω) is the phase of H. A sine is delayed by the phase delay. A group of nearby frequencies, such as the envelope of a modulated signal, is delayed by the group delay. When the group delay is not constant, frequencies arrive at different times and a pulse spreads out. A Butterworth filter of order 2 or more has a delay peak a little below its cut off, and a higher order makes it taller (order 1 has no peak: its delay only falls). In MATLAB grpdelay plots the group delay of a digital filter in samples, and fvtool can overlay the phase delay.
Filters in Simulink
Lab task 2 builds the same low pass filter in Simulink. The Analog Filter Design block (DSP System Toolbox) asks for the design method (Butterworth), the type (Lowpass), the order and the passband edge frequency in rad/s: 1 kHz is 2*pi*1000.
The Filter Designer app (fdatool or filterDesigner) can design a filter and export it to a Simulink block as well. Two Sine Wave blocks and an Add block make the test signal; a Scope with two inputs shows the input and the output on one screen.
In the virtual lab
In guided mode each step ticks itself when it is really done: the right file open, the right values set, the script or the simulation run, the value read and typed. Free mode leaves you alone with every file. The report keeps each figure with the values that made it.
What you should see
| File | Settings | Result |
|---|---|---|
| ft_pulse | T = 4 | sinc with peak 4 at f = 0, zeros every 0.25 Hz |
| rc_spectrum, rc_output | R = 1.5 MΩ, C = 1 µF | cut off 0.106 Hz; the output pulse is heavily rounded |
| rc_output | R = 150 kΩ | cut off ten times higher; the output is close to the pulse |
| butter_freqs | n = 5, 10, 20, fc = 300 Hz | all three pass 0.7071 at 300 Hz; order 20 falls almost straight down |
| butter_lsim | n = 20, 100 Hz + 500 Hz | a transient, then the 100 Hz tone alone |
| grpdelay_butter, fvtool_delay | digital Butterworth, n = 6 and 10 | both delays equal at low frequency; group delay peaks near the cut off |
| task2_lpf.slx | 500 Hz + 3 kHz, edge 2*pi*1000 | the output is the 500 Hz sine |
Check yourself
Q1What is a linear communication system?
A system that obeys superposition: the response to a sum of inputs is the sum of the responses, and scaling the input scales the output. If it is also time invariant (LTI) it is fully described by its impulse response h(t) or its frequency response H(f).
Q2How is the output of a linear communication system analyzed?
In the frequency domain the output spectrum is Y(f) = H(f)X(f), and the inverse Fourier transform of Y(f) gives y(t). In the time domain the same output is the convolution y(t) = x(t) * h(t).
Q3Write down the command for simulating a low pass Butterworth filter.
Analog: [b,a] = butter(n, 2*pi*fc, 's'); then H = freqs(b,a,w) for the response and y = lsim(tf(b,a), x, t) for the output. Digital: [b,a] = butter(n, Wn) with Wn between 0 and 1, then filter(b,a,x).
Q4Write down the command for simulating a high pass Butterworth filter.
Analog: [b,a] = butter(n, 2*pi*fc, 'high', 's'). Digital: [b,a] = butter(n, Wn, 'high'). The response and output are found with freqs and lsim (or freqz and filter) as for the low pass filter.
Q5Explain the magnitude response of a low pass Butterworth filter.
|H(f)| = 1/√(1 + (f/fc)^(2n)). It is 1 at f = 0, maximally flat in the passband with no ripple, 0.7071 (−3 dB) at the cut off for every order, and falls at 20n dB per decade beyond it. A higher order gives a sharper edge.
Q6Explain the frequency response of a low pass Butterworth filter.
The frequency response H(f) has a magnitude and a phase. The magnitude is as above. The phase falls from 0 towards −nπ/2 rad as f grows and is −nπ/4 at the cut off; it is nearly linear well inside the passband, so the group delay is flat there and peaks near the cut off.
Q7Define group delay.
τg(ω) = −dθ(ω)/dω, the negative slope of the phase response. It is the delay of the envelope of a narrow band of frequencies around ω. A constant group delay means no phase distortion.
Q8Define phase delay.
τp(ω) = −θ(ω)/ω, the delay of a single sine of frequency ω passing through the filter. For a linear phase filter the phase delay and the group delay are equal.