Say I have an impulse response...
(an envelope of the actual IR obtained using the Hilbert transform)
... question: how do I calculate the surrounding noise level? Visually this looks to be ~ -54 dB w.r.t. the peak.
But before you say something like "just average the surrounding parts" (ok maybe with better technical terminology), I would actually like to determine the noise level programmatically, in order to deal with wider peaks, like...
Just arbitrarily taking some noise samples could accidentally include part of the peak and obviously invalidate the result.
My hunch: set a threshold as the minimum number of samples above some level X such that this level can be considered to be noisy. This could work well in the first case - as you increase X to above ~ -54 dB the number of samples above suddenly drops by a significant amount.
This approach may not work so well in the second case as the decay range consists of more samples (the increase may not be so significant). I could extend the sampling time... but I can only hold my breath for so long when recording.