Esempio n. 1
0
 def test_zeros(self):
     sample_rate = 2000
     times = np.linspace(-0.5, 0.5, sample_rate)
     freqs = 0.0 * times
     expected = np.array([
         0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
         0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
         0.0, 0.0
     ])
     actual = utils.get_contour_shape_features(times, freqs, sample_rate)
     self.assertTrue(array_equal(expected, actual))
Esempio n. 2
0
 def test_line_with_vib(self):
     sample_rate = 2000
     times = np.linspace(-0.5, 0.5, sample_rate)
     freqs = (
         (1.2 * times + 440.0) + 7.3 * np.cos(2.0 * np.pi * 12.0 * times)
     )
     expected = np.array([
         12.0, 7.296015, 1.0, 1.0, 1.0, 1.0,
         440.139861, 1.2, -6.77396486e+00, 3.49420344e-12,
         3.42394991e+01, -1.48802985e-11,
         1.15390225e-01, 3.77435044e-03
     ])
     actual = utils.get_contour_shape_features(times, freqs, sample_rate)
     print(expected)
     print(actual)
     self.assertTrue(array_equal(expected, actual))
Esempio n. 3
0
    def get_feature_vector(self, times, freqs_hz, salience, sample_rate):
        """Get feature vector for a contour.

        Parameters
        ----------
        times : np.array
            Contour times
        freqs_hz : np.array
            Contour frequencies (Hz)
        salience : np.array
            Contour salience
        sample_rate : float
            Contour sample rate.

        Returns
        -------
        feature_vector : np.array
            Feature vector.

        """
        freqs_cents = utils.hz_to_cents(freqs_hz, ref_hz=self.ref_hz)

        features = [
            utils.get_contour_shape_features(
                times,
                freqs_cents,
                sample_rate,
                poly_degree=self.poly_degree,
                min_freq=self.min_freq,
                max_freq=self.max_freq,
                freq_step=self.freq_step,
                vibrato_threshold=self.vibrato_threshold),
            utils.get_polynomial_fit_features(times - np.mean(times),
                                              salience,
                                              n_deg=self.poly_degree,
                                              norm=False),
            utils.get_contour_duration(times),
            utils.get_std(freqs_cents),
            utils.get_range(freqs_cents),
            utils.get_total_variation(freqs_cents) / len(freqs_cents),
            utils.get_std(salience),
            utils.get_range(salience),
            utils.get_total_variation(salience) / len(freqs_cents)
        ]

        return np.concatenate(features)