After denoising and cleaning, I get amplitude signals like this (y-axis: dB):

On bottom left of each of these 3 graphs, you can see a noise floor (nearly "horizontal line"). This noise floor fluctuates in a range < +-1 dB.

How to detect when the real signal begins, i.e. when the signal starts increasing?

Here is what I've tried:

Let $t_i$ be the first time the signal goes higher than $noisefloor + i \ dB$. For example $t_4$ is the first time the signal goes 4 dB more than the noise floor.

Let's do a quadratic or cubic interpolation $f$ of the curve going by $(t_2, floor+2)$, $(t_4, floor+4)$, $(t_6, floor+6)$, etc.

Than let's check when the polynomial $f$ crosses the horizontal line $y = floor$.

It sometimes works, and better than all I've tried so far. But it's not perfect:

  1. Here the place where the green interpolation crosses $y = floor$ (dashed line) for the first time is more or less what I'm looking for, but there are 2 crossings, how to select the best? Sometimes it's the first to choose, sometimes it's the second..., it's quite random.

enter image description here

  1. Here the place where the green interpolation crosses $y = floor$ (dashed line) does not exist! so it doesn't work at all:

enter image description here

How to do better than this?

Note: a simple threshold-detection of when the signal goes higher than $noisefloor + 0.5 \ dB$ as "the time when the signal starts" is not precise enough for my application.

  • $\begingroup$ Did you try using a differentiator? $\endgroup$
    – Moti
    May 5, 2018 at 1:12
  • $\begingroup$ @Moti yes a diff was used in the process, before obtaining these graphs. $\endgroup$
    – Basj
    May 5, 2018 at 1:18
  • $\begingroup$ Can I please ask if this was resolved? $\endgroup$
    – A_A
    Jun 11, 2018 at 5:49
  • $\begingroup$ @A_A Yes mostly resolved, I'm currently writing an article about it, I'll post a link to ArXiv about it here $\endgroup$
    – Basj
    Jun 11, 2018 at 6:52
  • $\begingroup$ @Basj Thank you for letting me know and it would definitely be interesting to see a little bit more about this. But more generally, I am asking with respect to the outcome of this Q&A. If you think that the answer is "acceptable", can you please mark it as such (large tick mark on the left of the answer box), which would also stop the question from being circulated on the board as "unanswered" (?) $\endgroup$
    – A_A
    Jun 11, 2018 at 7:02

3 Answers 3


It is not entirely clear what sort of signal we are dealing with here, apart from the use of the "audio" tag. If the signal had a wider bandwidth then this would be closer to onset detection. But this is not what we are dealing with here. What we are dealing with here is a slow varying waveform that is considered "on", when it has emerged from some kind of background activity. This viewpoint would make it closer to Anomaly Detection or "Outlier Detection" type of problems.

There are a couple of approaches you can take here. One is to fit a model that includes an "activation" parameter and then try to see when does that parameter transits to activation and take that point as the beginning of the onset. If you set off down the path of model fitting, eventually you are going to have to train your model on a number of these curves so that it learns all the different possible "avenues to activation" there might be. For example, the third trace shows background activity, transiting to an intermediate plateau, transiting to full on activation and even in the "activated" region its slope might show further variation.

So, before you start looking at those techniques, maybe you can try the plain old technique of detecting outliers through the statistics of the signal.

As a human being (?) you seem to have a good idea of when you would like to consider this curve as being "on". Therefore, collect all samples of your signal within the "background" region and use something like a boxplot or fit a distribution to this data. The simplest example of that distribution would be a Gaussian that has a mean and standard deviation. This models your "normality" region. Any value that could have emerged from that distribution is dubious as to whether it belongs to the "background" or "activated" segments. But that is not true for all values because soon enough (as time evolves towards the right), the curve will start pushing towards extremal points of the distribution where the probability of generating such a value becomes smaller and smaller.

Putting a hard threshold there, would give you an estimate of where the "activation" region starts.

Hope this helps.


After more information about the problem was shared, I am more inclined to suggest one of the onset detection techniques which will work directly on the audio data.

In any case, the following (cave) illustrations might help a bit more with the earlier suggestions in this post.

enter image description here

The "Human being" comment comes into play when determining the point of earliest transition from "background" to "key on" (rather than doing it automatically). You use the data in the "background" part of the waveform to estimate the statistics of what it means for a sample to be coming from the "background" part and use that to determine a threshold beyond which the samples are now more likely to belong to the "key on" part.

Alternatively: enter image description here

Combine many takes at similar settings by aligning them on the "Key on" slope and summarise all of this data with a series of boxplots, each one telling you the sort of value limits you can expect at each time instance. Use that information then to choose the point in time when there is deviation from the background.

(Inset images of boxplot and distribution from this and this wikipedia articles respectively.)

  • $\begingroup$ Thank you for your answer. Some more context: the original sound files are pipe organ notes, played in solo for 10 seconds in a silent ambiance. The noise is the background noise. Then I want to detect the ADSR (only the A, and maybe R later in fact). My curve here is the result of an envelope detection (I tried several methods, and the envelope I get here is the cleaner I can get, it's actually very clean). $\endgroup$
    – Basj
    May 5, 2018 at 8:26
  • $\begingroup$ I hope I passed the Turing test, so yes, human being ;). About your paragraph about boxplot/Gaussian, just two little questions: 1) what do you mean by "background" or "activation" region? Could you give an example on the data I posted? 2) About the Gaussian model: which variable (time between what and what? amplitude difference between what and what?) should be modelled as a Gaussian? $\endgroup$
    – Basj
    May 5, 2018 at 8:30
  • 1
    $\begingroup$ @Basj Indeed. Please see updated answer. $\endgroup$
    – A_A
    May 6, 2018 at 12:16
  • $\begingroup$ Thank you very very much for your detailed updated answer. I will try such kind of things! $\endgroup$
    – Basj
    May 6, 2018 at 12:22

Have you tried plotting $ y[n] = x[n+1] - 2x[n] +x[n-1] $? It is the discrete analog of the second derivative. You might even want to apply the curvature formula, but since you are coming from horizontal there probably isn't a big difference in the results you would get.

Hope this helps.


Follow up:

I made a slight error in my comment. Here is the proper formula for the "second derivative" with spacing:

$$ x[n] = a n^2 $$

$$ x[n+s] = a n^2 + a 2 n s + a s^2 $$

$$ x[n-s] = a n^2 - a 2 n s + a s^2 $$

$$ x[n+s] - 2 x[n] + x[n-s] = 2 a s^2 $$

$$ x' = 2 a n $$

$$ x'' = 2 a $$

$$ x'' = ( x[n+s] - 2 x[n] + x[n-s] ) / s^2 $$

You should divide by $s^2$, not $s$ as I said in the comment.

  • $\begingroup$ Good idea, I'll try this @CedronDawg. As I want to keep the very part when the sound begins, I need to be able to detect very soon even a very small variation of 1st derivative or 2nd derivative (acceleration), and thus thresholding will be difficult: how to make a difference between small acceleration change (real beginning of the increasing part of signal / beginning of the sound) or small acceleration change (noise)? $\endgroup$
    – Basj
    May 5, 2018 at 12:07
  • $\begingroup$ @Basj, You can take the same measurement at various spacings: $y_s[n]=(x[n+s]-2x[n]+x[n-s])/s$. For a parabolic shape, these will be the same. The wider the spacing, the more noise resistant. Also, you could take a weighted average of several spacing results, which are combinable into a single formula once you find your best "recipe". $\endgroup$ May 5, 2018 at 14:10
  • $\begingroup$ @Basj, To find the real beginning, I would look for the peak of the "second derivative" and then scan backward until the value drops below a threshold. If your data is still "noisy", smoothing the weighted average a bit may solve your problem. $\endgroup$ May 5, 2018 at 14:21
  • $\begingroup$ @Basj, See my followup for a correction. $\endgroup$ May 6, 2018 at 2:13

Your denoising and cleaning may be part of the problem. Humans might instead pattern match the opening noisy unclean inharmonic transient to detect note onset. Which may or more likely may not be anything like a polynomial curve fit.

  • $\begingroup$ No, the denoising/cleaning/envelope creation is good: the time t0 for which my sound "begins" corresponds exactly to the time t1 for which the curve shown here stops to be horizontal and begins to increase. So the correspondance audio <-> envelope is totally ok. (I can compare with previous similar works, and here it's ok). $\endgroup$
    – Basj
    May 6, 2018 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.