def test_all_features(self): if self.matlab_engine is None: self.skipTest("Matlab engine not available") # WhiteNoise input fs = 44100 x_py = np.random.uniform(-1, 1, size=(fs // 2, 1)) # 0.5 sec x_m = matlab.double(x_py.tolist()) for feature in pyACA.getFeatureList(): self.logger.info('Testing feature:' + feature) v_out_py, t_py = pyACA.computeFeature(feature, x_py, fs) # Note: fs must be float when passing to Matlab v_out_m, t_m = self.matlab_engine.ComputeFeature(feature, x_m, float(fs), nargout=2) v_out_py = v_out_py.squeeze() v_out_m = np.asarray(v_out_m).squeeze() with self.subTest(msg=feature): npt.assert_almost_equal( v_out_py, v_out_m, decimal=7, err_msg="MATLAB crosscheck test failed for " + feature)
def test_compute_feature_num_blocks(self): blockLength = 256 # Using smaller blocksize to reduce time required to test (~7.3 sec) hopLength = 128 fs = 44100 inputData = np.random.uniform(-1, 1, size=(2 * blockLength, 1)) for inputSize in range(1, 2 * blockLength): x = inputData[:inputSize] expectedNumBlocks = self.calcNumBlocks(x.size + blockLength, blockLength, hopLength) for feature in pyACA.getFeatureList('all'): with self.subTest(msg=feature + ':' + str(inputSize)): out, t = pyACA.computeFeature(feature, x, fs, iBlockLength=blockLength, iHopLength=hopLength) npt.assert_equal(out.shape[-1], expectedNumBlocks)
def test_spectral_features_for_1d_input(self): fs = 44100 X = np.zeros(1025) features = pyACA.getFeatureList('spectral') features.remove('SpectralMfccs') features.remove('SpectralPitchChroma') for feature in features: with self.subTest(msg=feature): featureFunc = getattr(pyACA, "Feature" + feature) out = featureFunc(X, fs) npt.assert_equal(out.shape, ()) with self.subTest(msg='SpectralMfccs'): out = pyACA.FeatureSpectralMfccs(X, fs) npt.assert_equal(out.shape, (13, )) with self.subTest(msg='SpectralPitchChroma'): out = pyACA.FeatureSpectralPitchChroma(X, fs) npt.assert_equal(out.shape, (12, ))
def test_spectral_features_for_2d_input(self): fs = 44100 features = pyACA.getFeatureList('spectral') features.remove('SpectralMfccs') features.remove('SpectralPitchChroma') # Test for 2d input with only one block X = np.zeros((1025, 1)) for feature in features: with self.subTest(msg=feature): featureFunc = getattr(pyACA, "Feature" + feature) out = featureFunc(X, fs) npt.assert_equal(out.shape, (1, )) with self.subTest(msg='SpectralMfccs'): out = pyACA.FeatureSpectralMfccs(X, fs) npt.assert_equal(out.shape, (13, 1)) with self.subTest(msg='SpectralPitchChroma'): out = pyACA.FeatureSpectralPitchChroma(X, fs) npt.assert_equal(out.shape, (12, 1)) # Test for 2d input with only multiple block X = np.zeros((1025, 16)) for feature in features: with self.subTest(msg=feature): featureFunc = getattr(pyACA, "Feature" + feature) out = featureFunc(X, fs) npt.assert_equal(out.shape, (16, )) with self.subTest(msg='SpectralMfccs'): out = pyACA.FeatureSpectralMfccs(X, fs) npt.assert_equal(out.shape, (13, 16)) with self.subTest(msg='SpectralPitchChroma'): out = pyACA.FeatureSpectralPitchChroma(X, fs) npt.assert_equal(out.shape, (12, 16))