Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My contribution to the MOSQITO repository #63

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
fa01e65
Leq finished and LAeq almost finished
Igarciac117 Nov 15, 2021
0cd3901
LAeq finished and I have made changes to Leq, they both work
Igarciac117 Nov 15, 2021
122314f
Small changes in Leq, LAeq and LCeq. LCeq works
Igarciac117 Nov 15, 2021
187383f
Added Leq, LCeq, LAeq and C_weighting
Igarciac117 Nov 25, 2021
513a884
Merge branch 'Eomys:master' into master
Igarciac117 Nov 30, 2021
56ea8e3
prototype of LN and LN_3oct
Igarciac117 Nov 30, 2021
a34259e
prototype of max_level and max_level_3oct
Igarciac117 Dec 1, 2021
00d2ab9
prototype of min_level and min_level_3oct
Igarciac117 Dec 1, 2021
767087a
Leq with with comments in the code and prototype of max_level_3oct
Igarciac117 Dec 1, 2021
7c4ed49
remove max_3oct
Igarciac117 Dec 1, 2021
492d729
LAeq with with comments in the code
Igarciac117 Dec 1, 2021
9b4b6ac
LCeq with with comments in the code
Igarciac117 Dec 1, 2021
fffcec3
Changes in the commented codes: LAeq, LCeq, Leq
Igarciac117 Dec 8, 2021
58cfa52
Change the name of the functions
Igarciac117 Dec 8, 2021
e430d8b
all the functions with the first comments
Igarciac117 Dec 11, 2021
ce3e4c6
all the functions with the first comments
Igarciac117 Dec 11, 2021
64c61fd
tutorial first try test
Igarciac117 Dec 14, 2021
2e60370
documentation first try test
Igarciac117 Dec 15, 2021
1d0e9d3
Leq_3oct code is finished
Igarciac117 Jan 24, 2022
07eaf18
Leq_3oct code is finished
Igarciac117 Jan 24, 2022
0079979
Leq_3oct.py code complete
Igarciac117 Jan 26, 2022
d4181ae
problems with the wav, but code of LN_3oct complete
Igarciac117 Jan 26, 2022
2dfa5bd
problems with the wav, but code of max_level_3oct complete
Igarciac117 Jan 26, 2022
2352ba6
problems with the wav, but code of min_level_3oct complete
Igarciac117 Jan 26, 2022
d7155a9
Merge branch 'Eomys:master' into master
Igarciac117 Feb 7, 2022
5c24ca3
some general changes in the code
Igarciac117 Feb 10, 2022
6fb8ea2
some general changes in the code
Igarciac117 Feb 10, 2022
fc96d04
Change test sognals
Igarciac117 Feb 21, 2022
41bff4c
Merge branch 'Eomys:master' into master
Igarciac117 Mar 15, 2022
8a68c43
All the changes untill now
Igarciac117 Mar 15, 2022
3f55e64
Merge branch 'master' of https://github.com/Igarciac117/MoSQITo
Igarciac117 Mar 15, 2022
26230e3
space kkk
Igarciac117 Mar 15, 2022
19deda2
New tutorial
Igarciac117 Mar 15, 2022
58878a3
remove C_W
Igarciac117 Mar 15, 2022
05b7479
Merge branch 'Eomys:master' into master
Igarciac117 Mar 22, 2022
6104a5f
Merge branch 'Eomys:master' into master
Igarciac117 Mar 27, 2022
7ba7aab
Merge branch 'Eomys:master' into master
Igarciac117 Apr 4, 2022
6e995cb
Add the wiki images.
Igarciac117 Apr 12, 2022
545e878
Add the wiki images.
Igarciac117 Apr 12, 2022
a7f461f
Add the wiki images.
Igarciac117 Apr 14, 2022
c9353fe
Add the wiki images.
Igarciac117 Apr 20, 2022
a52f9ff
Add the wiki images.
Igarciac117 Apr 20, 2022
3d16a16
Merge branch 'Eomys:master' into master
Igarciac117 May 23, 2022
98ddc36
Merge branch 'Eomys:master' into master
Igarciac117 May 25, 2022
90df63d
Merge branch 'Eomys:master' into master
Igarciac117 Jul 12, 2022
c820da3
Change the folder in the local repository
Igarciac117 Aug 5, 2022
b11c8c3
Add the function C_weighting to conversion the dB in dBC
Igarciac117 Aug 5, 2022
2d7377b
Todas las funciones pueden compilar sin importar locales, los test no…
Igarciac117 Aug 5, 2022
de2a091
Leq_3oct runs fine, the result is not right, I have to fix it
Igarciac117 Sep 12, 2022
6c870e6
The Leq_3oct function works.
Igarciac117 Sep 13, 2022
481c98d
The Leq_3oct function works.
Igarciac117 Sep 13, 2022
daa80b3
LAeq_3oct doesn't run, I'm making changes, it's not done.
Igarciac117 Sep 16, 2022
71cb731
More changes in the LAeq_3oct function, it still doesn't work, it's n…
Igarciac117 Sep 19, 2022
783b4c9
The max_level_3oct function works
Igarciac117 Sep 21, 2022
ea9bce8
remove the "pruebas" file
Igarciac117 Sep 21, 2022
9e36974
The min_level_3oct function works
Igarciac117 Sep 21, 2022
1ae38e5
The LN_3oct function works, I have to check if it returns the desired…
Igarciac117 Sep 21, 2022
8cfbe30
The max_level function works
Igarciac117 Sep 27, 2022
2d35c17
The min_level function works and I have removed the import math from …
Igarciac117 Sep 27, 2022
6144196
the function LN works
Igarciac117 Sep 27, 2022
e6a28e2
The Leq_3oct function works, the input parameters have been changed
Igarciac117 Oct 3, 2022
96585f1
The LN_3oct function works, the input parameters have been changed
Igarciac117 Oct 3, 2022
bab9a2a
Removed C_weighting file, LAeq function works and add my own dB2DBA c…
Igarciac117 Nov 8, 2022
cf6b2bd
The LCeq function works and I add my own dB2DBC conversion (spectrum2…
Igarciac117 Nov 8, 2022
6eeef7b
Small changes in the function Leq_3oct
Igarciac117 Nov 8, 2022
ad3cc54
small changes to max_level_3oct and min_level_3oct functions
Igarciac117 Nov 8, 2022
9697267
Fixed negative logarithms problem in LN.py, max_level.py and min_leve…
Igarciac117 Nov 8, 2022
bb16671
Last arrangements before presenting the work to the tutor
Igarciac117 Jan 12, 2023
1123295
Modification of the Calculate by third octave point of the tutorial
Igarciac117 Jun 18, 2023
bdd4d5f
Final touches
Igarciac117 Jul 21, 2023
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
28 changes: 28 additions & 0 deletions docs/sound-level-meter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# MOSQITO Documentation
## Sound level meter functions

### Introduction

There are operations that are important. We need to be able to perform them to have a better understanding of the data with which we work and to be able to use them to calculate data of interest. For this are the sonometer functions.

A step by step description of how to use MOSQITO to use the sonometer functions is given in [this tutorial](../tutorials/tuto_sound_level_meter.ipynb)

### Validation of the implementation

This section of the MoSQITo repository are mathematical accounts. For this reason, the validations have consisted of comparing two results: the results of the software and the simulated results in Excel.

Accounts are backed by regulations. Among them we have ISO 1996 part 1, ISO 1996 part 2 and the international standard IEC 61672: 2014 (This is for the A weighting and the C weighting).

We have taken three signals to carry out the calculations. These signals are located at ../tests/input and These are a white noise (349315__newagesoup__white-noise-10s.wav), a pink noise (349312__newagesoup__pink-noise-10s.wav) and a pure tone at 1000 Hz (554329__patobottos__beep-sound-of-1000-hz).

For the functions that work with Thirds of an Octave, the three signals (input array) were introduced to the program. In the same way, the data of the signals are entered in an Excel in which the desired operation of the function has been replicated. If the function and Excel return the same result, it is shown that the function works well and returns the correct result.

In the case of functions that work with temporary samples, only one of these three signals is entered and the procedure is the same, results are compared between the function and Excel.

### References

ISO 1996 - 1: Description, measurement and evaluation of environmental noise Part 1: Basic magnitudes and evaluation methods.

ISO 1996 - 2: Description, measurement and evaluation of environmental noise Part 2: determination of sound pressure levels.

IEC 61672-1:2014, Electroacoustics - Sound level meters - Part 1: Specifications.
Binary file modified logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions mosqito/functions/sound_level_meter/LN.py
Copy link

@mlotinga mlotinga Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the code operating over a signal in a for loop? These operations can all be applied to the entire signal in a single operation without any loops. This is true even if the input comprises multiple signals, although this code doesn't seem to address that situation.

This also goes for all other functions using this loop kernel.

Moreover, if the signal is being operated on sample-by-sample (as indicated), it doesn't make sense to take a mean of a single value (line 34).

Statistical levels are typically calculated using exponentially-weighted amplitude (ie, using a time-weighting integration filter), which is then downsampled to the specified calculation interval. For example, take time signal x, apply Fast (tau=0.125 s) time-weighting RMS filter to give xFRMS, then resample down to (eg) 0.125 s intervals. Then convert to dB and take the max/min/percentile.

Even if exponential weighting is not desired, taking an RMS implies averaging over a series of samples, which this code doesn't seem to be applying.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 12 19:45:20 2023

@author: Igarciac117
"""

# Third party imports
import numpy as np

# Local imports
from mosqito.utils.conversion import amp2db

def LN(signal):
"""Calculate the percentile value of the series of levels (dB) of the one signal.

Parameters
----------
signal : numpy.array
time signal values [Pa]

Outputs
-------
percentiles : numpy.ndarray
The values in dB of L90, L50 and L25 of the signal.
"""
# Empty array to store the values in dB of the signal.
dB_values = np.zeros(signal.shape[0])
# Performs the conversion to dB with all the values of the signal.
for i in range(signal.shape[0]):
#If the value is negative value.
if signal[i] <= 0:
# we convert it to positive.
signal[i] = np.sqrt(np.mean(signal[i] ** 2))
# Conversion Pa to dB.
dB = amp2db(np.array(signal[i]))
# Save all values in dB of the third octave in another array.
dB_values[i] = dB
# Calculate the percentiles with the values. "q" of np.percentile = 100 - N (N of LN).
L90 = np.percentile(dB_values, 10,interpolation='linear')
L50 = np.percentile(dB_values, 50,interpolation='linear')
L25 = np.percentile(dB_values, 75,interpolation='linear')
# Save the calculated percentile values.
percentiles = np.array([L90,L50,L25])

return percentiles
42 changes: 42 additions & 0 deletions mosqito/functions/sound_level_meter/max_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
"""
Created on Wen Dic 1 18:08:08 2021

@author: Igarciac117
"""

# Third party imports
import numpy as np

# Local imports
from mosqito.utils.conversion import amp2db

def max_level(signal):
"""Calculate the maximum value of the series of levels (dB) of the one signal.

Parameters
----------
signal : numpy.array
time signal values

Outputs
-------
max_level : numpy.ndarray
return the maximum value of the signal values.
"""
# Empty array to store the values in dB of the signal.
dB_values = np.zeros(signal.shape[0])
# Performs the conversion to dB with all the values of the signal.
for i in range(signal.shape[0]):
#If the value is negative value.
if signal[i] <= 0:
# we convert it to positive.
signal[i] = np.sqrt(np.mean(signal[i] ** 2))
# Conversion Pa to dB.
dB = amp2db(np.array(signal[i]))
# Save all values in dB of the third octave in another array.
dB_values[i] = dB
# Save the maximum level.
max_level = np.array(max(dB_values))

return max_level
66 changes: 66 additions & 0 deletions mosqito/functions/sound_level_meter/max_level_3oct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 12 19:40:20 2023

@author: Igarciac117
"""

# Third party imports
import numpy as np

# Local imports
from mosqito.sound_level_meter.noct_spectrum.noct_spectrum import noct_spectrum
from mosqito.utils.conversion import amp2db

def max_level_3oct(data_all_signals, fs, f_min, f_max):
"""Return the maximum value of the frequency bands you choose. Each one is calculated with the levels (dB)
of its band in the different signals.

Parameters
----------
data_all_signals : numpy.ndarray
Array which each row corresponds to the data of a signal [Pa].
fs : float
Sampling frequency [Hz].
fmax : float
Max frequency band [Hz].
fmin : float
Min frequency band [Hz].

Outputs
-------
max_level_3oct : numpy.ndarray
The maximum values of each frequency band.
"""
# We initialize the array that stores the third octave values (in Pa) of the all signals ​​with the first signal.
spectrum_all_signals_Pa = noct_spectrum(data_all_signals[0],fs,f_min,f_max)[0]
# We initialize the center frequencies of the third octaves with the first signal.
freq = noct_spectrum(data_all_signals[0],fs,f_min,f_max)[1]
# We initialize the number of the signals.
num_signals = data_all_signals.shape[0]
# We initialize the number of frequency bands.
num_bands = freq.shape[0]

# Calculate the value of the third octave in Pa of each signal.
for i in range(num_signals):
# We skip the first signal because we have initialized with it.
if i != 0:
# We calculate and save the values ​​of the third octaves of the signals
spectrum_all_signals_Pa = np.append(spectrum_all_signals_Pa,noct_spectrum(data_all_signals[i],fs,f_min,f_max)[0],axis=1)

# Creating a list of zeros of the size of the frequency bands (to keep the maximum level values).
max_level_3oct = np.zeros(num_bands)
# Empty array to store the values in dB of the third octave whose maximum value is going to be calculated.
band_value_all_signals = np.zeros(num_signals)
# For each frequency band you perform the operation.
for i in range(num_bands):
# Performs the conversion to dB with all the values of the frequency band in the different signals.
for j in range(num_signals):
# Conversion Pa to dB.
dB = amp2db(np.array(spectrum_all_signals_Pa[i][j]))
# Save all values in dB of the third octave in another array.
band_value_all_signals[j] = dB
# Calculate and keep the maximum value found in the array. That value will be the maximum of the third of an octave.
max_level_3oct[i] = max(band_value_all_signals)

return max_level_3oct
42 changes: 42 additions & 0 deletions mosqito/functions/sound_level_meter/min_level.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 12 19:44:20 2023

@author: Igarciac117
"""

# Third party imports
import numpy as np

# Local imports
from mosqito.utils.conversion import amp2db

def min_level(signal):
"""Calculate the minimum value of the series of levels (dB) of the one signal.

Parameters
----------
signal : numpy.array
time signal values

Outputs
-------
min_level : numpy.ndarray
return the minimum value of the signal values.
"""
# Empty array to store the values in dB of the signal.
dB_values = np.zeros(signal.shape[0])
# Performs the conversion to dB with all the values of the signal.
for i in range(signal.shape[0]):
#If the value is negative value.
if signal[i] <= 0:
# we convert it to positive.
signal[i] = np.sqrt(np.mean(signal[i] ** 2))
# Conversion Pa to dB.
dB = amp2db(np.array(signal[i]))
# Save all values in dB of the third octave in another array.
dB_values[i] = dB
# Save the minimum level.
min_level = np.array(min(dB_values))

return min_level
66 changes: 66 additions & 0 deletions mosqito/functions/sound_level_meter/min_level_3oct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 12 19:43:20 2023

@author: Igarciac117
"""

# Third party imports
import numpy as np

# Local imports
from mosqito.sound_level_meter.noct_spectrum.noct_spectrum import noct_spectrum
from mosqito.utils.conversion import amp2db

def min_level_3oct(data_all_signals, fs, f_min, f_max):
"""Return the minimum value of the frequency bands you choose. Each one is calculated with the levels (dB)
of its band in the different signals.

Parameters
----------
data_all_signals : numpy.ndarray
Array which each row corresponds to the data of a signal [Pa].
fs : float
Sampling frequency [Hz].
fmax : float
Max frequency band [Hz].
fmin : float
Min frequency band [Hz].

Outputs
-------
min_level_3oct : numpy.ndarray
The minimum values of each frequency band.
"""
# We initialize the array that stores the third octave values (in Pa) of the all signals ​​with the first signal.
spectrum_all_signals_Pa = noct_spectrum(data_all_signals[0],fs,f_min,f_max)[0]
# We initialize the center frequencies of the third octaves with the first signal.
freq = noct_spectrum(data_all_signals[0],fs,f_min,f_max)[1]
# We initialize the number of the signals.
num_signals = data_all_signals.shape[0]
# We initialize the number of frequency bands.
num_bands = freq.shape[0]

# Calculate the value of the third octave in Pa of each signal.
for i in range(num_signals):
# We skip the first signal because we have initialized with it.
if i != 0:
# We calculate and save the values ​​of the third octaves of the signals
spectrum_all_signals_Pa = np.append(spectrum_all_signals_Pa,noct_spectrum(data_all_signals[i],fs,f_min,f_max)[0],axis=1)

# Creating a list of zeros of the size of the frequency bands (to keep the maximum level values).
min_level_3oct = np.zeros(num_bands)
# Empty array to store the values in dB of the third octave whose maximum value is going to be calculated.
band_value_all_signals = np.zeros(num_signals)
# For each frequency band you perform the operation.
for i in range(num_bands):
# Performs the conversion to dB with all the values of the frequency band in the different signals.
for j in range(num_signals):
# Conversion Pa to dB.
dB = amp2db(np.array(spectrum_all_signals_Pa[i][j]))
# Save all values in dB of the third octave in another array.
band_value_all_signals[j] = dB
# Calculate and keep the maximum value found in the array. That value will be the maximum of the third of an octave.
min_level_3oct[i] = min(band_value_all_signals)

return min_level_3oct
Loading