A4 Python for engineers · Practice
Lab: measuring and plotting signals
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 starter captures v = −1.2 + 1·sin(2π·440·t) at 100 kHz for 5000 samples. Using the lesson's recipe, set vpp, freq (from interpolated upward crossings of v - v.mean()), and mean and rms (AC RMS) over the whole cycles between the first and last upward crossings.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A source of V = 5 V with internal resistance Rs drives a load RL. With Rs from the starter as a column and RL = np.logspace(0, 4, 401) as a row, compute the load power on the whole grid with broadcasting (no loops). Set P (shape (4, 401)), best to each row's best load and Pmax to each row's largest power.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
On one figure, plot the gain in dB of a second-order low-pass, , with f0 = 200 Hz, for = 0.5, 0.707 and 2, over f = np.logspace(np.log10(f0) - 2, np.log10(f0) + 2, 400). Use a log frequency axis, label both axes with units, and give each curve a legend label containing its Q, such as "Q = 0.707".
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 10 000 readings with noise of standard deviation s = 0.5 mV around 1.000 V. Set counts, edges = np.histogram(err_mV, bins=50) for the errors in millivolts, within1 to the fraction of errors within one sample standard deviation of zero, and within3 to the fraction within three.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An amplifier with gain g = 3 clips at ±L = 5 V. For an input of 3 V amplitude at 50 Hz over 40 ms (2000 samples), plot the output against time in ms as a line, then mark only the clipped samples with red dots ('r.'), using a mask. Label both axes. Set frac to the fraction of samples clipped.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A sine of amplitude 5 V is sampled finely over whole cycles. What fraction of the samples exceed V in size?
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