Exemple #1
0
 def test_spectral_entropy(self):
     spectral_entropy(RANDOM_TS, SF_TS, method='fft')
     spectral_entropy(RANDOM_TS, SF_TS, method='welch')
     spectral_entropy(RANDOM_TS, SF_TS, method='welch', nperseg=400)
     self.assertEqual(np.round(spectral_entropy(RANDOM_TS, SF_TS,
                                                normalize=True), 1), 0.9)
     self.assertEqual(np.round(spectral_entropy(PURE_SINE, 100), 2), 0.0)
     # 2D data
     params = dict(sf=SF_TS, normalize=True, method='welch', nperseg=100)
     assert_equal(aal(spectral_entropy, axis=1, arr=data, **params),
                  spectral_entropy(data, **params))
def compute_entropy_phase(score, ver_ratio=0.2, aw_size=4):
    arr1 = produce_pitch_class_matrix_from_filename(score, aw_size=aw_size)
    utm = np.round(np.angle(apply_dft_to_pitch_class_matrix(arr1)), 2)
    vec = []
    coeffs = []
    height = int(utm.shape[0] * ver_ratio) - 1
    sel = np.array(utm[height, :, :]).T
    entr = ent.spectral_entropy(sel, 1, method='fft')
    return entr[1:]
def compute_magnitude_entropy(score,
                              ver_ratio=0.2,
                              hor_ratio=(0, 1),
                              aw_size=4):
    arr1 = produce_pitch_class_matrix_from_filename(score, aw_size=aw_size)
    utm = np.abs(apply_dft_to_pitch_class_matrix(arr1))
    vec = []
    for i in range(7):
        vec.append(utm[int(utm.shape[0] * ver_ratio) - 1, :,
                       i][utm[int(utm.shape[0] * ver_ratio) - 1, :, i] != 0])
    sel = np.array([
        ve[int(utm.shape[1] * hor_ratio[0]):int(utm.shape[1] * hor_ratio[1])]
        for ve in vec
    ])
    entr = ent.spectral_entropy(sel, 1, method='fft')
    return entr[1:]
Exemple #4
0
def create_database(
        path_data="C:/Users/kb39309/Documents/Studia/Vovel_sounds/src/vowels_dataset/*",
        path_csv="data.csv"):
    """ Funkcja pozyskująca cechy z próbek dźwiękowych do ramki danych (Pandas).

    :param path_data: Ścieżka do plików dźwiękowych (glob)
    :param path_csv: Ścieżka do zapisu ramki danych z rozszerzeniem .csv
    :return: Ramka danych (pandas.DataFrame)
    """
    filenames = glob.glob(path_data)

    df = pd.DataFrame(columns=[
        "vowel", "sex", "f0", "form1", "form2", "form3", "form4", "spc1",
        "spc2", "spc3", "entrspc"
    ])

    for fname in filenames:

        input, fs = get_signal(fname, fs=10000)

        f0 = get_base_freq(input, fs)
        formants = get_formants(input, fs)
        spc = get_spectral_centroids(input, fs)
        spcent = ant.spectral_entropy(input, sf=fs, method='welch')

        df = df.append(
            {
                'vowel': os.path.basename(fname)[2],
                "sex": 1 if 'f' in fname else 0,
                "f0": f0,
                "form1": formants[0],
                "form2": formants[1],
                "form3": formants[2],
                "form4": formants[3],
                "spc1": spc[0],
                "spc2": spc[1],
                "spc3": spc[2],
                "entrspc": spcent
            },
            ignore_index=True)
    df.to_csv(path_csv)
    return df