music.harmonic_series

music.harmonic_series(partials=20)[source]

The first partials harmonics, in semitones above the fundamental.

The n-th partial is at 12 * log2(n), which is what this computes. HARMONIC_SERIES_AS_PRINTED is the article’s table of the first twenty, rounded to two decimals and with one typo.

Parameters:
partialsinteger

How many, from 1 upwards. The article tabulates twenty; nothing here stops at that.

Returns:
tuple of floats

Semitones, with the fractions that make the series inequal to any tempered scale.

Raises:
ValueError

If partials is less than 1.

Parameters:

partials (int)

Return type:

tuple[float, …]

See also

midi_to_hz_interval

turns one of these semitone counts into a ratio.

Notes

Every octave is exact – partials 1, 2, 4, 8 and 16 land on 0, 12, 24, 36 and 48 – and nothing else does. The third partial is 2 cents sharp of a tempered fifth and the seventh is 31 cents flat of a tempered minor seventh, which is the size of the disagreement between this series and the tuning of scale().

Examples

>>> [round(h, 2) for h in harmonic_series(4)]
[0.0, 12.0, 19.02, 24.0]
>>> round(harmonic_series(7)[-1], 2)
33.69