The ideal filter
We sample at 8000 Hz and want a lowpass filter: keep everything below 1000 Hz, remove everything above. The ideal answer is a brick wall: gain 1 up to the cutoff, gain 0 after it.
Run the brick wall backwards through the inverse DTFT (the DTFT lesson, run in reverse) and you get its impulse response: hi[m] = sin(ωc·m)/(π·m), a sinc. Its middle value is ωc/π = 0.25. It never ends, in either direction, so no machine can run it.
A filter cannot use inputs that have not arrived. So slide the sinc right by 10 samples: hd[n] = hi[n − 10]. The peak now sits at n = 10. A delay only adds a 1.25 ms lag; it leaves the gain alone.
Cut it short
Keep only n = 0 to 20: 21 numbers, called taps. Throwing the rest away is the same as multiplying by a rectangle window, 1 inside and 0 outside. Now it is a real FIR filter.
The 21-tap response wiggles. It overshoots to 1.073 near 643 Hz (7.3% too high), and in the stopband its biggest ripple is only −19.6 dB: about one tenth of the input gets through. These ripples come from the sharp cut.
Multiplying by a rectangle in time smears the brick wall with the rectangle's spectrum, whose side lobes are big. With 61 taps the edge gets steeper, but the overshoot grows to 8.4%. It heads for about 9%, never zero: the Gibbs phenomenon.
Window it
Instead of a hard cut, fade the taps out. The Hamming window w[n] = 0.54 − 0.46·cos(2πn/20) is 0.08 at both ends and 1 in the middle. Its spectrum has much smaller side lobes than the rectangle's.
Each tap is multiplied by its window value: h[n] = hd[n]·w[n]. The middle stays almost whole; the ends shrink. For example h[4] = −0.0531 × 0.3979 = −0.0211. These 21 numbers are the filter.
Now the gain never rises above 1.004 and the stopband stays below −49.8 dB, against −19.6 dB before. The price: a wider transition. The gain first reaches zero at 1743 Hz instead of 1221 Hz.
Use it
Load the taps into the filter and feed it two tones. 500 Hz comes out at −0.31 dB, almost untouched. 2000 Hz comes out at −49.8 dB: about 300 times smaller in amplitude. The filter does what we asked.
In Python 3 with numpy, the design is four lines. np.sinc(x) means sin(πx)/(πx), so 0.25*np.sinc(0.25*m) is the ideal sinc. scipy.signal.firwin(21, 1000, fs=8000) does the same, then scales the gain at 0 Hz to exactly 1.
The working
# step 1/11 · ask
fs = 8000 samples per second
highest frequency: fs/2 = 4000 Hz
ask: gain 1 for 0 .. 1000 Hz (passband)
gain 0 for 1000 .. 4000 Hz (stopband)
cutoff as an angle per sample:
ωc = 2π·1000 / 8000 = π/4 rad
plots: gain against frequency,
plain (0 .. 1.2) and in decibels (dB)
The sample rate, the 1000 Hz cutoff and the 21 taps are a chosen example; every tap, gain and dB figure is computed from this model with the DTFT sum on a 1 Hz grid, and the Python card was checked with numpy. Gains are plain ratios of output to input amplitude; dB = 20·log10(gain). Oppenheim & Schafer's Table 7.2 lists peak stopband errors of about −21 dB (rectangle) and −53 dB (Hamming); those are for long filters. With only 21 taps this design measures −19.6 dB and −49.8 dB.