cutcutcodec.core.filter.audio.resample.anti_aliasing
- cutcutcodec.core.filter.audio.resample.anti_aliasing(rate: Integral, cutoff: Real, band: Real | None = None, attenuation: Real = 120.0) ndarray[source]
Find the best type 1 impulse response that perfectly matchs the constraints.
Search the low pass symetric odd filter filter as possible. This filter introduces a linear phase shift, with a time delay equal to
len(rif)/(2*rate).Parameters
- rateint
The sampling rate of the filter in time domain in Hz.
- cutofffloat
The cut-off absolute frequency in Hz. It has to be < rate/2. It is not the -3 dB but the
-attenuationdB frequency.- bandfloat, optional
The absolute width of the transition band in Hz. If not provide, the value is compute for an audio application that correspond to the perceptive frequency hearing threshold resolution. It is based on a MEL cut-off of 5 musical cents, or 5 mel_cent. One cent is define by cent = f0 * 2**(1/1200).
- attenuationfloat, default=120
The attenuation in the stopband in dB. Transmitted to
cutcutcodec.core.filter.audio.resample.kaiser.
Returns
- rifnp.ndarray
The 1d symetric odd finite response that matche the given constraints.
Examples
>>> import numpy as np >>> from cutcutcodec.core.filter.audio.resample import anti_aliasing >>> fir = anti_aliasing(48000, 8000) >>> np.round(fir, 11) array([-3.8e-10, -5.6e-10, -1.8e-10, ..., -1.8e-10, -5.6e-10, -3.8e-10], shape=(45587,)) >>> >>> # import matplotlib.pyplot as plt >>> # fig, (ax_t, ax_f) = plt.subplots(ncols=2) >>> # _ = fig.suptitle("FIR filter design") >>> # _ = ax_f.set_title("Frequency domain response") >>> # _ = ax_f.set_xlabel("freq [Hz]") >>> # _ = ax_f.set_ylabel("gain [dB]") >>> # _ = ax_t.set_title("Temporal domain response") >>> # _ = ax_t.set_xlabel("time [s]") >>> # _ = ax_t.set_ylabel("magnitude") >>> # _ = ax_t.plot(np.arange(len(fir))/48000, fir, "o-") >>> # _ = ax_f.plot( >>> # np.linspace(-24000, 24000, 128*len(fir)+1), >>> # 20*np.log10(abs(np.fft.fftshift(np.fft.fft(fir, n=128*len(fir)+1)/48000)))) >>> # fig.tight_layout() >>> # plt.show() >>>