A4 Python for engineers · Practice
Sampling and the FFT
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
Write alias(f, fs) returning the apparent frequency of a tone f sampled at fs, in the range 0 to fs/2. Set fa = alias(f, fs) for f = 7000 Hz and fs = 10000 Hz.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter samples two tones at 8 kHz for 1600 samples. Set A to the amplitude spectrum (2 * |X| / N), f to the bin frequencies, and peaks to the sorted frequencies of the bins with amplitude above 0.1.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two tones are df = 2 Hz apart. With sample rate fs = 1000 Hz, set N to the smallest number of samples whose bin spacing is at most df, and T to the record length in seconds.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes x: a DC level plus a sine of amplitude A1 landing exactly on bin k1. From np.fft.rfft(x), set dc_est and amp_est.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes N = 1000 samples of a sine of amplitude 1 whose frequency sits at bin 50.5, between bins. Set amp_rect to the largest value of 2 * abs(np.fft.rfft(x)) / N, and amp_hann to the same for x * np.hanning(N), divided also by the Hann window's coherent gain (its mean). Then set loss_rect and loss_hann to how far each falls below 1, in dB.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A 2.5 kHz tone is sampled at 8000 samples per second for 1000 samples. Which FFT bin index (counting from 0) holds it exactly?
Check
Set nyq to the Nyquist frequency for fs = 40000 Hz, and fa to where a 30 kHz tone appears.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set f to np.fft.rfftfreq(N, 1/fs) and step to its bin spacing.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in A4