def CQT(samplerate, nfft, nwin=None, nhop=None, winfun=np.hamming, fmin=55.0, fmax=587.36, bpo=12): """Constant Q transform. Parameters ---------- samplerate : int Sampling rate of the incoming signal. nfft : int FFT length to use. nwin : int Length of each window in samples. Defaults to `nfft`. nhop : int Number of samples to skip between adjacent frames (hopsize). Defaults to `nwin`. winfun : function of the form fun(winlen), returns array of length winlen Function to generate a window of a given length. Defaults to numpy.hamming. fmin : float Frequency in Hz of the lowest edge of the Mel bands. Defaults to 0. fmax : float Frequency in Hz of the upper edge of the Mel bands. Defaults to `samplerate` / 2. bpo : int Number of bins per octave. """ CQ = constantqfb(samplerate, nfft, fmin, fmax, bpo) return dataprocessor.Pipeline(basic.STFT(nfft, nwin, nhop, winfun), basic.Filterbank(CQ))
def CQChroma(samplerate, nfft, nwin=None, nhop=None, winfun=np.hamming, fmin=55.0, fmax=587.36, nchroma=12): """Compute chroma features using the constant Q transform. Parameters ---------- samplerate : int Sampling rate of the incoming signal. nfft : int FFT length to use. nwin : int Length of each window in samples. Defaults to `nfft`. nhop : int Number of samples to skip between adjacent frames (hopsize). Defaults to `nwin`. winfun : function of the form fun(winlen), returns array of length winlen Function to generate a window of a given length. Defaults to numpy.hamming. fmin : float Frequency in Hz of the lowest edge of the Mel bands. Defaults to 0. fmax : float Frequency in Hz of the upper edge of the Mel bands. Defaults to `samplerate` / 2. nchroma : int Number of chroma dimensions to return (number of bins per octave). See Also -------- CQT : Constant Q transform Chroma : Alternate implementation of chroma features """ return dataprocessor.Pipeline(CQT(samplerate, nfft, nwin, nhop, winfun, fmin, fmax, nchroma), basic.Abs(), ConstantQToChroma(nchroma))
def MFCC(samplerate, nfft, nwin=None, nhop=None, winfun=np.hamming, nmel=40, width=1.0, fmin=0, fmax=None, ndct=13): """Mel-frequency Cepstral Coefficients Parameters ---------- samplerate : int Sampling rate of the incoming signal. nfft : int FFT length to use. nwin : int Length of each window in samples. Defaults to `nfft`. nhop : int Number of samples to skip between adjacent frames (hopsize). Defaults to `nwin`. winfun : function of the form fun(winlen), returns array of length winlen Function to generate a window of a given length. Defaults to numpy.hamming. nmel : int Number of Mel bands to use. width : float The constant width of each band relative to standard Mel. Defaults 1.0. fmin : float Frequency in Hz of the lowest edge of the Mel bands. Defaults to 0. fmax : float Frequency in Hz of the upper edge of the Mel bands. Defaults to `samplerate` / 2 ndct : int Number of DCT components (cepstra) to return. See Also -------- MelSpec : Mel-frequency power spectrum. """ DCT = dctfb(ndct, nmel) return dataprocessor.Pipeline( MelSpec(samplerate, nfft, nwin, nhop, winfun, nmel, width, fmin, fmax), basic.Log(), basic.Filterbank(DCT))
def MelSpec(samplerate, nfft, nwin=None, nhop=None, winfun=np.hamming, nmel=40, width=1.0, fmin=0, fmax=None): """Mel-frequency power spectrum. Parameters ---------- samplerate : int Sampling rate of the incoming signal. nfft : int FFT length to use. nwin : int Length of each window in samples. Defaults to `nfft`. nhop : int Number of samples to skip between adjacent frames (hopsize). Defaults to `nwin`. winfun : function of the form fun(winlen), returns array of length winlen Function to generate a window of a given length. Defaults to numpy.hamming. nmel : int Number of Mel bands to use. width : float The constant width of each band relative to standard Mel. Defaults 1.0. fmin : float Frequency in Hz of the lowest edge of the Mel bands. Defaults to 0. fmax : float Frequency in Hz of the upper edge of the Mel bands. Defaults to `samplerate` / 2 See Also -------- STFT : Short-time Fourier transform. """ FB = melfb(samplerate, nfft, nmel, width, fmin, fmax) return dataprocessor.Pipeline(basic.PowSpec(nfft, nwin, nhop, winfun), basic.Filterbank(FB))
def Chroma(samplerate, nfft, nwin=None, nhop=None, winfun=np.hamming, nchroma=12, center=1000, sd=1): """Compute chroma features using the constant Q transform. Parameters ---------- samplerate : int Sampling rate of the incoming signal. nfft : int FFT length to use. nwin : int Length of each window in samples. Defaults to `nfft`. nhop : int Number of samples to skip between adjacent frames (hopsize). Defaults to `nwin`. winfun : function of the form fun(winlen), returns array of length winlen Function to generate a window of a given length. Defaults to numpy.hamming. nchroma : int Number of chroma dimensions to return (number of bins per octave). center : int sd : int See Also -------- CQChroma : Alternate implementation of chroma features based on the constant Q transform. """ A0 = 27.5 # Hz A440 = 440.0 # Hz f_ctr_log = np.log2(center/A0) CM = chromafb(samplerate, nfft, nchroma, A440, f_ctr_log, sd) return dataprocessor.Pipeline(basic.STFT(nfft, nwin, nhop, winfun), basic.Abs(), PickPeaks(), basic.Filterbank(CM))