def test_scale_degenerate(self): orig = numpy.array([-3, -3, -3]) x1, range_old = peakutils.scale(orig, (5, 7)) x2, range_new = peakutils.scale(x1, range_old) assert_array_almost_equal(x1, [6, 6, 6]) assert_array_almost_equal(x2, orig)
def test_scale(self): orig = numpy.array([-2, -1, 0.5, 1, 3]) x1, range_old = peakutils.scale(orig, (-10, 8)) x2, range_new = peakutils.scale(x1, range_old) assert_array_almost_equal(orig, x2) self.assertTupleEqual(range_new, (-10, 8))
def binstoprocess_onset(Pnm0, sg, fL, fH, Fs, NFFT, olap): """ Select the bins with energy higher than RMS mean :param Pnm0: 0th-order SHD coefficient STFT matrix :param sg: 32xlength audio signals from em32 :param fL: Lower frequency bound :param fH: Higher frequency bound :param Fs: Sampling rate (Hz) :param NFFT: FFT size :param olap: (NFFT / olap) is the hop_size of the STFT :return: Time and frequency indices of the bins that are selected for HiGRID DOA estimation """ em32 = EigenmikeEM32() estr = em32.returnAsStruct() wts = estr['weights'] f1 = int(fL / Fs * NFFT) f2 = int(fH / Fs * NFFT) sgo = np.zeros(sg[0].shape) * 1j for ind in range(32): # Calculate omnidirectional response sgo += sg[ind] * wts[ind] ls = mm.audio.spectrogram.LogarithmicFilteredSpectrogram(sgo, frame_size=NFFT, hop_size=NFFT / olap, fft_size=NFFT, num_bands=24, sample_rate=Fs) os = mm.features.onsets.superflux(ls) # These are the onsets os = os / max(os) # These are the onsets in the analysed recording THR = np.sqrt(np.mean(np.array(os)**2)) pk = indexes(os, thres=THR, min_dist=2) idx = [] idy = [] for ind in pk: vect = np.abs(np.abs(np.array(Pnm0[ind, f1:f2 + 1]))) vb = baseline(vect, deg=2) vect, _ = scale(vect - vb) THRv = 0.1 ids = indexes(vect, thres=THRv, min_dist=1) for knd in ids: idx.append(ind) idy.append(f1 + knd) return idx, idy