---
title: "Room and noise lab: decay curves, level statistics, dose and reverberation"
heading: Reverberation times from a noisy impulse response by Schroeder integration, how the noise floor biases T30 but not T20, equivalent and exceeded levels from a record of levels, noise dose under two criteria, and Sabine, Eyring and critical distance for a room with several surfaces
eyebrow: S16 · Lesson 36 · Room and noise lab
xp: 60
---

::: hook
An acoustic consultant's day turns measurements into a handful of numbers: a room's reverberation time, a site's equivalent and exceeded levels, a worker's daily dose. Lessons 29 to 35 gave the definitions. In this lab you'll compute them from raw data, a synthetic impulse response with realistic fluctuations and a noise floor, a list of logged levels and a shift's exposure profile, and see where the definitions hide judgment calls.
:::

::: play
- For a noise whose level, in decibels, is Gaussian with standard deviation σ, the solid curve is how far the equivalent level sits above the median, $L_{eq} - L_{50} = 0.115\sigma^2$, and the dashed one how far $L_{10}$ sits above it, $1.28\sigma$.
- Steady noise (small σ) has all three nearly equal. Fluctuating noise, like traffic with occasional trucks, has an equivalent level pulled well above the median by the loud moments.
- Task 2 computes these statistics from a logged record without assuming any distribution.
:::

```sim plot
view: graph
x: s = 0..10
y: d = 0..15
plot: 0.1151*s^2 | label: Leq above L50, dB
plot: 1.2816*s | dashed | label: L10 above L50, dB
```

::: predict
## An impulse response with a 1.2 s reverberation time ends in noise 50 dB below its peak. What does a T30 fit report?

- [ ] Exactly 1.2 s
- [x] Noticeably too long, near 1.4 s
- [ ] Too short, near 1.0 s
- [ ] Nothing: the fit fails

::: reveal
The backward integral adds the noise's energy to every point, bending the decay curve's lower part upward; at −35 dB, only 15 dB above the floor, the bend is already significant, so the fitted slope is too shallow and T30 comes out near 1.39 s in task 1's synthetic response. T20, stopping at −25 dB, gives 1.22 s.
:::
:::

::: nameit
## What the lab computes

- **Schroeder integration**: the decay curve $10\log[\sum_{j \ge i}h_j^2/\sum_jh_j^2]$, and reverberation time from the least-squares slope s (dB/s) of the points between −5 and −35 dB (T30) or −5 and −25 dB (T20): T = −60/s.
- **Level statistics**: from N logged levels, $L_{eq} = 10\log[\frac1N\sum10^{L_i/10}]$, and the exceeded levels $L_{10}$, $L_{50}$ and $L_{90}$ read from the sorted list.
- **Dose**: each period t at level L counts $t/T_\text{allowed}(L)$, with $T_\text{allowed} = 8/2^{(L - 85)/3}$ hours for NIOSH and $8/2^{(L - 90)/5}$ for OSHA.
- **Rooms**: Sabine $0.161V/(A + 4mV)$, Eyring $0.161V/[-S\ln(1 - \bar\alpha) + 4mV]$, the room constant $R = S\bar\alpha/(1 - \bar\alpha)$ and the critical distance $\sqrt{QR/16\pi}$.
:::

::: check
kind: python

## Write `decay_curve(h2)` returning the Schroeder curve in dB, and `rt(curve, dt, top=-5, bottom=-35)` returning the reverberation time from the fit between those levels.

```python starter
import math

def decay_curve(h2):
    return [10 * math.log10(v / h2[0]) for v in h2]

def rt(curve, dt, top=-5, bottom=-35):
    return 0.0
```

```python solution
import math

def decay_curve(h2):
    out = [0.0] * len(h2)
    acc = 0.0
    for i in range(len(h2) - 1, -1, -1):
        acc += h2[i]
        out[i] = acc
    return [10 * math.log10(v / out[0]) for v in out]

def rt(curve, dt, top=-5, bottom=-35):
    pts = [(i * dt, v) for i, v in enumerate(curve) if bottom <= v <= top]
    n = len(pts)
    mx = sum(p[0] for p in pts) / n
    my = sum(p[1] for p in pts) / n
    slope = sum((x - mx) * (y - my) for x, y in pts) / sum((x - mx) ** 2 for x, _ in pts)
    return -60 / slope
```

```python tests
import math, random
dt = 1 / 8000
r = random.Random(5)
clean = [math.exp(-13.8155 * i * dt / 1.2) * r.expovariate(1) + 1e-6 for i in range(int(3 / dt))]
assert abs(rt(decay_curve(clean), dt) - 1.2) < 0.05, "With a floor 60 dB down, T30 finds 1.2 s."
noisy = [math.exp(-13.8155 * i * dt / 1.2) * r.expovariate(1) + 1e-5 for i in range(int(3 / dt))]
c = decay_curve(noisy)
assert rt(c, dt) > 1.3 and abs(rt(c, dt, -5, -25) - 1.2) < 0.05, "With the floor at −50 dB, T30 reads long; T20 still finds 1.2 s."
```

::: right
Right. The noise floor's bias is why T20 exists, and why measurements report which they used.
:::
:::

::: check
kind: python

## Write `level_stats(levels)` returning ($L_{eq}$, $L_{10}$, $L_{50}$, $L_{90}$), with $L_x$ the sorted list's entry exceeded x% of the time (nearest rank).

```python starter
def level_stats(levels):
    m = sum(levels) / len(levels)
    return m, m, m, m
```

```python solution
import math

def level_stats(levels):
    s = sorted(levels)
    n = len(s)
    leq = 10 * math.log10(sum(10 ** (L / 10) for L in levels) / n)
    pick = lambda p: s[int(round((1 - p) * (n - 1)))]
    return leq, pick(0.10), pick(0.50), pick(0.90)
```

```python tests
levels = [50 + 0.01 * k for k in range(1001)]
leq, l10, l50, l90 = level_stats(levels)
assert (l10, l50, l90) == (59.0, 55.0, 51.0), "Levels spread evenly from 50 to 60 dB: L10, L50, L90 = 59, 55, 51."
assert abs(leq - 55.92) < 0.01, "The energy average, 55.9 dB, sits above the median."
assert abs(level_stats([60] * 90 + [80] * 10)[0] - 70.4) < 0.05, "Loud 10% of the time dominates: 70.4 dB."
```

::: right
Right. The equivalent level is pulled toward the loudest moments, which is why it, not the median, predicts annoyance and hearing risk.
:::
:::

::: check
kind: python

## Write `dose(profile, criterion)` for a list of (level in dB(A), hours) and criterion "NIOSH" or "OSHA", returning percent.

```python starter
def dose(profile, criterion):
    return sum(t for L, t in profile) / 8 * 100
```

```python solution
def dose(profile, criterion):
    L0, ex = (85, 3) if criterion == "NIOSH" else (90, 5)
    return sum(t / (8 / 2 ** ((L - L0) / ex)) for L, t in profile) * 100
```

```python tests
prof = [(92, 2), (85, 4), (100, 0.5)]
assert abs(dose(prof, "NIOSH") - 375.99) < 0.05, "NIOSH: 376%."
assert abs(dose(prof, "OSHA") - 82.99) < 0.05, "OSHA: 83%, within its limit."
assert abs(dose([(85, 8)], "NIOSH") - 100) < 1e-9, "Eight hours at 85 dB(A) is exactly NIOSH's limit."
```

::: right
Right. The same shift can be four times over one limit and within another, because their exchange rates differ.
:::
:::

::: check
kind: python

## Write `room(V, surfaces, m=0.0, Q=2)` for a list of (area, α) returning (Sabine T, Eyring T, critical distance).

```python starter
def room(V, surfaces, m=0.0, Q=2):
    A = sum(S * a for S, a in surfaces)
    return 0.161 * V / A, 0.161 * V / A, 1.0
```

```python solution
import math

def room(V, surfaces, m=0.0, Q=2):
    S = sum(s for s, _ in surfaces)
    A = sum(s * a for s, a in surfaces)
    ab = A / S
    sab = 0.161 * V / (A + 4 * m * V)
    eyr = 0.161 * V / (-S * math.log(1 - ab) + 4 * m * V)
    R = S * ab / (1 - ab)
    return sab, eyr, math.sqrt(Q * R / (16 * math.pi))
```

```python tests
sab, eyr, rc = room(1000, [(300, 0.05), (200, 0.6), (100, 0.3)], 0.001)
assert abs(sab - 0.9527) < 1e-3 and abs(eyr - 0.8175) < 1e-3, "Sabine 0.95 s, Eyring 0.82 s."
assert abs(rc - 3.009) < 1e-3, "Critical distance 3.0 m for a talker with Q = 2."
```

::: right
Right. With an average absorption near 0.25, Eyring's correction is already 14%.
:::
:::

::: explain
## Why does background noise make a measured reverberation time too long rather than too short?

::: model
Schroeder's decay curve at each moment is the energy still to arrive after it. Background noise adds a steady contribution that the backward integral accumulates as if it were sound still decaying, and that added energy matters more and more as the true decay sinks toward it. The lower part of the curve is therefore lifted, it falls more slowly than the room's real decay, and a straight line fitted there has a shallower slope, which means a longer reverberation time. Fitting a shorter range, higher above the floor, or subtracting the noise's estimated contribution before integrating, avoids the bias.
:::
:::
