diff --git a/mosqito/sound_level_meter/__init__.py b/mosqito/sound_level_meter/__init__.py index d4e1f9ce..e87ee5a5 100644 --- a/mosqito/sound_level_meter/__init__.py +++ b/mosqito/sound_level_meter/__init__.py @@ -1,3 +1,3 @@ -from mosqito.sound_level_meter.noct_spectrum.noct_spectrum import ( - noct_spectrum, -) +from mosqito.sound_level_meter.noct_spectrum.noct_spectrum import noct_spectrum +from mosqito.sound_level_meter.noct_spectrum.noct_synthesis import noct_synthesis + diff --git a/mosqito/sound_level_meter/noct_spectrum/_filter_bandwidth.py b/mosqito/sound_level_meter/noct_spectrum/_filter_bandwidth.py index c0b2c677..53c08164 100644 --- a/mosqito/sound_level_meter/noct_spectrum/_filter_bandwidth.py +++ b/mosqito/sound_level_meter/noct_spectrum/_filter_bandwidth.py @@ -30,6 +30,11 @@ def _filter_bandwidth(fc, n=3, N=3): alpha : numpy.ndarray Ratio of the upper and lower band-edge frequencies to the mid-band frequency + f1 : float + Lower frequency of the band in Hz + f2 : float + Upper frequency of the band in Hz + """ """ @@ -54,7 +59,7 @@ def _filter_bandwidth(fc, n=3, N=3): # Ratio of the upper and lower band-edge frequencies to the mid-band frequency alpha = (1 + np.sqrt(1 + 4 * qd ** 2)) / 2 / qd - return alpha + return alpha, f1, f2 if __name__ == "__main__": diff --git a/mosqito/sound_level_meter/noct_spectrum/_n_oct_freq_filter.py b/mosqito/sound_level_meter/noct_spectrum/_n_oct_freq_filter.py index 502fddc7..f349104e 100644 --- a/mosqito/sound_level_meter/noct_spectrum/_n_oct_freq_filter.py +++ b/mosqito/sound_level_meter/noct_spectrum/_n_oct_freq_filter.py @@ -1,15 +1,11 @@ # -*- coding: utf-8 -*- -""" -Created on Thu Mar 10 10:00:03 2022 -@author: wantysal -""" + # Standard library imports import numpy as np -from scipy.signal import butter, freqz - +from scipy.signal import butter, sosfreqz -def _n_oct_freq_filter(spectrum, fs, fc, alpha, n=3): +def _n_oct_freq_filter(spectrum, fs, fc, alpha, n=3): """ n-th octave filtering in frequency domain Designs a digital 1/3-octave filter with center frequency fc for @@ -26,7 +22,7 @@ def _n_oct_freq_filter(spectrum, fs, fc, alpha, n=3): alpha : float Ratio of the upper and lower band-edge frequencies to the mid-band frequency - N : int, optional + n : int, optional Filter order. Default to 3 Outputs @@ -35,40 +31,17 @@ def _n_oct_freq_filter(spectrum, fs, fc, alpha, n=3): Rms level of sig in the third octave band centered on fc """ - # Check for Nyquist-Shannon criteria - if fc > 0.88 * (fs / 2): - raise ValueError( - """ERROR: Design not possible. Filter center frequency shall - verify: fc <= 0.88 * (fs / 2)""" - ) - # Normalized cutoff frequencies - w1 = fc / (fs / 2) / alpha - w2 = fc / (fs / 2) * alpha - - # define filter coefficient - b, a = butter(n, [w1, w2], "bandpass", analog=False) - + w1 = fc / (fs / 2) / alpha + w2 = fc / (fs / 2) * alpha + + # Define filter coefficient + sos = butter(n, [w1, w2], "bandpass", analog=False, output ='sos') + # Get FRF and apply it + w, h = sosfreqz(sos, worN=len(spectrum)) + spec_filt = np.multiply(h, spectrum.T).T - # filter signal - if len(spectrum.shape)>1: - level = [] - # go into frequency domain - w, h = freqz(b, a, worN=spectrum.shape[1]) - for i in range(spectrum.shape[0]): - spec_filt = spectrum[i,:] * h - # Compute overall rms level - level.append(np.sqrt(np.sum(np.abs(spec_filt) ** 2))) - level = np.array(level) - else: - # go into frequency domain - w, h = freqz(b, a, worN=len(spectrum)) - spec_filt = spectrum * h - # Compute overall rms level - level = np.sqrt(np.sum(np.abs(spec_filt) ** 2)) + # Compute overall rms level + level = np.sqrt(np.sum(np.abs(spec_filt) ** 2, axis=0)) return level - - - - diff --git a/mosqito/sound_level_meter/noct_spectrum/_n_oct_time_filter.py b/mosqito/sound_level_meter/noct_spectrum/_n_oct_time_filter.py index 50ad8017..45773982 100644 --- a/mosqito/sound_level_meter/noct_spectrum/_n_oct_time_filter.py +++ b/mosqito/sound_level_meter/noct_spectrum/_n_oct_time_filter.py @@ -2,7 +2,7 @@ # Standard library imports import numpy as np -from scipy.signal import decimate, butter, lfilter +from scipy.signal import decimate, butter, sosfilt def _n_oct_time_filter(sig, fs, fc, alpha, N=3): @@ -29,7 +29,7 @@ def _n_oct_time_filter(sig, fs, fc, alpha, N=3): alpha : float Ratio of the upper and lower band-edge frequencies to the mid-band frequency - N : int, optional + n : int, optional Filter order. Default to 3 Outputs @@ -59,10 +59,10 @@ def _n_oct_time_filter(sig, fs, fc, alpha, N=3): w2 = fc / (fs / 2) * alpha # define filter coefficient - b, a = butter(N, [w1, w2], "bandpass", analog=False) + sos = butter(int(N), (w1, w2), "bandpass", analog=False, output='sos') # filter signal - sig_filt = lfilter(b, a, sig, axis=0) + sig_filt = sosfilt(sos, sig, axis=0) # Compute overall rms level level = np.sqrt(np.mean(sig_filt ** 2, axis=0)) diff --git a/mosqito/sound_level_meter/noct_spectrum/noct_spectrum.py b/mosqito/sound_level_meter/noct_spectrum/noct_spectrum.py index 6cce7dc8..d9831dbf 100644 --- a/mosqito/sound_level_meter/noct_spectrum/noct_spectrum.py +++ b/mosqito/sound_level_meter/noct_spectrum/noct_spectrum.py @@ -53,7 +53,7 @@ def noct_spectrum(sig, fs, fmin, fmax, n=3, G=10, fr=1000): fc_vec, fpref = _center_freq(fmin=fmin, fmax=fmax, n=n, G=G, fr=fr) # Compute the filters bandwidth - alpha_vec = _filter_bandwidth(fc_vec, n=n) + alpha_vec, _, _ = _filter_bandwidth(fc_vec, n=n) # Calculation of the rms level of the signal in each band spec = [] diff --git a/mosqito/sound_level_meter/noct_spectrum/noct_synthesis.py b/mosqito/sound_level_meter/noct_spectrum/noct_synthesis.py index 25f83fcc..4bead4e1 100644 --- a/mosqito/sound_level_meter/noct_spectrum/noct_synthesis.py +++ b/mosqito/sound_level_meter/noct_spectrum/noct_synthesis.py @@ -5,14 +5,14 @@ # Local application imports from mosqito.sound_level_meter.noct_spectrum._center_freq import _center_freq +from mosqito.sound_level_meter.noct_spectrum._filter_bandwidth import _filter_bandwidth +from mosqito.sound_level_meter.noct_spectrum._n_oct_freq_filter import _n_oct_freq_filter def noct_synthesis(spectrum, freqs, fmin, fmax, n=3, G=10, fr=1000): """Adapt input spectrum to nth-octave band spectrum - Convert the input spectrum to third-octave band spectrum between "fc_min" and "fc_max". - Parameters ---------- spectrum : numpy.ndarray @@ -32,7 +32,6 @@ def noct_synthesis(spectrum, freqs, fmin, fmax, n=3, G=10, fr=1000): Reference frequency. Shall be set to 1 kHz for audible frequency range, to 1 Hz for infrasonic range (f < 20 Hz) and to 1 MHz for ultrasonic range (f > 31.5 kHz). - Outputs ------- spec : numpy.ndarray @@ -40,40 +39,40 @@ def noct_synthesis(spectrum, freqs, fmin, fmax, n=3, G=10, fr=1000): fpref : numpy.ndarray Corresponding preferred third octave band center frequencies, size (nbands). """ + + # Deduce sampling frequency + fs = np.mean(freqs[1:] - freqs[:-1]) * 2 * len(spectrum) # Get filters center frequencies fc_vec, fpref = _center_freq(fmin=fmin, fmax=fmax, n=n, G=G, fr=fr) + + # Compute the filters bandwidth + alpha_vec, f_low, f_high = _filter_bandwidth(fc_vec, n=n) + + # Delete ends frequencies to prevent aliasing + idx = np.asarray(np.where(f_high > fs / 2)) + if any(idx[0]): + fc_vec = np.delete(fc_vec, idx) + f_low = np.delete(f_low, idx) + f_high = np.delete(f_high, idx) - nband = len(fpref) - + # Number of nth bands + nband = len(fc_vec) + + # Results array initialization if len(spectrum.shape) > 1: nseg = spectrum.shape[1] spec = np.zeros((nband, nseg)) + # If only one axis is given, it is used for all the spectra if len(freqs.shape) == 1: freqs = np.tile(freqs, (nseg, 1)).T - else: nseg = 1 spec = np.zeros((nband)) - # Frequency resolution - # df = freqs[1:] - freqs[:-1] - # df = np.concatenate((df, [df[-1]])) - - # Get upper and lower frequencies - fu = fc_vec * 2**(1/(2*n)) - fl = fc_vec / 2**(1/(2*n)) - - for s in range(nseg): - for i in range(nband): - if len(spectrum.shape) > 1: - # index of the frequencies within the band - idx = np.where((freqs[:, s] >= fl[i]) & (freqs[:, s] < fu[i])) - spec[i, s] = np.sqrt( - np.sum(np.power(np.abs(spectrum[idx,s]), 2))) - else: - # index of the frequencies within the band - idx = np.where((freqs >= fl[i]) & (freqs < fu[i])) - spec[i] = np.sqrt(np.sum(np.abs(spectrum[idx])**2)) + # Calculation of the rms level of the signal in each band + spec = [] + for fc, alpha in zip(fc_vec, alpha_vec): + spec.append(_n_oct_freq_filter(spectrum, fs, fc, alpha)) - return spec, fpref + return np.array(spec), fpref diff --git a/mosqito/sq_metrics/tonality/prominence_ratio_ecma/_pr_main_calc.py b/mosqito/sq_metrics/tonality/prominence_ratio_ecma/_pr_main_calc.py index d621715c..3ad5843d 100644 --- a/mosqito/sq_metrics/tonality/prominence_ratio_ecma/_pr_main_calc.py +++ b/mosqito/sq_metrics/tonality/prominence_ratio_ecma/_pr_main_calc.py @@ -205,9 +205,7 @@ def _pr_main_calc(spectrum_db, freq_axis): # suppression from the list of tones of all the candidates belonging to the # same critical band - sup = np.where((peaks >= low_limit_idx) & (peaks <= high_limit_idx))[ - 0 - ] + sup = np.where((peaks >= low_limit_idx) & (peaks <= high_limit_idx))[0] peaks = np.delete(peaks, sup) nb_tones -= len(sup) diff --git a/mosqito/sq_metrics/tonality/tone_to_noise_ecma/_screening_for_tones.py b/mosqito/sq_metrics/tonality/tone_to_noise_ecma/_screening_for_tones.py index 6084bcd9..d9d8c4e4 100644 --- a/mosqito/sq_metrics/tonality/tone_to_noise_ecma/_screening_for_tones.py +++ b/mosqito/sq_metrics/tonality/tone_to_noise_ecma/_screening_for_tones.py @@ -8,9 +8,7 @@ import numpy as np # Mosqito functions import -from mosqito.sq_metrics.tonality.tone_to_noise_ecma._spectrum_smoothing import ( - _spectrum_smoothing, -) +from mosqito.sq_metrics.tonality.tone_to_noise_ecma._spectrum_smoothing import _spectrum_smoothing from mosqito.sq_metrics.tonality.tone_to_noise_ecma._LTH import _LTH from mosqito.sq_metrics.tonality.tone_to_noise_ecma._critical_band import _critical_band @@ -54,7 +52,7 @@ def _screening_for_tones(freqs, spec_db, method, low_freq, high_freq): # Detection of the tonal candidates according to their level # Creation of the smoothed spectrum - smooth_spec = _spectrum_smoothing(freqs, spec_db, 24, low_freq, high_freq, freqs) + smooth_spec = _spectrum_smoothing(freqs, spec_db.T, 24, low_freq, high_freq, freqs).T n = spec_db.shape[0] @@ -149,7 +147,7 @@ def _screening_for_tones(freqs, spec_db, method, low_freq, high_freq): # Screen the left points of the peak temp = peak_index - 1 # As long as the level decreases, - while (spec_db[temp] > smooth_spec[temp] + 6) and (temp + 1 < (block+1)*m): + while (spec_db[temp] > smooth_spec[temp] + 6) and (temp +1 > (block)*m): # if a highest spectral line is found, it becomes the candidate if spec_db[temp] > spec_db[peak_index]: peak_index = temp diff --git a/mosqito/sq_metrics/tonality/tone_to_noise_ecma/_spectrum_smoothing.py b/mosqito/sq_metrics/tonality/tone_to_noise_ecma/_spectrum_smoothing.py index 06ae5e4f..73b86858 100644 --- a/mosqito/sq_metrics/tonality/tone_to_noise_ecma/_spectrum_smoothing.py +++ b/mosqito/sq_metrics/tonality/tone_to_noise_ecma/_spectrum_smoothing.py @@ -18,9 +18,9 @@ def _spectrum_smoothing(freqs_in, spec, noct, low_freq, high_freq, freqs_out): Parameters ---------- freqs : numpy.array - frequency axis (frequency axis) + frequency axis dim (nperseg) spec : numpy.array - spectrum in dB (n block x spectrum) + spectrum in dB (nperseg, nseg) noct : integer n-th octave-band according to which smooth the spectrum low_freq : float @@ -36,14 +36,13 @@ def _spectrum_smoothing(freqs_in, spec, noct, low_freq, high_freq, freqs_out): smoothed spectrum along the given frequency axis """ - n = spec.shape[0] + nperseg = spec.shape[0] if len(spec.shape) > 1: - m = spec.shape[1] + nseg = spec.shape[1] else: - m = spec.shape[0] - n = 1 + nseg = 1 spec = spec.ravel() - stop = np.arange(1, n + 1) * m + stop = np.arange(1, nseg + 1) * nperseg freqs_in = freqs_in.ravel() # n-th octave bands filter @@ -53,14 +52,12 @@ def _spectrum_smoothing(freqs_in, spec, noct, low_freq, high_freq, freqs_out): # Smoothed spectrum creation nb_bands = filter_freqs.shape[0] - smoothed_spectrum = np.zeros((n, nb_bands)) + smoothed_spectrum = np.zeros((nb_bands, nseg)) i = 0 # Each band is considered individually until all of them have been treated while nb_bands > 0: # Find the index of the spectral components within the frequency bin - bin_index = np.where( - (freqs_in >= filter_freqs[i, 0]) & (freqs_in <= filter_freqs[i, 2]) - )[0] + bin_index = np.where((freqs_in >= filter_freqs[i, 0]) & (freqs_in <= filter_freqs[i, 2]))[0] # If the frequency bin is empty, it is deleted from the list if len(bin_index) == 0: @@ -70,45 +67,32 @@ def _spectrum_smoothing(freqs_in, spec, noct, low_freq, high_freq, freqs_out): else: # The spectral components within the frequency bin are averaged on an energy basis - spec_sum = np.zeros((n)) - for j in range(n): - if ( - len(bin_index[(bin_index < stop[j]) & (bin_index > (stop[j] - m))]) - != 0 - ): - spec_sum[j] = np.mean( - 10 - ** ( - spec[ - bin_index[ - (bin_index < stop[j]) & (bin_index > (stop[j] - m)) - ] - ] - / 10 - ) - ) + spec_sum = np.zeros((nseg)) + for j in range(nseg): + if len(bin_index[(bin_index < stop[j]) & (bin_index > (stop[j] - nperseg))])!= 0: + spec_sum[j] = np.mean(10** (spec[bin_index[(bin_index < stop[j]) & (bin_index > (stop[j] - nperseg))]]/ 10)) else: spec_sum[j] = 1e-12 - smoothed_spectrum[:, i] = 10 * np.log10( - spec_sum - # / len(bin_index[(bin_index < stop[j]) & (bin_index > (stop[j] - m))]) - ) + smoothed_spectrum[i, :] = 10 * np.log10(spec_sum)# / len(bin_index[(bin_index < stop[j]) & (bin_index > (stop[j] - m))])) nb_bands -= 1 i += 1 # Pose of the smoothed spectrum on the frequency-axis - low = np.zeros((n, filter_freqs.shape[0])) - high = np.zeros((n, filter_freqs.shape[0])) + low = np.zeros((filter_freqs.shape[0], nseg)) + high = np.zeros((filter_freqs.shape[0], nseg)) # Index of the lower and higher limit of each frequency bin into the original spectrum for i in range(len(filter_freqs)): - low[:, i] = np.argmin(np.abs(freqs_out - filter_freqs[i, 0])) - high[:, i] = np.argmin(np.abs(freqs_out - filter_freqs[i, 2])) + low[i,:] = np.argmin(np.abs(freqs_out - filter_freqs[i, 0])) + high[i,:] = np.argmin(np.abs(freqs_out - filter_freqs[i, 2])) low = low.astype(int) high = high.astype(int) - smooth_spec = np.zeros((n, m)) - for i in range(n): + smooth_spec = np.zeros((nperseg, nseg)) + for i in range(nseg): for j in range(filter_freqs.shape[0]): - smooth_spec[i, low[i, j] : high[i, j]] = smoothed_spectrum[i, j] + smooth_spec[low[j,i] : high[j,i], i] = smoothed_spectrum[j,i] + + if smooth_spec.shape[1] == 1: + smooth_spec = np.squeeze(smooth_spec) return smooth_spec diff --git a/tests/sound_level_meter/noct_spectrum/test_noct_synthesis.py b/tests/sound_level_meter/noct_spectrum/test_noct_synthesis.py index 9a0aedac..62549f47 100644 --- a/tests/sound_level_meter/noct_spectrum/test_noct_synthesis.py +++ b/tests/sound_level_meter/noct_spectrum/test_noct_synthesis.py @@ -7,7 +7,7 @@ raise RuntimeError( "In order to perform the tests you need the 'pytest' package." ) -# import matplotlib.pyplot as plt +#import matplotlib.pyplot as plt # External library imports import numpy as np @@ -24,9 +24,10 @@ def _dB(amp): @pytest.mark.noct_synthesis # to skip or run only loudness noct_synthesis tests -def test_noct_synthesis(): - sig, fs = load( - "tests/input/Test signal 5 (pinknoise 60 dB).wav", wav_calib=2*2**0.5) +def test_noct_synthesis_technical(): + + ############################## TECHNICAL SIGNAL ########################## + sig, fs = load("tests/input/Test signal 5 (pinknoise 60 dB).wav", wav_calib=2*2**0.5) spec_3t, freq_3t = noct_spectrum(sig, fs, fmin=24, fmax=12600, n=3) spec_1t, freq_1t = noct_spectrum(sig, fs, fmin=24, fmax=12600, n=1) @@ -41,27 +42,65 @@ def test_noct_synthesis(): # Frequency axis freqs = fftfreq(n, 1/fs)[0:n//2] - spec_3f, freq_3f = noct_synthesis( - np.abs(spectrum), freqs, fmin=24, fmax=12600, n=3) - spec_1f, freq_1f = noct_synthesis( - np.abs(spectrum), freqs, fmin=24, fmax=12600, n=1) + spec_3f, freq_3f = noct_synthesis(np.abs(spectrum), freqs, fmin=24, fmax=12600, n=3) + spec_1f, freq_1f = noct_synthesis(np.abs(spectrum), freqs, fmin=24, fmax=12600, n=1) - # plt.figure() - # plt.semilogx(freq_3t, _dB(spec_3t), label='noct spectrum') - # plt.semilogx(freq_3f, _dB(spec_3f), label='noct synth') - # plt.legend() + # plt.figure() + # plt.semilogx(freq_3t, _dB(spec_3t), label='noct spectrum') + # plt.semilogx(freq_3f, _dB(spec_3f), label='noct synth') + # plt.legend() - # plt.figure() - # plt.semilogx(freq_1t, _dB(spec_1t), label='noct spectrum') - # plt.semilogx(freq_1f, _dB(spec_1f), label='noct synth') - # plt.legend() + # plt.figure() + # plt.semilogx(freq_1t, _dB(spec_1t), label='noct spectrum') + # plt.semilogx(freq_1f, _dB(spec_1f), label='noct synth') + # plt.legend() - # plt.show() + # plt.show() np.testing.assert_allclose(_dB(spec_3t[:, 0]), _dB(spec_3f), atol=0.3) np.testing.assert_allclose(_dB(spec_1t[:, 0]), _dB(spec_1f), atol=0.3) + + +# @pytest.mark.noct_synthesis # to skip or run only loudness noct_synthesis tests +# def test_noct_synthesis_synthetic(): + +# ########################## SYNTHETIC SIGNAL############################### +# sig, fs = load("tests\input\white_noise_200_2000_Hz_stationary.wav", wav_calib=2*2**0.5) + +# spec_3t, freq_3t = noct_spectrum(sig, fs, fmin=24, fmax=12600, n=3) +# spec_1t, freq_1t = noct_spectrum(sig, fs, fmin=24, fmax=12600, n=1) + +# # Creation of the spectrum by FFT +# # 2* because we consider a one-sided spectrum +# # /np.sqrt(2) to go from amplitude peak to amplitude RMS +# # /n normalization for the numpy fft function +# n = len(sig) +# spectrum = 2 / np.sqrt(2) / n * fft(sig)[0:n//2] + +# # Frequency axis +# freqs = fftfreq(n, 1/fs)[0:n//2] + +# spec_3f, freq_3f = noct_synthesis(np.abs(spectrum), freqs, fmin=24, fmax=12600, n=3) +# spec_1f, freq_1f = noct_synthesis(np.abs(spectrum), freqs, fmin=24, fmax=12600, n=1) + +# plt.figure() +# plt.semilogx(freq_3t, _dB(spec_3t), label='noct spectrum') +# plt.semilogx(freq_3f, _dB(spec_3f), label='noct synth') +# plt.legend() + +# plt.figure() +# plt.semilogx(freq_1t, _dB(spec_1t), label='noct spectrum') +# plt.semilogx(freq_1f, _dB(spec_1f), label='noct synth') +# plt.legend() + +# plt.show() + +# np.testing.assert_allclose(_dB(spec_3t[:, 0]), _dB(spec_3f), atol=0.3) +# np.testing.assert_allclose(_dB(spec_1t[:, 0]), _dB(spec_1f), atol=0.3) + # test de la fonction if __name__ == "__main__": - test_noct_synthesis() + test_noct_synthesis_technical() + # test_noct_synthesis_synthetic() diff --git a/tests/sq_metrics/tonality/test_pr_ecma_st.py b/tests/sq_metrics/tonality/test_pr_ecma_st.py index c7f5d39a..e1baec3d 100644 --- a/tests/sq_metrics/tonality/test_pr_ecma_st.py +++ b/tests/sq_metrics/tonality/test_pr_ecma_st.py @@ -8,7 +8,7 @@ "In order to perform the tests you need the 'pytest' package." ) - +import numpy as np # Local application imports from mosqito.utils import load from mosqito.sq_metrics import pr_ecma_st @@ -30,19 +30,20 @@ def test_pr_ecma_st(): None """ # Test signal as input for prominence ratio calculation - # signals generated using audacity : white noise + tones at 200 and 2000 Hz + # signals generated using audacity : white noise + tones at 442 and 1768 Hz signal = { "data_file": "tests/input/white_noise_442_1768_Hz_stationary.wav" } # Load signal - audio, fs = load(signal["data_file"]) + audio, fs = load(signal["data_file"], wav_calib=0.01) # Compute tone-to-noise ratio - pr = pr_ecma_st( audio, fs, prominence=True) - - + t_pr, pr, prom, freq = pr_ecma_st(audio, fs, prominence=True) + np.testing.assert_almost_equal(t_pr, 32.20980078537321) + np.testing.assert_almost_equal(freq.astype(np.int32), [442, 1768]) + assert np.count_nonzero(prom == True) == 2 if __name__ == "__main__": diff --git a/tests/sq_metrics/tonality/test_pr_ecma_tv.py b/tests/sq_metrics/tonality/test_pr_ecma_tv.py index 10eac97b..ff4777bf 100644 --- a/tests/sq_metrics/tonality/test_pr_ecma_tv.py +++ b/tests/sq_metrics/tonality/test_pr_ecma_tv.py @@ -8,7 +8,7 @@ "In order to perform the tests you need the 'pytest' package." ) - +import numpy as np # Local application imports from mosqito.utils import load from mosqito.sq_metrics import pr_ecma_tv @@ -30,18 +30,21 @@ def test_pr_ecma_tv(): None """ # Test signal as input for prominence ratio calculation - # signals generated using audacity : white noise + tones at 200 and 2000 Hz + # signals generated using audacity : white noise + tones at 442 and 1768 Hz signal = { "data_file": "tests/input/white_noise_442_1768_Hz_varying.wav" } # Load signal - audio, fs = load(signal["data_file"]) + audio, fs = load(signal["data_file"], wav_calib=0.01) # Compute tone-to-noise ratio - t_pr, pr, prom, freq, time = pr_ecma_tv( audio, fs, prominence=True) - + t_pr, pr, prom, freq, time = pr_ecma_tv(audio, fs, prominence=True) + np.testing.assert_almost_equal(max(t_pr), 34.02082433185258) + assert pr[np.argmin(np.abs(freq-442)),:].all() != np.nan + assert pr[np.argmin(np.abs(freq-1768)),2:3].all() != np.nan + assert np.count_nonzero(prom == True) == 8 diff --git a/tests/sq_metrics/tonality/test_tnr_ecma_st.py b/tests/sq_metrics/tonality/test_tnr_ecma_st.py index e633aa0f..3480ebf8 100644 --- a/tests/sq_metrics/tonality/test_tnr_ecma_st.py +++ b/tests/sq_metrics/tonality/test_tnr_ecma_st.py @@ -9,7 +9,7 @@ "In order to perform the tests you need the 'pytest' package." ) - +import numpy as np # Local application imports from mosqito.utils import load from mosqito.sq_metrics import tnr_ecma_st @@ -30,18 +30,21 @@ def test_tnr_ecma_st(): ------- None """ - # Test signal as input for prominence ratio calculation - # signals generated using audacity : white noise + tones at 200 and 2000 Hz + # Test signal as input for tone to noise ratio calculation + # signals generated using audacity : white noise + tones at 442 and 1768 Hz signal = { - "tones freq": [200, 2000], + "tones freq": [442, 1768], "data_file": "tests/input/white_noise_442_1768_Hz_stationary.wav" } # Load signal - audio, fs = load(signal["data_file"]) + audio, fs = load(signal["data_file"], wav_calib=0.01) # Compute tone-to-noise ratio - tnr = tnr_ecma_st(audio, fs, prominence=True) + t_tnr, tnr, prom, freq = tnr_ecma_st(audio, fs, prominence=True) + np.testing.assert_almost_equal(t_tnr, 32.7142766) + np.testing.assert_almost_equal(freq.astype(np.int32), [442, 1768]) + assert np.count_nonzero(prom == True) == 2 if __name__ == "__main__": test_tnr_ecma_st() diff --git a/tests/sq_metrics/tonality/test_tnr_ecma_tv.py b/tests/sq_metrics/tonality/test_tnr_ecma_tv.py index dbfb69b4..26207d68 100644 --- a/tests/sq_metrics/tonality/test_tnr_ecma_tv.py +++ b/tests/sq_metrics/tonality/test_tnr_ecma_tv.py @@ -28,17 +28,20 @@ def test_tnr_ecma_tv(): None """ # Test signal as input for prominence ratio calculation - # signals generated using audacity : white noise + tones at 200 and 2000 Hz + # signals generated using audacity : white noise + tones at 442 and 1768 Hz - signal = {"data_file": "tests/input/white_noise_442_1768_Hz_varying.wav"} + signal = {"freq": [442, 1768], + "data_file": "tests/input/white_noise_442_1768_Hz_varying.wav"} # Load signal - audio, fs = load(signal["data_file"]) + audio, fs = load(signal["data_file"], wav_calib=0.01) # Compute tone-to-noise ratio t_tnr, tnr, prom, freq, time = tnr_ecma_tv(audio, fs, prominence=True) - np.testing.assert_almost_equal(max(t_tnr), 34.995108238375025) - assert np.count_nonzero(prom == True) == 6 + np.testing.assert_almost_equal(max(t_tnr), 34.710964273840155) + assert tnr[np.argmin(np.abs(freq-442)),:].all() != np.nan + assert tnr[np.argmin(np.abs(freq-1768)),2:3].all() != np.nan + assert np.count_nonzero(prom == True) == 8 if __name__ == "__main__": diff --git a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_1.png b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_1.png index 102ce828..180e63ca 100644 Binary files a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_1.png and b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_1.png differ diff --git a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_2_(250_Hz_80_dB).png b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_2_(250_Hz_80_dB).png index f0e04419..c0b45087 100644 Binary files a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_2_(250_Hz_80_dB).png and b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_2_(250_Hz_80_dB).png differ diff --git a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_3_(1_kHz_60_dB).png b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_3_(1_kHz_60_dB).png index 3b180d06..c9f564b7 100644 Binary files a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_3_(1_kHz_60_dB).png and b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_3_(1_kHz_60_dB).png differ diff --git a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_4_(4_kHz_40_dB).png b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_4_(4_kHz_40_dB).png index 614513d5..336fa57e 100644 Binary files a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_4_(4_kHz_40_dB).png and b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_4_(4_kHz_40_dB).png differ diff --git a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_5_(pinknoise_60_dB).png b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_5_(pinknoise_60_dB).png index f4037630..fe970bbd 100644 Binary files a/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_5_(pinknoise_60_dB).png and b/validations/sq_metrics/loudness_zwst/output/validation_loudness_zwst_Test_signal_5_(pinknoise_60_dB).png differ diff --git a/validations/sq_metrics/loudness_zwst/validation_loudness_zwst.py b/validations/sq_metrics/loudness_zwst/validation_loudness_zwst.py index 1e3882a3..e10ac187 100644 --- a/validations/sq_metrics/loudness_zwst/validation_loudness_zwst.py +++ b/validations/sq_metrics/loudness_zwst/validation_loudness_zwst.py @@ -20,13 +20,9 @@ from mosqito.sq_metrics import loudness_zwst from mosqito.utils import isoclose from mosqito.utils import load -from mosqito.sq_metrics.loudness.loudness_zwst._main_loudness import ( - _main_loudness, -) -from mosqito.sq_metrics.loudness.loudness_zwst._calc_slopes import ( - _calc_slopes, -) -from validations.sq_metrics.loudness_zwst.input.ISO_532_1.test_signal_1 import test_signal_1 +from mosqito.sq_metrics.loudness.loudness_zwst._main_loudness import _main_loudness +from mosqito.sq_metrics.loudness.loudness_zwst._calc_slopes import _calc_slopes +from input.ISO_532_1.test_signal_1 import test_signal_1 def validation_loudness_zwst_3oct(): @@ -50,7 +46,7 @@ def validation_loudness_zwst_3oct(): # (from ISO 532-1 annex B2) : test_signal_1 # Load ISO reference outputs - file_path = "./validations/sq_metrics/loudness_zwst/input/ISO_532_1/test_signal_1.csv" + file_path = "input/ISO_532_1/test_signal_1.csv" N_iso = 83.296 N_specif_iso = np.genfromtxt( file_path, skip_header=1 @@ -96,24 +92,24 @@ def validation_loudness_zwst(): signals = [ { - "data_file": "./validations/sq_metrics/loudness_zwst/input/ISO_532_1/Test signal 2 (250 Hz 80 dB).wav", + "data_file": "input/ISO_532_1/Test signal 2 (250 Hz 80 dB).wav", "N": 14.655, - "N_specif_file": "./validations/sq_metrics/loudness_zwst/input/ISO_532_1/test_signal_2.csv", + "N_specif_file": "input/ISO_532_1/test_signal_2.csv", }, { - "data_file": "./validations/sq_metrics/loudness_zwst/input/ISO_532_1/Test signal 3 (1 kHz 60 dB).wav", + "data_file": "input/ISO_532_1/Test signal 3 (1 kHz 60 dB).wav", "N": 4.019, - "N_specif_file": "./validations/sq_metrics/loudness_zwst/input/ISO_532_1/test_signal_3.csv", + "N_specif_file": "input/ISO_532_1/test_signal_3.csv", }, { - "data_file": "./validations/sq_metrics/loudness_zwst/input/ISO_532_1/Test signal 4 (4 kHz 40 dB).wav", + "data_file": "input/ISO_532_1/Test signal 4 (4 kHz 40 dB).wav", "N": 1.549, - "N_specif_file": "./validations/sq_metrics/loudness_zwst/input/ISO_532_1/test_signal_4.csv", + "N_specif_file": "input/ISO_532_1/test_signal_4.csv", }, { - "data_file": "./validations/sq_metrics/loudness_zwst/input/ISO_532_1/Test signal 5 (pinknoise 60 dB).wav", + "data_file": "input/ISO_532_1/Test signal 5 (pinknoise 60 dB).wav", "N": 10.498, - "N_specif_file": "./validations/sq_metrics/loudness_zwst/input/ISO_532_1/test_signal_5.csv", + "N_specif_file": "input/ISO_532_1/test_signal_5.csv", }, ] @@ -166,7 +162,7 @@ def _format_plot(is_isoclose_N, is_isoclose_N_specific, N, N_iso, filename): transform=plt.gca().transAxes, bbox=props, ) - out_dir = "./validations/sq_metrics/loudness_zwst/output/" + out_dir = "output/" plt.savefig( out_dir + 'validation_loudness_zwst_' + "_".join(filename.split(" ")) + ".png", diff --git a/validations/sq_metrics/loudness_zwtv/validation_loudness_zwtv.py b/validations/sq_metrics/loudness_zwtv/validation_loudness_zwtv.py index cda7b185..9b0a89db 100644 --- a/validations/sq_metrics/loudness_zwtv/validation_loudness_zwtv.py +++ b/validations/sq_metrics/loudness_zwtv/validation_loudness_zwtv.py @@ -28,141 +28,141 @@ signal = np.zeros((20), dtype=dict) signal[0] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Test signal 6 (tone 250 Hz 30 dB - 80 dB).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.4/Test signal 6 (tone 250 Hz 30 dB - 80 dB).wav", + "xls": "input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", "tab": "Test signal 6", "N_specif_bark": 2.5, "field": "free", } signal[1] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Test signal 7 (tone 1 kHz 30 dB - 80 dB).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.4/Test signal 7 (tone 1 kHz 30 dB - 80 dB).wav", + "xls": "input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", "tab": "Test signal 7", "N_specif_bark": 8.5, "field": "free", } signal[2] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Test signal 8 (tone 4 kHz 30 dB - 80 dB).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.4/Test signal 8 (tone 4 kHz 30 dB - 80 dB).wav", + "xls": "input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", "tab": "Test signal 8", "N_specif_bark": 17.5, "field": "free", } signal[3] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Test signal 9 (pink noise 0 dB - 50 dB).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.4/Test signal 9 (pink noise 0 dB - 50 dB).wav", + "xls": "input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", "tab": "Test signal 9", "N_specif_bark": 17.5, "field": "free", } signal[4] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Test signal 10 (tone pulse 1 kHz 10 ms 70 dB).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.4/Test signal 10 (tone pulse 1 kHz 10 ms 70 dB).wav", + "xls": "input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", "tab": "Test signal 10", "N_specif_bark": 8.5, "field": "free", } signal[5] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Test signal 11 (tone pulse 1 kHz 50 ms 70 dB).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.4/Test signal 11 (tone pulse 1 kHz 50 ms 70 dB).wav", + "xls": "input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", "tab": "Test signal 11", "N_specif_bark": 8.5, "field": "free", } signal[6] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Test signal 12 (tone pulse 1 kHz 500 ms 70 dB).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.4/Test signal 12 (tone pulse 1 kHz 500 ms 70 dB).wav", + "xls": "input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", "tab": "Test signal 12", "N_specif_bark": 8.5, "field": "free", } signal[7] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Test signal 13 (combined tone pulses 1 kHz).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.4/Test signal 13 (combined tone pulses 1 kHz).wav", + "xls": "input/ISO_532-1/Annex B.4/Results and tests for synthetic signals (time varying loudness).xlsx", "tab": "Test signal 13", "N_specif_bark": 8.5, "field": "free", } signal[8] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 14 (propeller-driven airplane).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 14 (propeller-driven airplane).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 14", "N_specif_bark": -1, "field": "free", } signal[9] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 15 (vehicle interior 40 kmh).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 15 (vehicle interior 40 kmh).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 15", "N_specif_bark": -1, "field": "diffuse", } signal[10] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 16 (hairdryer).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 16 (hairdryer).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 16", "N_specif_bark": -1, "field": "free", } signal[11] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 17 (machine gun).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 17 (machine gun).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 17", "N_specif_bark": -1, "field": "free", } signal[12] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 18 (hammer).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 18 (hammer).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 18", "N_specif_bark": -1, "field": "free", } signal[13] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 19 (door creak).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 19 (door creak).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 19", "N_specif_bark": -1, "field": "free", } signal[14] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 20 (shaking coins).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 20 (shaking coins).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 20", "N_specif_bark": -1, "field": "free", } signal[15] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 21 (jackhammer).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 21 (jackhammer).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 21", "N_specif_bark": -1, "field": "free", } signal[16] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 22 (ratchet wheel (large)).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 22 (ratchet wheel (large)).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 22", "N_specif_bark": -1, "field": "free", } signal[17] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 23 (typewriter).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 23 (typewriter).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 23", "N_specif_bark": -1, "field": "free", } signal[18] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 24 (woodpecker).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 24 (woodpecker).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 24", "N_specif_bark": -1, "field": "free", } signal[19] = { - "data_file": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 25 (full can rattle).wav", - "xls": "./validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", + "data_file": "input/ISO_532-1/Annex B.5/Test signal 25 (full can rattle).wav", + "xls": "input/ISO_532-1/Annex B.5/Results and tests for technical signals (time varying loudness).xlsx", "tab": "Test signal 25", "N_specif_bark": -1, "field": "free", @@ -213,7 +213,7 @@ def validation_loudness_zwtv(signal): # Check ISO 532-1 compliance _check_compliance( - loudness, signal, "./validations/sq_metrics/loudness_zwtv/output/" + loudness, signal, "output/" ) diff --git a/validations/sq_metrics/sharpness_din/validation_sharpness_din.py b/validations/sq_metrics/sharpness_din/validation_sharpness_din.py index ecf2b3e4..1203acfd 100644 --- a/validations/sq_metrics/sharpness_din/validation_sharpness_din.py +++ b/validations/sq_metrics/sharpness_din/validation_sharpness_din.py @@ -22,84 +22,84 @@ broadband = np.zeros((20), dtype=dict) broadband[0] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_250.wav", + "data_file": "input/broadband_250.wav", "type": "Broad-band", "S": 2.70, } broadband[1] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_350.wav", + "data_file": "input/broadband_350.wav", "S": 2.74, } broadband[2] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_450.wav", + "data_file": "input/broadband_450.wav", "S": 2.78, } broadband[3] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_570.wav", + "data_file": "input/broadband_570.wav", "S": 2.85, } broadband[4] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_700.wav", + "data_file": "input/broadband_700.wav", "S": 2.91, } broadband[5] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_840.wav", + "data_file": "input/broadband_840.wav", "S": 2.96, } broadband[6] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_1000.wav", + "data_file": "input/broadband_1000.wav", "S": 3.05, } broadband[7] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_1170.wav", + "data_file": "input/broadband_1170.wav", "S": 3.12, } broadband[8] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_1370.wav", + "data_file": "input/broadband_1370.wav", "S": 3.20, } broadband[9] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_1600.wav", + "data_file": "input/broadband_1600.wav", "S": 3.30, } broadband[10] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_1850.wav", + "data_file": "input/broadband_1850.wav", "S": 3.42, } broadband[11] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_2150.wav", + "data_file": "input/broadband_2150.wav", "S": 3.53, } broadband[12] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_2500.wav", + "data_file": "input/broadband_2500.wav", "S": 3.69, } broadband[13] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_2900.wav", + "data_file": "input/broadband_2900.wav", "S": 3.89, } broadband[14] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_3400.wav", + "data_file": "input/broadband_3400.wav", "S": 4.12, } broadband[15] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_4000.wav", + "data_file": "input/broadband_4000.wav", "S": 4.49, } broadband[16] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_4800.wav", + "data_file": "input/broadband_4800.wav", "S": 5.04, } broadband[17] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_5800.wav", + "data_file": "input/broadband_5800.wav", "S": 5.69, } broadband[18] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_7000.wav", + "data_file": "input/broadband_7000.wav", "S": 6.47, } broadband[19] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/broadband_8500.wav", + "data_file": "input/broadband_8500.wav", "S": 7.46, } @@ -108,88 +108,88 @@ narrowband = np.zeros((21), dtype=dict) narrowband[0] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_250.wav", + "data_file": "input/narrowband_250.wav", "type": "Narrow-band", "S": 0.38, } narrowband[1] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_350.wav", + "data_file": "input/narrowband_350.wav", "S": 0.49, } narrowband[2] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_450.wav", + "data_file": "input/narrowband_450.wav", "S": 0.6, } narrowband[3] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_570.wav", + "data_file": "input/narrowband_570.wav", "S": 0.71, } narrowband[4] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_700.wav", + "data_file": "input/narrowband_700.wav", "S": 0.82, } narrowband[5] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_840.wav", + "data_file": "input/narrowband_840.wav", "S": 0.93, } narrowband[6] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_1000.wav", + "data_file": "input/narrowband_1000.wav", "S": 1.00, } narrowband[7] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_1170.wav", + "data_file": "input/narrowband_1170.wav", "S": 1.13, } narrowband[8] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_1370.wav", + "data_file": "input/narrowband_1370.wav", "S": 1.26, } narrowband[9] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_1600.wav", + "data_file": "input/narrowband_1600.wav", "S": 1.35, } narrowband[10] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_1850.wav", + "data_file": "input/narrowband_1850.wav", "S": 1.49, } narrowband[11] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_2150.wav", + "data_file": "input/narrowband_2150.wav", "S": 1.64, } narrowband[12] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_2500.wav", + "data_file": "input/narrowband_2500.wav", "S": 1.78, } narrowband[13] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_2900.wav", + "data_file": "input/narrowband_2900.wav", "S": 2.06, } narrowband[14] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_3400.wav", + "data_file": "input/narrowband_3400.wav", "S": 2.40, } narrowband[15] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_4000.wav", + "data_file": "input/narrowband_4000.wav", "S": 2.82, } narrowband[16] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_4800.wav", + "data_file": "input/narrowband_4800.wav", "S": 3.48, } narrowband[17] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_5800.wav", + "data_file": "input/narrowband_5800.wav", "S": 4.43, } narrowband[18] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_7000.wav", + "data_file": "input/narrowband_7000.wav", "S": 5.52, } narrowband[19] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_8500.wav", + "data_file": "input/narrowband_8500.wav", "S": 6.81, } narrowband[20] = { - "data_file": "./validations/sq_metrics/sharpness_din/input/narrowband_10500.wav", + "data_file": "input/narrowband_10500.wav", "S": 8.55, } @@ -302,7 +302,7 @@ def _check_compliance(sharpness, reference, noise_type): plt.ylabel("Sharpness, [acum]") plt.savefig( - "./validations/sq_metrics/sharpness_din/output/" + "output/" + "validation_sharpness_" + noise_type + "_noise"