mfcc_spectrogram

Function mfcc_spectrogram 

Source
pub fn mfcc_spectrogram(
    mel_spectrogram: &[Vec<f64>],
    num_mfccs: usize,
    lifter: Option<f64>,
) -> Vec<Vec<f64>>
Expand description

Derives the Mel frequency cepstral coefficients (MFCCs) given a Mel spectrum.

If you provide a lifter value, liftering will be applied to the MFCCs (this approach is borrowed from librosa: https://librosa.org/doc/main/generated/librosa.feature.mfcc.html).

The MFCCs are derived by converting the Mel spectrum to a log Mel spectrum, then applying the Discrete Cosine Transform Type II. Liftering is optional.

ยงExample

This example covers the entire process for calculating the MFCCs from a FFT frame.

use aus::{spectrum, analysis};
let fft_size = 2048;
let audio = aus::read("myfile.wav").unwrap();
let rfft_freqs = spectrum::rfftfreq(fft_size, audio.sample_rate);
let mel_filterbank = analysis::mel::MelFilterbank::new(20.0, 8000.0, 40, &rfft_freqs, true);
let imaginary_spectrogram = spectrum::rstft(&audio.samples[0], fft_size, fft_size / 2, aus::WindowType::Hanning);
let (magnitude_spectrogram, _) = spectrum::complex_to_polar_rstft(&imaginary_spectrogram);
let power_spectrogram = analysis::make_power_spectrogram(&magnitude_spectrogram);
let mel_spectrogram = analysis::mel::make_mel_spectrogram(&power_spectrogram, &mel_filterbank);
let mfccs = analysis::mel::mfcc_spectrogram(&mel_spectrogram, 20, Some(2.0));