-
Notifications
You must be signed in to change notification settings - Fork 44
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
Igarciac117
wants to merge
70
commits into
Eomys:master
Choose a base branch
from
Igarciac117:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 0cd3901
LAeq finished and I have made changes to Leq, they both work
Igarciac117 122314f
Small changes in Leq, LAeq and LCeq. LCeq works
Igarciac117 187383f
Added Leq, LCeq, LAeq and C_weighting
Igarciac117 513a884
Merge branch 'Eomys:master' into master
Igarciac117 56ea8e3
prototype of LN and LN_3oct
Igarciac117 a34259e
prototype of max_level and max_level_3oct
Igarciac117 00d2ab9
prototype of min_level and min_level_3oct
Igarciac117 767087a
Leq with with comments in the code and prototype of max_level_3oct
Igarciac117 7c4ed49
remove max_3oct
Igarciac117 492d729
LAeq with with comments in the code
Igarciac117 9b4b6ac
LCeq with with comments in the code
Igarciac117 fffcec3
Changes in the commented codes: LAeq, LCeq, Leq
Igarciac117 58cfa52
Change the name of the functions
Igarciac117 e430d8b
all the functions with the first comments
Igarciac117 ce3e4c6
all the functions with the first comments
Igarciac117 64c61fd
tutorial first try test
Igarciac117 2e60370
documentation first try test
Igarciac117 1d0e9d3
Leq_3oct code is finished
Igarciac117 07eaf18
Leq_3oct code is finished
Igarciac117 0079979
Leq_3oct.py code complete
Igarciac117 d4181ae
problems with the wav, but code of LN_3oct complete
Igarciac117 2dfa5bd
problems with the wav, but code of max_level_3oct complete
Igarciac117 2352ba6
problems with the wav, but code of min_level_3oct complete
Igarciac117 d7155a9
Merge branch 'Eomys:master' into master
Igarciac117 5c24ca3
some general changes in the code
Igarciac117 6fb8ea2
some general changes in the code
Igarciac117 fc96d04
Change test sognals
Igarciac117 41bff4c
Merge branch 'Eomys:master' into master
Igarciac117 8a68c43
All the changes untill now
Igarciac117 3f55e64
Merge branch 'master' of https://github.com/Igarciac117/MoSQITo
Igarciac117 26230e3
space kkk
Igarciac117 19deda2
New tutorial
Igarciac117 58878a3
remove C_W
Igarciac117 05b7479
Merge branch 'Eomys:master' into master
Igarciac117 6104a5f
Merge branch 'Eomys:master' into master
Igarciac117 7ba7aab
Merge branch 'Eomys:master' into master
Igarciac117 6e995cb
Add the wiki images.
Igarciac117 545e878
Add the wiki images.
Igarciac117 a7f461f
Add the wiki images.
Igarciac117 c9353fe
Add the wiki images.
Igarciac117 a52f9ff
Add the wiki images.
Igarciac117 3d16a16
Merge branch 'Eomys:master' into master
Igarciac117 98ddc36
Merge branch 'Eomys:master' into master
Igarciac117 90df63d
Merge branch 'Eomys:master' into master
Igarciac117 c820da3
Change the folder in the local repository
Igarciac117 b11c8c3
Add the function C_weighting to conversion the dB in dBC
Igarciac117 2d7377b
Todas las funciones pueden compilar sin importar locales, los test no…
Igarciac117 de2a091
Leq_3oct runs fine, the result is not right, I have to fix it
Igarciac117 6c870e6
The Leq_3oct function works.
Igarciac117 481c98d
The Leq_3oct function works.
Igarciac117 daa80b3
LAeq_3oct doesn't run, I'm making changes, it's not done.
Igarciac117 71cb731
More changes in the LAeq_3oct function, it still doesn't work, it's n…
Igarciac117 783b4c9
The max_level_3oct function works
Igarciac117 ea9bce8
remove the "pruebas" file
Igarciac117 9e36974
The min_level_3oct function works
Igarciac117 1ae38e5
The LN_3oct function works, I have to check if it returns the desired…
Igarciac117 8cfbe30
The max_level function works
Igarciac117 2d35c17
The min_level function works and I have removed the import math from …
Igarciac117 6144196
the function LN works
Igarciac117 e6a28e2
The Leq_3oct function works, the input parameters have been changed
Igarciac117 96585f1
The LN_3oct function works, the input parameters have been changed
Igarciac117 bab9a2a
Removed C_weighting file, LAeq function works and add my own dB2DBA c…
Igarciac117 cf6b2bd
The LCeq function works and I add my own dB2DBC conversion (spectrum2…
Igarciac117 6eeef7b
Small changes in the function Leq_3oct
Igarciac117 ad3cc54
small changes to max_level_3oct and min_level_3oct functions
Igarciac117 9697267
Fixed negative logarithms problem in LN.py, max_level.py and min_leve…
Igarciac117 bb16671
Last arrangements before presenting the work to the tutor
Igarciac117 1123295
Modification of the Calculate by third octave point of the tutorial
Igarciac117 bdd4d5f
Final touches
Igarciac117 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.