maad.sound.select_bandwidth

maad.sound.select_bandwidth(x, fs, fcut, forder, fname='butter', ftype='bandpass', rp=None, rs=None)[source]

Use a lowpass, highpass, bandpass or bandstop filter to process a 1d signal with an iir filter.

Parameters:
xarray_like

1d vector of scalars to be filtered

fsscalar

sampling frequency

fcutarray_like

A scalar or length-2 sequence giving the critical frequencies.

forderint

The order of the filter.

fname{butter, ‘cheby1`, cheby2, ellip, bessel}, optional, default

is ‘butter’ The type of IIR filter to design: - Butterworth : butter - Chebyshev I : ‘cheby1` - Chebyshev II : cheby2 - Cauer/elliptic: ellip - Bessel/Thomson: bessel

ftype{bandpass, lowpass, highpass, bandstop}, optional, default

is bandpass The type of filter.

rpfloat, optional

For Chebyshev and elliptic filters, provides the maximum ripple in the passband. (dB)

rsfloat, optional

For Chebyshev and elliptic filters, provides the minimum attenuation in the stop band. (dB)

Returns:
yarray_like

The filtered output with the same shape and phase as x

See also

fir_filter1d

Lowpass, highpass, bandpass or bandstop a 1d signal with an Fir filter

Examples

>>> import maad

Load and display the spectrogram of a sound waveform

>>> w, fs = maad.sound.load('../data/cold_forest_daylight.wav') 
>>> Sxx_power,tn,fn,_ = maad.sound.spectrogram(w,fs)
>>> Sxx_dB = maad.spl.power2dBSPL(Sxx_power, gain=42) # convert into dB SPL
>>> fig_kwargs = {'vmax': Sxx_dB.max(),                    'vmin':0,                    'extent':(tn[0], tn[-1], fn[0], fn[-1]),                    'figsize':(4,13),                    'title':'Power spectrogram density (PSD)',                    'xlabel':'Time [sec]',                    'ylabel':'Frequency [Hz]',                    }
>>> ax, fig = maad.util.plot2d(Sxx_dB, **fig_kwargs)
>>> print('The energy in the spectrogram is {} dB SPL'.format(maad.util.add_dB(maad.util.add_dB(Sxx_dB))))
The energy in the spectrogram is 90.68996875800728 dB SPL

Filter the waveform : keep the bandwidth between 6-10kHz

>>> w_filtered = maad.sound.select_bandwidth(w,fs,fcut=(6000,10000), forder=5, fname ='butter', ftype='bandpass')
>>> Sxx_power_filtered,tn,fn,_ = maad.sound.spectrogram(w_filtered,fs)
>>> Sxx_dB_filtered = maad.spl.power2dBSPL(Sxx_power_filtered, gain=42) # convert into dB SPL
>>> ax, fig = maad.util.plot2d(Sxx_dB_filtered, **fig_kwargs)
>>> print('The energy in the spectrogram is {} dB SPL'.format(maad.util.add_dB(maad.util.add_dB(Sxx_dB_filtered))))
The energy in the spectrogram is 72.75045485363799 dB SPL