-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Eomys/MoSQITo into master
- Loading branch information
Showing
52 changed files
with
6,964 additions
and
1,700 deletions.
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
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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
Empty file.
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
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
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
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
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,82 +1,90 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from numpy import log10, power, linspace | ||
from numpy import log10, linspace, mean, sqrt | ||
|
||
from SciDataTool import Data1D, DataTime | ||
|
||
|
||
def compute_level(self, unit): | ||
"""Overall Sound Pressure Level calculation in the chosen unit | ||
TODO: modify to use get_rms of SciDataTool or even remove | ||
def compute_level(self, nb_points=[], start=[], stop=[]): | ||
"""Overall Sound Pressure Level calculation from the time signal | ||
The SPL can be computed according to a specified number of points or | ||
during a given time frame | ||
Parameter: | ||
---------- | ||
unit : string | ||
'dB' or 'dBA' to apply A-weighting | ||
plot : boolean | ||
if True, the overall level is plotted along time (non-steady signals) | ||
""" | ||
signal : numpy.array | ||
time signal value | ||
fs: integer | ||
sampling frequency | ||
if unit == "dB": | ||
# Third octave spectrum calculation | ||
if self.third_spec_db == None: | ||
self.comp_3oct_spec() | ||
Output: | ||
------- | ||
level : numpy.array | ||
SPL in dB | ||
L = 10 * log10(sum(power(10, self.third_spec_db.values / 10))) | ||
""" | ||
# Check the inputs | ||
if nb_points != []: | ||
if type(nb_points) != int: | ||
raise TypeError("ERROR : Number of points should be an integer") | ||
|
||
if self.is_stationary == True: | ||
self.level_db = Data1D( | ||
values=[L], name="Overall Sound Pressure Level", unit="dB" | ||
if nb_points < 1 or nb_points > len(self.signal.values): | ||
raise ValueError( | ||
"ERROR : Number of points should be between 1 and the length of the given signal" | ||
) | ||
|
||
else: | ||
time = Data1D( | ||
symbol="T", | ||
name="Time axis", | ||
unit="s", | ||
values=linspace( | ||
0, | ||
len(self.signal.values) / self.fs, | ||
self.third_spec_db.values.shape[1], | ||
), | ||
) | ||
if start != [] and stop != []: | ||
if type(start) != int and type(start) != float: | ||
raise TypeError("ERROR : Start (in sec) should be an integer or a float ") | ||
|
||
if type(stop) != int and type(stop) != float: | ||
raise TypeError("ERROR : Stop (in sec) should be an integer or a float ") | ||
|
||
self.level_db = DataTime( | ||
symbol="dB", | ||
axes=[time], | ||
values=L, | ||
name="Overall Sound Pressure Level", | ||
unit="dB", | ||
if ( | ||
start < 0 | ||
or stop < 0 | ||
or start > len(self.signal.values) / self.fs | ||
or stop > len(self.signal.values) / self.fs | ||
): | ||
raise ValueError( | ||
"ERROR : Time frame should be between 0s and the duration of the signal" | ||
) | ||
|
||
elif unit == "dBA": | ||
# Third octave spectrum calculation | ||
if self.third_spec_dba == None: | ||
self.comp_3oct_spec(unit="dBA") | ||
if start == stop: | ||
raise ValueError("ERROR : Start and stop values must be different") | ||
|
||
L = 10 * log10(sum(power(10, self.third_spec_dba.values / 10))) | ||
# Initialization | ||
level = [] | ||
|
||
if self.is_stationary == True: | ||
self.level_dba = Data1D( | ||
values=[L], name="Overall Sound Pressure Level", unit="dBA" | ||
) | ||
else: | ||
time = Data1D( | ||
symbol="T", | ||
name="Time axis", | ||
unit="s", | ||
values=linspace( | ||
0, | ||
len(self.signal.values) / self.fs, | ||
self.third_spec_dba.values.shape[1], | ||
), | ||
) | ||
# Case of a given time frame | ||
if start != [] and stop != []: | ||
frame = self.signal.values[int(start * self.fs) : int(stop * self.fs)] | ||
else: | ||
start = 0 | ||
stop = len(self.signal.values) / self.fs | ||
frame = self.signal.values | ||
|
||
self.level_dba = DataTime( | ||
symbol="dBA", | ||
axes=[time], | ||
values=L, | ||
name="Overall Sound Pressure Level", | ||
unit="dBA", | ||
) | ||
# Case of a given number of points | ||
if nb_points != []: | ||
|
||
time = Data1D( | ||
name="time", unit="s", values=linspace(start, stop, num=nb_points) | ||
) | ||
|
||
frame_size = int(len(frame) / nb_points) | ||
for i in range(nb_points): | ||
frame_i = frame[i * frame_size : i * frame_size + frame_size] | ||
peff = sqrt(mean(frame_i ** 2)) | ||
level.append(10 * log10((peff ** 2 / (2e-05) ** 2))) | ||
|
||
self.level = DataTime( | ||
name="Sound Pressure Level", | ||
symbol="SPL", | ||
unit="dB", | ||
axes=[time], | ||
values=level, | ||
) | ||
|
||
else: | ||
peff = sqrt(mean(frame ** 2)) | ||
self.level = 10 * log10((peff ** 2 / (2e-05) ** 2)) |
Empty file.
Empty file.
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
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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
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
Binary file not shown.
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
Oops, something went wrong.