Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
c339f7a
creando carpetas iniciales
TinaTabo Nov 10, 2021
ea4c3c0
Comenzamos...
TinaTabo Nov 17, 2021
e2ea23d
haciendo primeras pruebas + numpy funciona
TinaTabo Nov 17, 2021
b7d874c
primera prueba de lectura correcta
TinaTabo Nov 17, 2021
b2d39ac
lee e imprime el fichero.csv
TinaTabo Nov 17, 2021
349aea8
2º objetivo conseguido
TinaTabo Nov 17, 2021
030ad1e
3º objetivo conseguido
TinaTabo Nov 17, 2021
546229f
notas añadidas
TinaTabo Nov 17, 2021
4cb834c
funcion para extraer los datos.csv en un dict
TinaTabo Nov 18, 2021
2b7a5ad
4º objetivo funcionando
TinaTabo Nov 18, 2021
000d679
itera lista Lp_promedio
TinaTabo Nov 18, 2021
5d45af7
iteracion lista para empezar a comparar Lp
TinaTabo Nov 18, 2021
df31e72
rangos de frec definidos correctamente
TinaTabo Nov 18, 2021
586e40d
Obtenidas las posiciones de los tonos en la lista
TinaTabo Nov 19, 2021
7db614a
Diccionario tonos prominentes funciona!
TinaTabo Nov 19, 2021
9344480
transformado en función
TinaTabo Nov 19, 2021
1aad24b
pide el nombre del fichero de datos por consola
TinaTabo Nov 19, 2021
9c8120a
retoques
TinaTabo Nov 19, 2021
4e996d5
creado programa de prueba --> FUNCIONA!!
TinaTabo Nov 19, 2021
bf691aa
nuevo archivo.csv de pruebas
TinaTabo Nov 19, 2021
197e00f
prueba 2 superada
TinaTabo Nov 19, 2021
e575502
empezando prog Kt
TinaTabo Nov 29, 2021
92707de
probando
TinaTabo Nov 29, 2021
d480cb2
la idea falla
TinaTabo Nov 29, 2021
e539f15
Nuevo enfoque
TinaTabo Nov 29, 2021
d1a569f
el bucle solo hace 1 iteracion --> hay q solucionarlo
TinaTabo Nov 29, 2021
2eebfbe
Merge branch 'master' of https://github.com/Eomys/MoSQITo
Nov 29, 2021
00de4ad
Merge branch 'master' of https://github.com/TinaTabo/MoSQITo
Nov 29, 2021
5b92890
[CC] Achitecture modification on comp_tonality according to ISO 1996 K
Nov 29, 2021
dce0f43
[NF] test for tonality_iso1996K
Nov 29, 2021
7007f28
[NF] documentation for tonality_ISO1996K
Nov 29, 2021
5bcc103
[CC] deleted useless files
TinaTabo Dec 4, 2021
76fa0cb
[CC] deleted useless files
TinaTabo Dec 4, 2021
bc32894
[BC] comments translated to English
TinaTabo Dec 4, 2021
6769b4b
adding tracers
TinaTabo Dec 9, 2021
5cc1e34
correct data lists
TinaTabo Dec 10, 2021
badec20
defined comparison ranges
TinaTabo Dec 10, 2021
8f93b6b
detected prominent tone correctly
TinaTabo Dec 10, 2021
ba4a2c5
removing traces
TinaTabo Dec 10, 2021
ac197b1
new test signals
TinaTabo Dec 23, 2021
3e4ef2d
documentation + new tests
TinaTabo Jan 11, 2022
0461219
+tests
TinaTabo Jan 11, 2022
69ead43
new signals for tests
TinaTabo Jan 11, 2022
8317b02
description of test added
TinaTabo Jan 11, 2022
e29d2d3
documentation + tutorial
TinaTabo Jan 16, 2022
1f17f74
modify tutorial
TinaTabo Jan 22, 2022
dc30091
actu docu + new tests signals
TinaTabo Jan 22, 2022
baa84ea
remove signals
TinaTabo Jan 22, 2022
a653a5a
error when using siren signal
TinaTabo Jan 22, 2022
dbcb4e8
tutorial modifications
TinaTabo Jan 25, 2022
15fb22d
comprobar q todo sigue funcionando
TinaTabo Jan 25, 2022
bb3e1cd
modified tutorial + auxiliary folder
TinaTabo Jan 31, 2022
fd23e3c
files relocated for correct functioning of the test + tutorial
TinaTabo Jan 31, 2022
945aa24
starting validation script
TinaTabo Jan 31, 2022
327ea92
[BC] shared/load function is robust to multichannel wav files
Feb 9, 2022
a873aaa
new test signal
TinaTabo Feb 10, 2022
54d6c01
reinstalación de entorno
TinaTabo Feb 11, 2022
51e6912
prueba.wav
TinaTabo Feb 11, 2022
1a82afd
last changes
TinaTabo Feb 21, 2022
f33c357
return to previous version
TinaTabo Feb 21, 2022
f7eea01
delete useless files
TinaTabo Feb 23, 2022
ce5425e
Merge branch 'master' of git://github.com/Eomys/MoSQITo into Eomys-ma…
TinaTabo Feb 23, 2022
bb8d81a
Merge branch 'Eomys-master'
TinaTabo Feb 23, 2022
b4e6666
requires modifications for octave thirds calculation
TinaTabo Feb 24, 2022
ab9f446
delete useless files
TinaTabo Feb 24, 2022
637047b
comp_third_spec => comp_noct_spectrum
TinaTabo Feb 25, 2022
3cc4afe
already runs correctly but the results are erroneous
TinaTabo Feb 25, 2022
7f2a9b9
Merge branch 'Eomys:master' into master
TinaTabo Feb 25, 2022
dae2189
function updated => working correctly
TinaTabo Feb 28, 2022
235df8d
processes all signals correctly
TinaTabo Feb 28, 2022
f3d52f6
removed code traces
TinaTabo Feb 28, 2022
9a40c96
validation + tutorial complete
TinaTabo Feb 28, 2022
c2f8063
Improved validation
TinaTabo Feb 28, 2022
0c9fa1e
updated documentation
TinaTabo Feb 28, 2022
278fb97
img wiki
TinaTabo Mar 6, 2022
1576470
wiki img
TinaTabo Mar 10, 2022
d8c39da
Merge branch 'master' of git://github.com/Eomys/MoSQITo
TinaTabo Mar 10, 2022
2ef87c8
delete img wiki
TinaTabo Mar 10, 2022
4b479a1
img wiki
TinaTabo Mar 10, 2022
96293fc
wiki img
TinaTabo Mar 10, 2022
a0739ca
wiki img
TinaTabo Mar 10, 2022
a1b724f
img wiki
TinaTabo Mar 11, 2022
1e539b1
img wiki
TinaTabo Mar 11, 2022
04485cf
wiki gif
TinaTabo Mar 11, 2022
70177dc
wiki img
TinaTabo Mar 11, 2022
f947e41
wiki img
TinaTabo Mar 11, 2022
49e15c1
wiki img
TinaTabo Mar 12, 2022
6b9ef4d
wiki img
TinaTabo Mar 12, 2022
b28928a
wiki img
TinaTabo Mar 12, 2022
34de88c
wiki img
TinaTabo Mar 12, 2022
471ef47
Merge branch 'master' of https://github.com/Eomys/MoSQITo
TinaTabo Mar 24, 2022
291102d
update repository - tonality iso 1996 k
TinaTabo Mar 24, 2022
371f896
comp_tonality function added to MoSQITo
TinaTabo Mar 24, 2022
2cba6f8
merge update repository 26/03/2022
TinaTabo Mar 26, 2022
d164eed
Merge branch 'master' of https://github.com/Eomys/MoSQITo
TinaTabo Mar 26, 2022
3cd7508
adjustments derived from merge
TinaTabo Mar 26, 2022
17ffc0d
new signals
TinaTabo Mar 27, 2022
fbf839c
small adjustments
TinaTabo Mar 27, 2022
866ed35
new signal
TinaTabo Mar 27, 2022
a2e545e
rename Lp_dB list
TinaTabo Mar 27, 2022
7b37a78
new signal
TinaTabo Mar 27, 2022
2fffe6b
tutorial update
TinaTabo Mar 29, 2022
54a5bec
update tutorial
TinaTabo Mar 31, 2022
d5913b9
Merge branch 'Eomys:master' into master
TinaTabo Apr 4, 2022
be9b5f7
update tutorial
TinaTabo Apr 21, 2022
a0c9886
improved validation
TinaTabo Apr 22, 2022
0923702
update validation
TinaTabo Apr 22, 2022
7d8e94c
update validation
TinaTabo Apr 22, 2022
eb5cd51
Merge branch 'Eomys:master' into master
TinaTabo May 9, 2022
27cf13e
Merge branch 'Eomys:master' into master
TinaTabo May 13, 2022
d766c65
wiki img
TinaTabo May 13, 2022
daab4e7
Merge branch 'master' of https://github.com/TinaTabo/MoSQITo
TinaTabo May 13, 2022
c664ead
img wiki
TinaTabo May 13, 2022
b16eabf
Merge branch 'Eomys:master' into master
TinaTabo May 23, 2022
c0796ae
audible range correction
TinaTabo May 23, 2022
7080ff6
Merge branch 'master' of https://github.com/TinaTabo/MoSQITo
TinaTabo May 23, 2022
bc77831
tutorial correction and validation
TinaTabo May 26, 2022
97bfbfb
Merge branch 'Eomys:master' into master
TinaTabo May 29, 2022
701eb60
actu tutorial
TinaTabo Jun 8, 2022
ccfad67
Merge branch 'master' of https://github.com/TinaTabo/MoSQITo
TinaTabo Jun 8, 2022
2d22fd9
actu tutorial
TinaTabo Jun 8, 2022
cca379b
Merge branch 'Eomys:master' into master
TinaTabo Jun 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __pycache__/
.vscode/
.ipynb_checkpoints/
tests/output
prueba
1 change: 1 addition & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ In this folder, you will find the documentation and validation of the different
- [Sharpness according to DIN standard](./sharpness_din.md)
- [Roughness (Daniel and Weber method)](./roughness_dw.md)
- [Tone-to-noise ratio and Prominence ratio of stationary and time-varying signals](./tone-to-noise-prominence-ratio.md)
- [Third octave band tonality according to ISO 1996 annex K](./tonality_ISO1996K.md)
16 changes: 16 additions & 0 deletions docs/tonality_ISO1996K.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# MOSQITO Documentation
## Tone detection according to ISO 1996-2 Annex K

### Introduction
ISO 1996-2 introduces different methods for determining the presence of a prominent discrete frequency spectral component (tone).

In particular, Annex K describes the calculations for applying the "Objective method for the assessment of the audibility of tones in noise", also known as the "Inspection method".

These calculations are based on the comparison of time-averaged sound pressure levels in one-third octave bands taking into account the frequency range in which these levels are found.

### Validation
The validation of the function has been performed by testing the function to perform tone detection using different signals: pure tones at low, medium and high frequencies, multi-tone signals and atonal signals.
By means of manual calculations, it is verified that the calculations obtained with the function are correct.

### References
ISO 1996. Acoustics. Description, measurement and assessment of environmental noise. Part 2: Determination of sound pressure levels. (October 2020 version)
8 changes: 8 additions & 0 deletions mosqito/sound_level_meter/noct_spectrum/noct_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ def noct_spectrum(sig, fs, fmin, fmax, n=3, G=10, fr=1000):
Outputs
-------
spec : numpy.ndarray
<<<<<<< HEAD
<<<<<<< HEAD
Third octave band spectrum of signal sig (units: Pascals [Pa]).
=======
The third octave band spectrum of signal sig with size (nfreq, nseg)
>>>>>>> ad054c17c80ccea5874344f38a135c8fe1315a12
=======
The third octave band spectrum of signal sig with size (nfreq, nseg)
>>>>>>> ad054c17c80ccea5874344f38a135c8fe1315a12
fpref : numpy.ndarray
Corresponding preferred third octave band center frequencies
"""
Expand Down
Empty file.
119 changes: 119 additions & 0 deletions mosqito/sq_metrics/tonality/tonality_iso1996K/comp_tonality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# -*- coding: utf-8 -*-
"""
Author: Cristina Taboada (TinaTabo)
Start date: 17/11/2021
"""
# Standard library imports
import math

# Local imports
from mosqito.sound_level_meter.noct_spectrum.noct_spectrum import noct_spectrum


def comp_tonality(sig, fs):
"""
<Function to obtain the prominent tones of a given signal
according to the procedure described in ISO 1996-2 Annex K.>

Parameters
----------
sig : numpy.array
time signal values
fs : integer
sampling frequency

Outputs
-------
prominent_tones: dictionary
dictionary with {fc:Lp_dB} pairs where prominent tones are detected.
"""


#-- As the tonality is studied for the audible frequency range,
#-- we set the minimum and maximum frequencies at 25 Hz and 20 kHz.
fmin = 25
fmax = 10000

# -- we obtain the data of the Lp in Pa in thirds of octave of the signal of which
# -- we want to know the prominent tones
third_spec = noct_spectrum(sig=sig, fs=fs, fmin=fmin, fmax=fmax)

#-- Returns a tuple with two arrays, one with the Lp_Pa of each third octave band
#-- and the other with the center frequencies, fc, of each band.
#-- Convert tuple to list for further processing
third_spec = list(third_spec)

# -- Obtain the lists of the central frequencies and the average Lp
fc = third_spec[1].tolist()
Lp_Pa = third_spec[0].tolist()

#-- Create a list with the Lp conversion in dB.
Lp_dB = []
P_ref = 2e-05
for i in range(0, len(Lp_Pa)):
P = Lp_Pa[i][0]
level = 20*math.log10(P/P_ref)
Lp_dB.append(level)

# -- List where the indexes corresponding to the positions where there is
# -- a prominent tone will be stored.
index_tone_list = []

# -- length of the lists
idx = len(fc) - 1

# -- level differences depending on the frequency range to determine if there
# -- is a prominent pitch.
diff_low_freqs = 15.0
diff_medium_freqs = 8.0
diff_high_freqs = 5.0

for x in range(0, idx):
# -- Variables to compare
if x == 0:
Lp_prev = 0
Lp_central = abs(Lp_dB[x])
Lp_post = abs(Lp_dB[x + 1])
else:
Lp_prev = abs(Lp_dB[x - 1])
Lp_central = abs(Lp_dB[x])
Lp_post = abs(Lp_dB[x + 1])

# -- calculate the difference
Lp_diff_prev = Lp_central - Lp_prev
Lp_diff_post = Lp_central - Lp_post

# -- if the value of the difference is constant with respect to the bands below and above
# -- the one studied, we obtain the value of the difference and proceed to check if we have
# -- found a prominent tone.

if x > fc.index(25.0) and x < fc.index(160.0):
# -- "LOW FREQUENCY --> difference 15 dB".
if Lp_diff_prev >= diff_low_freqs and Lp_diff_post >= diff_low_freqs:
# -- there is a tone in x, we store its value.
index_tone_list.append(x)

elif x > fc.index(125.0) and x < fc.index(500.0):
# -- "HALF FREQUENCY --> difference 8 dB"
if Lp_diff_prev >= diff_medium_freqs and Lp_diff_post >= diff_medium_freqs:
# -- there is a tone in x, we store its value.
index_tone_list.append(x)
elif x > fc.index(400.0) and x < fc.index(10000.0):
# -- "HIGH FREQUENCY --> 5 dB difference".
if Lp_diff_prev >= diff_high_freqs and Lp_diff_post >= diff_high_freqs:
# -- there is a tone in x, we store its value.
index_tone_list.append(x)

# -- Dictionary in which the data corresponding to the prominent tones
# -- will be stored, i.e. {fc : Lp_dB}
prominent_tones = {}

for i in range(0, len(index_tone_list)):
index = index_tone_list[i]
key = fc[index]
value = Lp_dB[index]
prominent_tones[key] = value

# -- Return of the function.
return prominent_tones

Binary file added tests/input/ATONAL_ELECTRIC_GUITAR_RIFF.wav
Binary file not shown.
Binary file added tests/input/MULTITONE_ALARM.wav
Binary file not shown.
Binary file added tests/input/MULTITONE_SIREN.wav
Binary file not shown.
Binary file added tests/input/TONE1000HZ.wav
Binary file not shown.
Binary file added tests/input/TONE100HZ.wav
Binary file not shown.
Binary file added tests/input/TONE125HZ.wav
Binary file not shown.
Binary file added tests/input/TONE160HZ.wav
Binary file not shown.
Binary file added tests/input/TONE2000HZ.wav
Binary file not shown.
Binary file added tests/input/TONE200HZ.wav
Binary file not shown.
Binary file added tests/input/TONE250HZ.wav
Binary file not shown.
Binary file added tests/input/TONE31'5HZ.wav
Binary file not shown.
Binary file added tests/input/TONE4000HZ.wav
Binary file not shown.
Binary file added tests/input/TONE400HZ.wav
Binary file not shown.
Binary file added tests/input/TONE5000HZ.wav
Binary file not shown.
Binary file added tests/input/TONE50HZ.wav
Binary file not shown.
Binary file added tests/input/WHITE_NOISE.wav
Binary file not shown.
102 changes: 102 additions & 0 deletions tests/sq_metrics/tonality/test_ISO1996K.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import pytest

from mosqito.utils.load import load
from mosqito.sq_metrics.tonality.tonality_iso1996K.comp_tonality import comp_tonality


@pytest.mark.tonality_1996k # to skip or run PR test
def test_ISO1996K():
"""Test function for the detection of a prominent tone
using the inspection method described in ISO 1996-2 Annex K.

Validation of the function "comp_tonality" with signal array
as input. The input signals have been obtained from the website https://freesound.org/.

Parameters
----------
None

Outputs
-------
None
"""

"""-----TONE--100-Hz----"""
sig, fs = load("tests\input\TONE100HZ.wav")
tones = comp_tonality(sig, fs)
print("----RESULT-----")
print(tones)
print("---------------")
assert tones == {100.0: 84.85146128088218}


"""-----TONE--200-Hz----"""
sig, fs = load("tests\input\TONE200HZ.wav")
tones = comp_tonality(sig, fs)
print("----RESULT-----")
print(tones)
print("---------------")
assert tones == {200.0: 84.85835085762665}


"""-----TONE--1-KHz----"""
sig, fs = load("tests/input/TONE1000HZ.WAV")
tones = comp_tonality(sig, fs)
print("----RESULT-----")
print(tones)
print("---------------")
assert tones == {1000.0: 63.962211067656554}


"""-----TONE--2-KHz----"""
sig, fs = load("tests\input\TONE2000HZ.wav")
tones = comp_tonality(sig, fs)
print("----RESULT-----")
print(tones)
print("---------------")
assert tones == {2000.0: 84.95769475723816}


"""-----TONE--4-KHz----"""
sig, fs = load("tests\input\TONE4000HZ.wav")
tones = comp_tonality(sig, fs)
print("----RESULT-----")
print(tones)
print("---------------")
assert tones == {4000.0: 84.95769513303429}


"""-----TONE--5-kHz----"""
sig, fs = load("tests\input\TONE5000HZ.wav")
tones = comp_tonality(sig, fs)
print("----RESULT-----")
print(tones)
print("---------------")
assert tones == {5000.0: 84.95769534548218}


"""-----MULTITONE-ALARM----"""
sig, fs = load("tests\input\MULTITONE_ALARM.wav")
tones = comp_tonality(sig, fs)
print("----RESULT-----")
print(tones)
print("---------------")
assert tones == {800.0: 53.685430439067396, 2000.0: 55.97882939521264, 3150.0: 64.05469163499629, 5000.0: 74.90550800435562}


"""-----MUTITONE-SIREN----"""
sig, fs = load("tests\input\MULTITONE_SIREN.wav")
tones = comp_tonality(sig, fs)
print("----RESULT-----")
print(tones)
print("---------------")
assert tones == {1600.0: 61.618174324534216, 2500.0: 56.86145723559116, 8000.0: 38.87188014184665}


"""-----ATONAL-SIGNAL----"""
sig, fs = load("tests\input\WHITE_NOISE.wav")
tones = comp_tonality(sig, fs)
print("----RESULT-----")
print(tones)
print("---------------")
assert tones == {}
Loading