From 7647cebb8cd148ec5acc2b563cb18efe02410645 Mon Sep 17 00:00:00 2001 From: nrmarinho Date: Thu, 13 Jul 2023 14:43:28 +0200 Subject: [PATCH 1/2] Add plot Discrete Wavelet Transform Coefficients --- acoustics/signal.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/acoustics/signal.py b/acoustics/signal.py index 4481ae6..9177028 100644 --- a/acoustics/signal.py +++ b/acoustics/signal.py @@ -80,6 +80,7 @@ import numpy as np from scipy.sparse import spdiags from scipy.signal import butter, lfilter, freqz, filtfilt, sosfilt +from scipy.integrate import simpson import acoustics.octave #from acoustics.octave import REFERENCE @@ -1283,6 +1284,21 @@ def linear_phase(ntaps, steepness=1): return np.exp(-1j * 2. * np.pi * f * alpha) + +def transmitted_energy(signal, fs): + """Compute the integration over time of the amplitude envelope in a time-domain input signal + + :param signal: signal + :param fs: sample frequency + + The transmitted energy is the signal feature used to compare the signal response to different impact energies. + """ + analytic_signal= hilbert(signal) + amplitude_envelope = np.abs(analytic_signal) + area = simpson(amplitude_envelope, dx=1/fs) + return area + + __all__ = [ 'bandpass', 'bandpass_frequencies', From 4aad1b68e191cd5033f4f06a0b307e5c3a23753c Mon Sep 17 00:00:00 2001 From: nrmarinho Date: Thu, 13 Jul 2023 14:44:13 +0200 Subject: [PATCH 2/2] Add Plot Discrete Wavelet Transform Coefficients --- acoustics/imaging.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/acoustics/imaging.py b/acoustics/imaging.py index 0c6e6b5..a6bbae1 100644 --- a/acoustics/imaging.py +++ b/acoustics/imaging.py @@ -325,3 +325,38 @@ def _set_separator(ticklabels, separator): decimal_number_format = item.replace('.', separator) bands_sep.append(decimal_number_format) return bands_sep + +def plotDWTcoeff(signal,wavelet,fs): + """ + Plot Discrete Wavelet Transform Coefficients (Level 1) + + :param signal: signal + :param fs: sample frequency + :param fwavelet : Wavelet to use in the transform + + """ + [cA, cD] = pywt.wavedec(signal, wavelet, level= 1) + + L = len(signal); + t= np.arange(0,(len(signal))/fs, 1/fs) + plt.figure(figsize=(30, 20)); + + plt.subplot(3, 1, 1) + plt.plot(t, signal, color='k'); + plt.xlabel('Time'); + plt.ylabel('S'); + plt.title('Original Signal'); + + plt.subplot(3, 1, 2) + plt.plot(cA, color='r'); + plt.xlabel('Samples'); + plt.ylabel('cA'); + plt.title('Approximation Coeff. (cA)'); + + plt.subplot(3, 1, 3) + plt.plot(cD, color='g'); + plt.xlabel('Samples'); + plt.ylabel('cD'); + plt.title('Detailed Coeff. (cD)'); + + plt.show()