music.normalize_mono

music.normalize_mono(sonic_vector, remove_bias=True)[source]

Normalize a mono sonic vector.

The final array will have values only between -1 and 1.

Parameters:
sonic_vectorarray_like

A (nsamples,) shaped array.

remove_biasbool

If True (default), subtract the mean and divide by the larger of the two peaks, which preserves the waveform’s shape. If False, map [min, max] onto [-1, 1] affinely, which fills the range but stretches an asymmetric waveform. Either way the result is normalized; this chooses how.

Returns:
sndarray

A numpy array with values between -1 and 1.

Examples

>>> normalize_mono([-1., -.5, 0., .5, 1.])  # already normalized
array([-1. , -0.5,  0. ,  0.5,  1. ])
>>> normalize_mono([0., 1., 2.])  # centred, then scaled
array([-1.,  0.,  1.])