Skip to content

Commit d1c7cac

Browse files
author
Martin Glesser
authored
Merge pull request #71 from wantysal/sii
Speech intelligibility index (ANSI S3.5)
2 parents b6bf207 + 68e961b commit d1c7cac

File tree

20 files changed

+1898
-19
lines changed

20 files changed

+1898
-19
lines changed

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ authors:
44
- family-names: Green Forge Coop
55
given-names:
66
title: MOSQITO
7-
version: 1.0.8
7+
version: 1.1
88
doi: 10.5281/zenodo.6675733
9-
date-released: 2022-06-21
9+
date-released: 2023-12-21
1010
keywords:
1111
- audio
1212
- python

mosqito/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from mosqito.sound_level_meter.noct_spectrum.noct_spectrum import noct_spectrum
2+
from mosqito.sound_level_meter.noct_spectrum.noct_synthesis import noct_synthesis
3+
from mosqito.sound_level_meter.spectrum import spectrum
24

35
from mosqito.sq_metrics.loudness.loudness_ecma.loudness_ecma import loudness_ecma
46
from mosqito.sq_metrics.loudness.loudness_zwst.loudness_zwst import loudness_zwst
@@ -27,6 +29,10 @@
2729
from mosqito.sq_metrics.sharpness.sharpness_din.sharpness_din_perseg import sharpness_din_perseg
2830
from mosqito.sq_metrics.sharpness.sharpness_din.sharpness_din_freq import sharpness_din_freq
2931

32+
from mosqito.sq_metrics.speech_intelligibility.sii_ansi.sii_ansi import sii_ansi
33+
from mosqito.sq_metrics.speech_intelligibility.sii_ansi.sii_ansi_freq import sii_ansi_freq
34+
from mosqito.sq_metrics.speech_intelligibility.sii_ansi.sii_ansi_level import sii_ansi_level
35+
3036
from mosqito.sq_metrics.loudness.utils.sone_to_phon import sone_to_phon
3137
from mosqito.utils.isoclose import isoclose
3238
from mosqito.utils.load import load
@@ -36,8 +42,9 @@
3642
# Colors and linestyles
3743
COLORS = [
3844
"#69c3c5",
39-
"#9969c4",
40-
"#c46b69",
41-
"#95c469",
42-
"#2a6c6e",
45+
"#ffd788",
46+
"#ff8b88",
47+
"#7894cf",
48+
"#228080",
49+
"#a8e2e2"
4350
]
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from mosqito.sound_level_meter.noct_spectrum.noct_spectrum import noct_spectrum
22
from mosqito.sound_level_meter.noct_spectrum.noct_synthesis import noct_synthesis
3-
3+
from mosqito.sound_level_meter.spectrum import spectrum
4+
from mosqito.sound_level_meter.freq_band_synthesis import freq_band_synthesis
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Standard library import
4+
from numpy import array, concatenate, zeros, log10, power, argmin, split, arange, interp, iscomplex
5+
6+
def freq_band_synthesis(spectrum, freqs, fmin, fmax):
7+
"""Adapt input spectrum to frequency band levels
8+
9+
Convert the input spectrum to frequency band spectrum
10+
between "fmin" and "fmax".
11+
12+
Parameters
13+
----------
14+
spectrum : numpy.ndarray
15+
One-sided spectrum of the signal in [dB], size (nperseg, nseg).
16+
freqs : list
17+
List of input frequency , size (nperseg) or (nperseg, nseg).
18+
fmin : float
19+
Min frequency band [Hz].
20+
fmax : float
21+
Max frequency band [Hz].
22+
n : int
23+
Number of bands pr octave.
24+
G : int
25+
System for specifying the exact geometric mean frequencies.
26+
Can be base 2 or base 10.
27+
fr : int
28+
Reference frequency. Shall be set to 1 kHz for audible frequency
29+
range, to 1 Hz for infrasonic range (f < 20 Hz) and to 1 MHz for
30+
ultrasonic range (f > 31.5 kHz).
31+
Outputs
32+
-------
33+
spec : numpy.ndarray
34+
Third octave band spectrum of signal sig [dB re.2e-5 Pa], size (nbands, nseg).
35+
fpref : numpy.ndarray
36+
Corresponding preferred third octave band center frequencies, size (nbands).
37+
"""
38+
if iscomplex(spectrum).any():
39+
raise ValueError('Input spectrum must be in dB, no complex value allowed.')
40+
41+
if (fmin.min() < freqs.min()):
42+
print("[WARNING] Input spectrum minimum frequency if higher than fmin. Empty values will be filled with 0.")
43+
df = freqs[1] - freqs[0]
44+
spectrum = interp(arange(fmin.min(),fmax.max()+df, df), freqs, spectrum)
45+
freqs = arange(fmin.min(),fmax.max()+df, df)
46+
47+
if (fmax.max() > freqs.max()):
48+
print("[WARNING] Input spectrum maximum frequency if lower than fmax. Empty values will be filled with 0.")
49+
df = freqs[1] - freqs[0]
50+
spectrum = interp(arange(fmin.min(),fmax.max()+df, df), freqs, spectrum)
51+
freqs = arange(fmin.min(),fmax.max()+df, df)
52+
53+
# Find the lower and upper index of each band
54+
idx_low = argmin(abs(freqs[:,None] - fmin), axis=0)
55+
idx_up = argmin(abs(freqs[:,None] - fmax), axis=0)
56+
idx = concatenate((idx_low, [idx_up[-1]]))
57+
58+
# Split the given spectrum in several bands
59+
bands = array(split(spectrum, idx), dtype=object)[1:-1]
60+
61+
# Compute the bands level
62+
band_spectrum = zeros((len(bands)))
63+
i = 0
64+
for s in bands:
65+
band_spectrum[i] = 10*log10(sum(power(10,s/10)))
66+
i += 1
67+
68+
return band_spectrum, (fmin+fmax)/2
69+
70+
71+
72+
73+
74+

mosqito/sound_level_meter/noct_spectrum/noct_synthesis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
def noct_synthesis(spectrum, freqs, fmin, fmax, n=3, G=10, fr=1000):
1313
"""Adapt input spectrum to nth-octave band spectrum
14+
1415
Convert the input spectrum to third-octave band spectrum
1516
between "fc_min" and "fc_max".
1617
Parameters

mosqito/sq_metrics/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@
3232
from mosqito.sq_metrics.sharpness.sharpness_din.sharpness_din_freq import sharpness_din_freq
3333

3434
from mosqito.sq_metrics.loudness.utils.sone_to_phon import sone_to_phon
35+
36+
from mosqito.sq_metrics.speech_intelligibility.sii_ansi.sii_ansi import sii_ansi
37+
from mosqito.sq_metrics.speech_intelligibility.sii_ansi.sii_ansi_freq import sii_ansi_freq
38+
from mosqito.sq_metrics.speech_intelligibility.sii_ansi.sii_ansi_level import sii_ansi_level

mosqito/sq_metrics/loudness/loudness_zwst/_main_loudness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def _main_loudness(spec_third, field_type):
226226
# taking into account the dependance of absolute threshold
227227
# within this critical band
228228
korry = 0.4 + 0.32 * nm[0] ** 0.2
229-
nm[0, korry <= 1] *= korry
229+
nm[0, korry <= 1] *= korry[korry <= 1]
230230
# nm[:, -1] = 0
231231
# if spec_third.ndim == 1 or spec_third.shape[1] == 1:
232232
# # This is only for test_loudness_zwicker_3oct because only one array of one col is given and this routine needs 2 or more

0 commit comments

Comments
 (0)