maad.spl.apply_attenuation
- maad.spl.apply_attenuation(p0, fs, r, r0=1, t=20, rh=60, pa=101325, a0=0.02)[source]
Apply attenuation of a temporal signal p0 after propagation between the reference distance r0 and the final distance r taken into account the geometric, atmospheric and habitat attenuation contributions.
- Parameters:
- p0array-like (vector 1d)
temporal signal p0 in Pa (time domain)
- fs: scalar
sampling frequency Hz
- r: scalar
distance of propagation (in m) of the signal p0
- r0scalar
distance at which the temporal signal p0 was measured
- t: scalar, optional, default is 20
temperature in °C
- rh: scalar, optional, default is 60
relative humidity in %
- pa: scalar, optional, default is 101325
atmospheric pressure in Pa
- a0scalar, optional, default is 0.02
attenuation coefficient of the habitat in dB/kHz/m
- Returns:
- parray-like (vector 1d)
temporal signal (time domain) after attenuation
Examples
Prepare the spinetail sound (Sound level @1m = 85dB SPL).
>>> w, fs = maad.sound.load('../data/spinetail.wav') >>> p0 = maad.spl.wav2pressure(wave=w, gain=42) >>> p0_sig = p0[int(5.68*fs):int(7.48*fs)] >>> p0_noise = p0[int(8.32*fs):int(10.12*fs)] >>> Sxx_power, tn, fn, ext = maad.sound.spectrogram(p0_sig ,fs) >>> Sxx_power_noise, tn, fn, ext = maad.sound.spectrogram(p0_noise ,fs) >>> Sxx_dB = maad.util.power2dB(Sxx_power, db_range=96) + 96 >>> Sxx_dB_noise = maad.util.power2dB(Sxx_power_noise, db_range=96) + 96
Get the sound level of the spinetail song (sound between 4900-7500 Hz).
>>> p0_sig_4900_7500 = maad.sound.select_bandwidth(p0_sig,fs,fcut=[4900,7300],forder=10, ftype='bandpass') >>> L = maad.spl.pressure2leq(p0_sig_4900_7500, fs) >>> print ('Sound Level measured : %2.2fdB SPL' %L)
Estimate maximum distance from the source.
>>> r = maad.spl.active_distance(L, 85, f=(7500+4900)/2)
plot original spectrogram
>>> import matplotlib.pyplot as plt >>> fig, (ax1, ax2, ax3, ax4, ax5) = plt.subplots(1,5, sharex=True, figsize=(15,3)) >>> maad.util.plot2d(Sxx_dB, ax=ax1, extent=ext, vmin=0, vmax=70, figsize=[3,3])
Compute the audio attenuation at 10m.
>>> p_att = maad.spl.apply_attenuation(p0_sig, fs, r0=5, r =10) >>> Sxx_power_att, tn, fn, ext = maad.sound.spectrogram(p_att,fs) >>> Sxx_dB_att_10m = maad.util.power2dB(Sxx_power_att,db_range=96) + 96
>>> p_att = maad.spl.apply_attenuation(p0_sig, fs, r0=5, r =20) >>> Sxx_power_att, tn, fn, ext = maad.sound.spectrogram(p_att,fs) >>> Sxx_dB_att_20m = maad.util.power2dB(Sxx_power_att,db_range=96) + 96
>>> p_att = maad.spl.apply_attenuation(p0_sig, fs, r0=5, r =40) >>> Sxx_power_att, tn, fn, ext = maad.sound.spectrogram(p_att,fs) >>> Sxx_dB_att_40m = maad.util.power2dB(Sxx_power_att,db_range=96) + 96
>>> p_att = maad.spl.apply_attenuation(p0_sig, fs, r0=5, r =80) >>> Sxx_power_att, tn, fn, ext = maad.sound.spectrogram(p_att,fs) >>> Sxx_dB_att_80m = maad.util.power2dB(Sxx_power_att,db_range=96) + 96
Add noise to the signal.
>>> Sxx_dB_att_10m = maad.util.add_dB(Sxx_dB_att_10m,Sxx_dB_noise) - 3 >>> Sxx_dB_att_20m = maad.util.add_dB(Sxx_dB_att_20m,Sxx_dB_noise) - 3 >>> Sxx_dB_att_40m = maad.util.add_dB(Sxx_dB_att_40m,Sxx_dB_noise) - 3 >>> Sxx_dB_att_80m = maad.util.add_dB(Sxx_dB_att_80m,Sxx_dB_noise) - 3
Plot attenuated spectrogram.
>>> maad.util.plot2d(Sxx_dB_att_10m, ax=ax2, extent=ext, vmin=0, vmax=70, figsize=[3,3]) >>> maad.util.plot2d(Sxx_dB_att_20m, ax=ax3, extent=ext, vmin=0, vmax=70, figsize=[3,3]) >>> maad.util.plot2d(Sxx_dB_att_40m, ax=ax4, extent=ext, vmin=0, vmax=70, figsize=[3,3]) >>> maad.util.plot2d(Sxx_dB_att_80m, ax=ax5, extent=ext, vmin=0, vmax=70, figsize=[3,3])