def FeatureTimeRms(x, iBlockLength, iHopLength, f_s): # create blocks xBlocks = pyACA.ToolBlockAudio(x, iBlockLength, iHopLength) # number of results iNumOfBlocks = xBlocks.shape[0] # compute time stamps t = (np.arange(0, iNumOfBlocks) * iHopLength + (iBlockLength / 2)) / f_s # allocate memory vrms = np.zeros(iNumOfBlocks) for n, block in enumerate(xBlocks): # calculate the rms vrms[n] = np.sqrt(np.dot(block, block) / block.size) # convert to dB epsilon = 1e-5 # -100dB vrms[vrms < epsilon] = epsilon vrms = 20 * np.log10(vrms) return vrms, t
def FeatureTimeAcfCoeff(x, iBlockLength, iHopLength, f_s, eta=19): # create blocks xBlocks = pyACA.ToolBlockAudio(x, iBlockLength, iHopLength) # number of results iNumOfBlocks = xBlocks.shape[0] if (np.isscalar(eta)): iNumOfResultsPerBlock = 1 else: iNumOfResultsPerBlock = eta.size # compute time stamps t = (np.arange(0, iNumOfBlocks) * iHopLength + (iBlockLength / 2)) / f_s # allocate memory vacf = np.zeros([iNumOfResultsPerBlock, iNumOfBlocks]) for n, block in enumerate(xBlocks): # calculate the acf if not block.sum(): vacf[np.arange(0, iNumOfResultsPerBlock), n] = np.zeros(iNumOfResultsPerBlock) continue else: afCorr = np.correlate(block, block, "full") / np.dot(block, block) # find the coefficients specified in eta vacf[np.arange(0, iNumOfResultsPerBlock), n] = afCorr[iBlockLength + eta] return vacf, t
def FeatureTimeStd(x, iBlockLength, iHopLength, f_s): # create blocks xBlocks = pyACA.ToolBlockAudio(x, iBlockLength, iHopLength) # number of results iNumOfBlocks = xBlocks.shape[0] # compute time stamps t = (np.arange(0, iNumOfBlocks) * iHopLength + (iBlockLength / 2)) / f_s # allocate memory vstd = np.zeros(iNumOfBlocks) for n, block in enumerate(xBlocks): # calculate the rms vstd[n] = np.std(block) return vstd, t
def FeatureTimeZeroCrossingRate(x, iBlockLength, iHopLength, f_s): # create blocks xBlocks = pyACA.ToolBlockAudio(x, iBlockLength, iHopLength) # number of results iNumOfBlocks = xBlocks.shape[0] # compute time stamps t = (np.arange(0, iNumOfBlocks) * iHopLength + (iBlockLength / 2)) / f_s # allocate memory vzc = np.zeros(iNumOfBlocks) for n, block in enumerate(xBlocks): # calculate the zero crossing rate vzc[n] = 0.5 * np.mean(np.abs(np.diff(np.sign(block)))) return vzc, t
def FeatureTimePeakEnvelope(x, iBlockLength, iHopLength, f_s): # create blocks xBlocks = pyACA.ToolBlockAudio(x, iBlockLength, iHopLength) # number of results iNumOfBlocks = xBlocks.shape[0] # compute time stamps t = (np.arange(0, iNumOfBlocks) * iHopLength + (iBlockLength / 2)) / f_s alpha = 1 - np.array( [np.exp(-2.2 / (f_s * 0.01)), np.exp(-2.2 / (f_s * 1.5))]) # allocate memory vppm = np.zeros([2, iNumOfBlocks]) v_tmp = np.zeros(iBlockLength) for n, block in enumerate(xBlocks): x_block = np.abs(block) # detect the maximum per block vppm[0, n] = np.max(x_block) # calculate the PPM value - take into account block overlaps # and discard concerns wrt efficiency v_tmp = ppm(x_block, v_tmp[iHopLength - 1], alpha) vppm[1, n] = np.max(v_tmp) # convert to dB epsilon = 1e-5 # -100dB vppm[vppm < epsilon] = epsilon vppm = 20 * np.log10(vppm) return vppm, t
def FeatureTimeMaxAcf(x, iBlockLength, iHopLength, f_s, f_max=2000, fMinThresh=0.35): # create blocks xBlocks = pyACA.ToolBlockAudio(x, iBlockLength, iHopLength) # number of results iNumOfBlocks = xBlocks.shape[0] # compute time stamps t = (np.arange(0, iNumOfBlocks) * iHopLength + (iBlockLength / 2)) / f_s # allocate memory vacf = np.zeros(iNumOfBlocks) for n, block in enumerate(xBlocks): eta_min = np.floor(f_s / f_max).astype(int) # calculate the acf if not block.sum(): continue else: afCorr = np.correlate(block, block, "full") / np.dot(block, block) afCorr = afCorr[np.arange(iBlockLength, afCorr.size)] # update eta_min to avoid main lobe eta_tmp = np.argmax(afCorr < fMinThresh) eta_min = np.max([eta_min, eta_tmp]) afDeltaCorr = np.diff(afCorr) eta_tmp = np.argmax(afDeltaCorr > 0) eta_min = np.max([eta_min, eta_tmp]) # find the coefficients specified in eta vacf[n] = np.max(afCorr[np.arange(eta_min + 1, afCorr.size)]) return vacf, t