Measuring noise floor in an impulse response 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.
I can suggest you take a look at the supporting information for Dirac software, where they describe the process of INR (IR to Noise Ratio) calculation. 
The simplest approach is to estimate the noise level based on the beginning of the IR before the main peak. For that purpose, you can also do the tail of the Impulse response.

Yet another article supporting that estimation is by Lundeby et al.: "Uncertainties of Measurements in Room Acoustics". Their algorithm is an iterative procedure which tries to estimate the background noise level and the slope:



You could also try to verify that the noise floor doesn't have any distortions, by fitting the linear regression and making sure that the slope is as close to 0 as possible.