maad.util.get_unimode
- maad.util.get_unimode(X, mode='median', axis=1, N=7, N_bins=100, verbose=False)[source]
Get the statistical mode or modal value which is the most common number in the dataset.
- Parameters:
- X1d or 2d ndarray of scalars
Vector or matrix
- modestr, optional, default is ‘median’
Select the mode to remove the noise Possible values for mode are : - ‘ale’ : Adaptative Level Equalization algorithm [Lamel & al. 1981] - ‘median’ : subtract the median value - ‘mean’ : subtract the mean value (DC)
- axisinteger, default is 1
if matrix, estimate the mode for each row (axis=0) or each column (axis=1)
- Nint (only for mode = “ale”)
length of window to compute the running mean of the histogram
- N_binsint (only for mode = “ale”)
number of bins to compute the histogram
- verboseboolean, optional, default is False
print messages into the consol or terminal if verbose is True
- Returns:
- unimode_valuefloat
The most common number in the dataset
Notes
ale : Adaptative Level Equalization algorithm from Lamel et al., 1981 : L.F. Lamel, L.R. Rabiner, A.E. Rosenberg, J.G. Wilpon An improved endpoint detector for isolated word recognition IEEE Trans. ASSP, ASSP-29 (1981), pp. 777-785 DOI: 10.1109/TASSP.1981.1163642
Examples
This function is interesting to obtain the background noise (BGN) profile (e.g. frequency bin by frequency bin) of a spectrogram
>>> w, fs = maad.sound.load('../data/cold_forest_daylight.wav') >>> Sxx_power,tn,fn,_ = maad.sound.spectrogram(w,fs,window='hann',noverlap=512, nFFT=1024) >>> Sxx_dB = maad.util.power2dB(Sxx_power) >>> BGN_med = maad.util.get_unimode (Sxx_dB, mode='median', axis=1) >>> import matplotlib.pyplot as plt >>> plt.plot(fn,maad.util.mean_dB(Sxx_dB,axis=1)) >>> plt.plot(fn,BGN_med)
Extract the background noise from mean
>>> BGN_mean = maad.util.get_unimode (Sxx_dB, mode='mean', axis=1) >>> plt.plot(fn,BGN_mean)
Extract the background noise from ale (i.e. unimode)
>>> BGN_ale = maad.util.get_unimode (Sxx_dB, mode='ale', N=7, N_bins=100, axis=1) >>> plt.plot(fn,BGN_ale)