hum
result = hum(x, fs, [freq=50], [harmonics=3], [snr=20], [amplitude=], [seed=])
Input: x, fs, freq, harmonics, snr, amplitude, seed · Output: result
What it is
Adds simulated mains pickup to x, a length-N signal vector, given the sample rate fs in Hz. freq (number, Hz) is the mains fundamental, default 50. harmonics (integer count) is how many odd harmonics to include — 3 means the 1st, 3rd and 5th, i.e. 50, 150 and 250 Hz — default 3. snr (number, dB, default 20) or amplitude (number, raw units) sets the interference level, one or the other, not both. seed (integer, optional) fixes the phase/noise draw for a reproducible run.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = hum(x, fs, [freq=50], [harmonics=3], [snr=20], [amplitude=], [seed=]) | x vectorAdds simulated mains pickup to x, a length-N signal vector, given the sample rate fs in Hz.fs vectorAdds simulated mains pickup to x, a length-N signal vector, given the sample rate fs in Hz.freq number, optional (default 50)freq (number, Hz) is the mains fundamental, default 50.harmonics optional (default 3)harmonics (integer count) is how many odd harmonics to include — 3 means the 1st, 3rd and 5th, i.e.snr number, optional (default 20)snr (number, dB, default 20) or amplitude (number, raw units) sets the interference level, one or the other, not both.amplitude number, optionalsnr (number, dB, default 20) or amplitude (number, raw units) sets the interference level, one or the other, not both.seed optionalseed (integer, optional) fixes the phase/noise draw for a reproducible run. | result vector | Returns a length-N vector, x plus the interference. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
fs = 1000
t = (0 to 999) / fs
clean = sin(2 * pi * 7 * t)
h = hum(clean, fs, freq = 50, harmonics = 3, snr = 6)
e = emf(clean, fs, carrier = 150, snr = 6)
print("hum {measure_snr(clean, h):.2f} dB, emf {measure_snr(clean, e):.2f} dB")
hum 6.00 dB, emf 6.00 dB
from noise
How it works
hum(x, fs, freq = 50, harmonics = 3, snr = 20) — mains pickup, with its ODD harmonics. harmonics = 3 means 50, 150 and 250 Hz: mains arrives through a symmetric nonlinearity, which generates odd harmonics only, and a notch at the fundamental alone leaves the rest behind.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.