def hammingWindow(): ''' Generate plot of a Hamming window and windowed signal. ''' d = np.linspace(0, 4 * np.pi, 200) h = 200 * hamming(200) sig = 100 * np.sin(3 * d) windowed = sig * h / 200 plt.plot(h) plt.xticks([]) plt.yticks([]) plt.savefig('HammingWindowFunction.pdf') plt.close() plt.plot(sig) plt.xticks([]) plt.yticks([]) plt.savefig('Original.pdf') plt.close() plt.plot(windowed) plt.xticks([]) plt.yticks([]) plt.savefig('WindowedSignal.pdf') plt.close()
def hammingWindow(): ''' Generate plot of a Hamming window and windowed signal. ''' d = np.linspace(0,4*np.pi, 200) h = 200*hamming(200) sig = 100*np.sin(3*d) windowed = sig*h/200 plt.plot(h) plt.xticks([]) plt.yticks([]) plt.savefig('HammingWindowFunction.pdf') plt.close() plt.plot(sig) plt.xticks([]) plt.yticks([]) plt.savefig('Original.pdf') plt.close() plt.plot(windowed) plt.xticks([]) plt.yticks([]) plt.savefig('WindowedSignal.pdf') plt.close()
def extract(x): ''' Extract MFCC coefficients of the sound signal x in numpy array format. Inputs: x -- array of shape (88200,) Returns: array of shape (198,10), the MFCCs of x. ''' window = hamming(1323) feature = [] for i in xrange(198): # Windowing frame = x[i * 441:i * 441 + 1323] * window # Pre-emphasis frame[1:] -= frame[:-1] * .95 # Power spectrum X = np.abs(pyfftw.interfaces.scipy_fftpack.fft(frame, n=2048)[:1025])**2 X[X < 1e-100] = 1e-100 # Avoid zero # Mel filtering, logarithm, DCT M = melfb(40, 2048, 44100) X = 0.25 * pyfftw.interfaces.scipy_fftpack.dct(np.log(np.dot(M, X)))[1:11] feature.append(X) feature = np.row_stack(feature) return feature
def window(f): ''' Break up a signal into frames, and multiply each frame with a Hamming window. Create 198 frames of length 1323, with adjacent frames overlapping by 882 values. Inputs: f -- array of shape (88200,) Returns: List of length 198, containing arrays of shape (1323,), ordered according to the position of the frames relative to f. ''' window = hamming(1323) frames = [] for i in xrange(198): frame = f[i * 441:i * 441 + 1323] * window frames.append(frame) return frames
def window(f): ''' Break up a signal into frames, and multiply each frame with a Hamming window. Create 198 frames of length 1323, with adjacent frames overlapping by 882 values. Inputs: f -- array of shape (88200,) Returns: List of length 198, containing arrays of shape (1323,), ordered according to the position of the frames relative to f. ''' window = hamming(1323) frames = [] for i in xrange(198): frame = f[i*441: i*441 + 1323]*window frames.append(frame) return frames
def extract(x): ''' Extract MFCC coefficients of the sound signal x in numpy array format. Inputs: x -- array of shape (88200,) Returns: array of shape (198,10), the MFCCs of x. ''' window = hamming(1323) feature = [] for i in xrange(198): # Windowing frame = x[i*441: i*441 + 1323]*window # Pre-emphasis frame[1:] -= frame[:-1] * .95 # Power spectrum X = np.abs(pyfftw.interfaces.scipy_fftpack.fft(frame, n=2048)[:1025]) ** 2 X[X < 1e-100] = 1e-100 # Avoid zero # Mel filtering, logarithm, DCT M = melfb(40, 2048, 44100) X = 0.25*pyfftw.interfaces.scipy_fftpack.dct(np.log(np.dot(M,X)))[1:11] feature.append(X) feature = np.row_stack(feature) return feature