A small microphone board cannot output negative voltages, so it adds a constant bias: in silence it reads about 1.65 V, and sound makes the voltage wobble above and below that. Engineers call the constant part of a signal its DC offset (DC for "direct current", the part that never changes). Over a recording, the DC offset is the mean of the samples. The sound itself is what is left after taking the offset away: a signal that wobbles around 0.
Write remove_offset(volts) that returns a pair:
- the DC offset, the mean of the samples in
volts, - a new list with the offset subtracted from every sample, in the same order.
Do not change volts. Press Run with plot(volts) and plot(remove_offset(volts)[1]) to see the same wave lifted and centred.
Examples
Input: volts = [1.75, 1.55, 1.65, 1.85, 1.45]
Output: (1.65, [0.1, -0.1, 0.0, 0.2, -0.2])
Explanation: the five samples add up to 8.25, and 8.25 / 5 = 1.65 V is the resting voltage.
Input: volts = [3, 3, 3]
Output: (3.0, [0.0, 0.0, 0.0])
Explanation: a constant signal is all offset and no sound.
Constraints
- answers are compared with a tolerance of
1e-6, so0.09999999999999987counts as0.1
Goals
- Read the mean of a signal as its constant part, the DC offset
- Subtract the offset from every sample to centre the signal on zero
- Return a new list and leave the original readings unchanged