Note
Go to the end to download the full example code.
Harmonic and percussive separation
Median-filtering HPSS: sustained tones go to the harmonic part and clicks to the
percussive part. harmonic_percussive returns one AudioSamples for each.
import numpy as np
import audio_samples as aus
from audio_samples import effects, mpl
A sustained tone mixed with clicks.
harmonic, percussive = audio.harmonic_percussive()
fig, axes = mpl.plot_waveform_comparison(
[audio, harmonic, percussive], ["Mix", "Harmonic", "Percussive"], title="HPSS"
)

The harmonic part sounds like the tone.
The percussive part sounds like the clicks.
The two parts add back up to the mix.
largest residual: 2.09e-07
Total running time of the script: (0 minutes 0.351 seconds)