question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adaptive waveplot

See original GitHub issue

Is your feature request related to a problem? Please describe.

display.waveplot works by downsampling the input waveform to get an amplitude envelope, rather than the raw samples.

This is great when we want a big-picture view of a long signal, but it’s pretty lousy when we’re looking at a signal close up. The max_points parameter sets a threshold of sample counts, below which the raw signal is displayed.

The problem is that there’s no easy way to switch between the two modes based on the actual display limits of plot in question. For example, it’d be nice to be able to just waveplot some data, set the axis limits later, and have the plot decide dynamically whether to show the aggregated envelope or the raw samples. Even better, for interactive backends (ipympl, qt), a user could zoom in or out, and the plot should update automatically.

Describe the solution you’d like

The matplotlib example gallery shows how to do this kind of thing using a callback for whenever the display limits change. The example there isn’t perfect: it recomputes the downsampled signal on any limit change, including panning (not just zooming), so it’s likely pretty slow. But I think we could adapt it to be more efficient.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
phdoddscommented, Aug 31, 2020

Hi Brian (@bmcfee), If this is still open, I could take a crack at it. I recently had to solve a similar problem.

1reaction
bmcfeecommented, May 14, 2021

Looks like multi-plotting actually does work!

y, sr = librosa.load(librosa.ex('trumpet'))
yh, yp = librosa.effects.hpss(y, margin=2)

fig, ax = plt.subplots(figsize=(6, 3))
o1 = waveshow(yh, sr=sr, ax=ax, alpha=0.75, label='Harmonic')
o2 = waveshow(yp, sr=sr, ax=ax, alpha=0.75, label='Percussive')
o3 = waveshow(y-yp-yh, sr=sr, ax=ax, alpha=0.75, label='Residual')
ax.legend(loc='upper right', labelcolor='markerfacecolor', ncol=1)

when zoomed out (envelope mode):

waveshow-multi-1

and then zoomed in (samples mode):

waveshow-multi-2

And here’s a video embed of it running interactively:

https://user-images.githubusercontent.com/1190540/118262220-94cad100-b482-11eb-8131-ff875cf8797b.mp4

At this point I’m pretty happy with the implementation. There are still a few rough edges to work out, mostly around how kwargs are handled for the different artists, and how axes limits are set. I’ll try to smooth these out in the coming days and then open a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

librosa.display.AdaptiveWaveplot
A helper class for managing adaptive wave visualizations. This object is used to dynamically switch between sample-based and envelope-based visualizations of ...
Read more >
Speech Emotion Recognition | Kaggle
Speech Emotion Recognition · Visualization¶ · Showing spectogram and waveplot¶ · Waveplot¶ · Spectogram¶ · Augmentation (Noise Injection)¶ · Fearure Extraction¶.
Read more >
librosa.display.waveplot — librosa 0.6.0 documentation
Plot the amplitude envelope of a waveform. If y is monophonic, a filled curve is drawn between [-abs(y), abs(y)]. If y is stereo,...
Read more >
Astrophysical signal consistency test adapted for gravitational ...
In this work, we assess the performance of wavegraph clustering in real LIGO and Virgo noises (the sixth science run and the first...
Read more >
| notebook.community
Combination of adaptive quantization with LMS adaption of predictor ... 10)) plt.subplot(2,1,1) librosa.display.waveplot(x, sr=sampling_rate) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found