def log_cepstrum(data, fs, nc, p, n, w): # @UnusedVariable: n is never used!!! """ Cepstrum of a signal. Computes the cepstral coefficient on a logarithmic scale of the given data which can be windowed or not. If data are windowed the analytic signal and the envelope of each window is returned. :type data: :class:`~numpy.ndarray` :param data: Data to make envelope of. :param fs: Sampling frequency in Hz. :param nc: number of cepstral coefficients. :param p: Number of filters in filterbank. :param n: Number of data windows. :return: Cepstral coefficients. """ new_dtype = np.float32 if data.dtype.itemsize == 4 else np.float64 data = np.require(data, dtype=new_dtype) dataT = np.transpose(data) nfft = util.next_pow_2(dataT.shape[0]) fc = fftpack.fft(dataT, nfft, 0) f = fc[1:len(fc) // 2 + 1, :] m, a, b = log_spaced_filterbank_matrix(p, nfft, fs, w) pw = np.real(np.multiply(f[a:b, :], np.conj(f[a:b, :]))) pth = np.max(pw) * 1E-20 ath = np.sqrt(pth) # h1 = np.transpose(np.array([[ath] * int(b + 1 - a)])) # h2 = m * abs(f[a - 1:b, :]) y = np.log(np.maximum(m * abs(f[a - 1:b, :]), ath)) z = util.rdct(y) z = z[1:, :] # nc = nc + 1 nf = np.size(z, 1) if (p > nc): z = z[:nc, :] elif (p < nc): z = np.vstack([z, np.zeros(nf, nc - p)]) return z
def log_cepstrum(data, fs, nc, p, n, w): # @UnusedVariable: n is never used!!! """ Cepstrum of a signal. Computes the cepstral coefficient on a logarithmic scale of the given data which can be windowed or not. If data are windowed the analytic signal and the envelope of each window is returned. :type data: :class:`~numpy.ndarray` :param data: Data to make envelope of. :param fs: Sampling frequency in Hz. :param nc: number of cepstral coefficients. :param p: Number of filters in filterbank. :param n: Number of data windows. :return: Cepstral coefficients. """ new_dtype = np.float32 if data.dtype.itemsize == 4 else np.float64 data = np.require(data, dtype=new_dtype) data_t = np.transpose(data) nfft = util.next_pow_2(data_t.shape[0]) fc = fftpack.fft(data_t, nfft, 0) f = fc[1:len(fc) // 2 + 1, :] m, a, b = log_spaced_filterbank_matrix(p, nfft, fs, w) pw = np.real(np.multiply(f[a:b, :], np.conj(f[a:b, :]))) pth = np.max(pw) * 1E-20 ath = np.sqrt(pth) # h1 = np.transpose(np.array([[ath] * int(b + 1 - a)])) # h2 = m * abs(f[a - 1:b, :]) y = np.log(np.maximum(m * abs(f[a - 1:b, :]), ath)) z = util.rdct(y) z = z[1:, :] # nc = nc + 1 nf = np.size(z, 1) if (p > nc): z = z[:nc, :] elif (p < nc): z = np.vstack([z, np.zeros(nf, nc - p)]) return z