def feature_extraction_lp_group_delay(y, fs=44100, statistics=True, lpgd_params=None, win_params=None): eps = numpy.spacing(1) nfft = lpgd_params['nfft'] lp_order = lpgd_params['lp_order'] y = y + eps frames = segment_axis(y, win_params['win_length'], win_params['hop_length']); print 'frames : ' + str(frames.shape) a,e,k = lpc(frames, lp_order) print 'a : ' + str(a.shape) A = fft(a, nfft) A = 1/A phaseA = numpy.unwrap(numpy.angle(A)) print 'phaseA: ' + str(phaseA.shape) phaseA = phaseA[:,0:nfft/2] print 'phaseA: ' + str(phaseA.shape) tauA = -1 * numpy.diff(phaseA) print 'tauA' + str(tauA.shape) # tau = numpy.concatenate((tauA, tauA[-1])) # tau = tau feature_matrix = tauA feature_matrix = dct(feature_matrix, n=20) print 'fm: ' + str(feature_matrix.shape) # Collect into data structure if statistics: return { 'feat': feature_matrix, 'stat': { 'mean': numpy.mean(feature_matrix, axis=0), 'std': numpy.std(feature_matrix, axis=0), 'N': feature_matrix.shape[0], 'S1': numpy.sum(feature_matrix, axis=0), 'S2': numpy.sum(feature_matrix ** 2, axis=0), } } else: return { 'feat': feature_matrix}
def feature_extraction_gd(y, fs=44100, statistics=True, include_delta=True, include_acceleration=True, lpgd_params=None, win_params=None, delta_params=None, acceleration_params=None): eps = numpy.spacing(1) nfft = lpgd_params['nfft'] lp_order = lpgd_params['lp_order'] y = y + eps frames = segment_axis(y, win_params['win_length'], win_params['hop_length']); #print 'frames : ' + str(frames.shape) a,e,k = lpc(frames, lp_order) #print 'a : ' + str(a.shape) A = fft(a, nfft) A = 1/A phaseA = numpy.unwrap(numpy.angle(A)) #print 'phaseA: ' + str(phaseA.shape) phaseA = phaseA[:,0:nfft/2] #print 'phaseA: ' + str(phaseA.shape) tauA = -1 * numpy.diff(phaseA) #print 'tauA' + str(tauA.shape) tauA = numpy.vstack((tauA, tauA[-1])) # tau = tau # print 'tauA' + str(tauA.shape) feature_matrix = tauA feature_matrix = dct(feature_matrix, n=20) feature_matrix = feature_matrix.T print feature_matrix.shape if include_delta: # Delta coefficients feature_delta = librosa.feature.delta(feature_matrix, **delta_params) # Add Delta Coefficients to feature matrix feature_matrix = numpy.vstack((feature_matrix, feature_delta)) # print 'fm: ' + str(feature_matrix.shape) if include_acceleration: # Acceleration coefficients (aka delta) feature_delta2 = librosa.feature.delta(feature_delta, order=2, **acceleration_params) # Add Acceleration Coefficients to feature matrix feature_matrix = numpy.vstack((feature_matrix, feature_delta2)) feature_matrix = feature_matrix.T print 'fm: ' + str(feature_matrix.shape) # Collect into data structure if statistics: return { 'tauA' : tauA, 'feat': feature_matrix, 'stat': { 'mean': numpy.mean(feature_matrix, axis=0), 'std': numpy.std(feature_matrix, axis=0), 'N': feature_matrix.shape[0], 'S1': numpy.sum(feature_matrix, axis=0), 'S2': numpy.sum(feature_matrix ** 2, axis=0), } } else: return { 'feat': feature_matrix}
def feature_extraction_gd(y, fs=44100, statistics=True, include_delta=True, include_acceleration=True, lpgd_params=None, win_params=None, delta_params=None, acceleration_params=None): eps = numpy.spacing(1) nfft = lpgd_params['nfft'] lp_order = lpgd_params['lp_order'] y = y + eps frames = segment_axis(y, win_params['win_length'], win_params['hop_length']) #print 'frames : ' + str(frames.shape) a, e, k = lpc(frames, lp_order) #print 'a : ' + str(a.shape) A = fft(a, nfft) A = 1 / A phaseA = numpy.unwrap(numpy.angle(A)) #print 'phaseA: ' + str(phaseA.shape) phaseA = phaseA[:, 0:nfft / 2] #print 'phaseA: ' + str(phaseA.shape) tauA = -1 * numpy.diff(phaseA) #print 'tauA' + str(tauA.shape) tauA = numpy.vstack((tauA, tauA[-1])) # tau = tau # print 'tauA' + str(tauA.shape) feature_matrix = tauA feature_matrix = dct(feature_matrix, n=20) feature_matrix = feature_matrix.T print feature_matrix.shape if include_delta: # Delta coefficients feature_delta = librosa.feature.delta(feature_matrix, **delta_params) # Add Delta Coefficients to feature matrix feature_matrix = numpy.vstack((feature_matrix, feature_delta)) # print 'fm: ' + str(feature_matrix.shape) if include_acceleration: # Acceleration coefficients (aka delta) feature_delta2 = librosa.feature.delta(feature_delta, order=2, **acceleration_params) # Add Acceleration Coefficients to feature matrix feature_matrix = numpy.vstack((feature_matrix, feature_delta2)) feature_matrix = feature_matrix.T print 'fm: ' + str(feature_matrix.shape) # Collect into data structure if statistics: return { 'tauA': tauA, 'feat': feature_matrix, 'stat': { 'mean': numpy.mean(feature_matrix, axis=0), 'std': numpy.std(feature_matrix, axis=0), 'N': feature_matrix.shape[0], 'S1': numpy.sum(feature_matrix, axis=0), 'S2': numpy.sum(feature_matrix**2, axis=0), } } else: return {'feat': feature_matrix}