Skip to content

ENH: speed up vocalpy.feature._biosound.fundamental.estimate_f0 #197

Open

Description

@NickleDave

The function vocalpy.feature._biosound.fundamental.estimate_f0 (defined here) is super slow: not only for users but for us it takes up a lot of time in tests.

In #189 I ended up adding an arg to the tests that defaults to true where we only test functions that end up calling this with 1-2 files (see commit 3f6fccec) so that tests finish in 2 minutes instead of 1 hour 12 minutes.

I did some initial profiling of vocalpy.feature._biosound.fundamental.estimate_f0 with Itamar Turner-Trauring's sciagraph.
It looks like far and away the biggest slowdowns are from two calls to syn_spect, that in turn (indirectly) calls leastsq when the argument bout2[0] gets evaluated -- i.e., the slowdown is running these linear regressions.
See the line before one of these calls, where we set up the linear regression

bout2 = leastsq(residual_syn, vars, args=(f[0:fhigh], powSoundGood - powAmp))

Each call takes up about 5% of the runtime, ~40-50 "samples". So this tells us all the rest of the function takes time too, but still 10% is a lot of the time for two lines of a ~400 line function.

Very possible I'm not understanding in enough detail what's going on in the function, but my guess is we might be able to speed this up with better guesses for the initial parameters?
My thinking is that for many frames, the value is likely to be near what the previous value was, so we should set that to be the initial params.
But of course there will be sudden transitions to broad spectrum noise or silence where that is no longer true.
So maybe we could do some initial test like "if difference between spectrum of this frame and last frame are less than $epsilon$, then use the fit values from the last frame for the initial guess".
Again, they do already use another method for the initial guess so very possible I'm wrong that we could do much better. Just writing down this initial thought

Activity

  1. added
    ENH: enhancement
    Acoustic feature
    on Nov 19, 2024
  2. self-assigned this
    on Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Acoustic featureENH: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions