maad.util.index_bw

maad.util.index_bw(fn, bw)[source]

Select all the index coresponding to a selected frequency band.

Parameters:
fn1d ndarray of scalars

Vector of frequencies

bwsingle value or tupple of two values

if single value : frequency to select if tupple of two values : min frequency and max frequency to select

Returns:
index1d ndarray of scalars

Vector of booleans corresponding to the selected frequency(-ies)

Examples

>>> 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) # convert into dB
>>> bw = (2000,6000) #in Hz
>>> fig_kwargs = {'vmax': Sxx_dB.max(),
                  'vmin': -90,
                  'extent':(tn[0], tn[-1], fn[0], fn[-1]),
                  'figsize':(10,13),
                  'title':'Power Spectrum Density (PSD)',
                  'xlabel':'Time [sec]',
                  'ylabel':'Frequency [Hz]',
                  }
>>> maad.util.plot2d(Sxx_dB,**fig_kwargs)
>>> Sxx_dB_crop = Sxx_dB[maad.util.index_bw(fn, bw)]
>>> fn_crop = fn[maad.util.index_bw(fn, bw)]
>>> fig_kwargs = {'vmax': Sxx_dB.max(),
                  'vmin': -90,
                  'extent':(tn[0], tn[-1], fn_crop[0], fn_crop[-1]),
                  'figsize':(10*len(fn_crop)/len(fn),13),
                  'title':'Power Spectrum Density (PSD)',
                  'xlabel':'Time [sec]',
                  'ylabel':'Frequency [Hz]',
                  }
>>> maad.util.plot2d(Sxx_dB_crop,**fig_kwargs)