A4 Python for engineers · Practice
Problem set 11: data
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
The CSV in the starter is a sensor calibration: temperature in °C and output in V. Fit a straight line with np.polyfit and set slope (V per °C), offset (V at 0 °C), and T_at to the temperature that gives 1.0 V.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The log in the starter has gaps. Read it with np.genfromtxt, then for the v column set n_good (readings present), m (their mean) and sem (their standard error, with ddof=1).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A resistance is measured as with V = 3.3 ± 0.01 V and I = 0.022 ± 0.0003 A, independent. Set R and uR (absolute, in ohms), combining the relative uncertainties in quadrature.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Model R = 4.7 kΩ ±tR% and C = 33 nF ±tC% as uniform. With rng = np.random.default_rng(7) and 100,000 draws (R first), set yld to the fraction of RC filters whose corner is within ±10% of nominal, and p5, p95 to the 5th and 95th percentiles of the corner.
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 a noisy record with one hidden tone, sampled at 2 kHz for 4000 samples. Set f_peak to the frequency of the largest FFT bin, skipping DC, and amp to that bin's amplitude estimate, 2 * |X| / N.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Tones at 1, 3.5, 6, 9.2 and 13 kHz reach an ADC sampling at fs = 10000 Hz with no filter. Set aliases to the list of the frequencies (in Hz) where each appears, and clean to the list of input tones that appear at their true frequency.
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 a noisy exponential decay (with in ms). Fit a straight line to against with np.polyfit, and set tau_est from its slope and V0_est from its intercept.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A pressure sensor's calibration table maps pressure (kPa) to output voltage: 0 → 0.20, 20 → 0.95, 50 → 1.90, 100 → 3.10, 150 → 3.95, 200 → 4.60 V. Using np.interp on the inverted table, set p to the pressures for the starter's readings, with np.nan for any reading outside the table's voltage range, and n_out to how many readings were outside.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter has a slow signal clean, and x, the same signal with noise and occasional large glitches. Set ma to an N-point moving average of x (5 points, "same" mode), med_ma to the same moving average applied after a 5-point median filter (pad the median's output back to full length by repeating its first and last values twice), and err_ma, err_med to each one's RMS error against clean over samples 20 to 479.
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