Compute the Mel-frequency cepstral coefficients (MFCC) for a signal. Notes ----- Computing MFCC features proceeds in the following stages: 1. Convert the signal into overlapping frames and apply a window fn 2. Compute the power spectrum at each frame 3. App
(
x,
fs=44000,
n_mfccs=13,
alpha=0.95,
center=True,
n_filters=20,
window="hann",
normalize=True,
lifter_coef=22,
stride_duration=0.01,
window_duration=0.025,
replace_intercept=True,
)
| 611 | |
| 612 | |
| 613 | def mfcc( |
| 614 | x, |
| 615 | fs=44000, |
| 616 | n_mfccs=13, |
| 617 | alpha=0.95, |
| 618 | center=True, |
| 619 | n_filters=20, |
| 620 | window="hann", |
| 621 | normalize=True, |
| 622 | lifter_coef=22, |
| 623 | stride_duration=0.01, |
| 624 | window_duration=0.025, |
| 625 | replace_intercept=True, |
| 626 | ): |
| 627 | """ |
| 628 | Compute the Mel-frequency cepstral coefficients (MFCC) for a signal. |
| 629 | |
| 630 | Notes |
| 631 | ----- |
| 632 | Computing MFCC features proceeds in the following stages: |
| 633 | |
| 634 | 1. Convert the signal into overlapping frames and apply a window fn |
| 635 | 2. Compute the power spectrum at each frame |
| 636 | 3. Apply the mel filterbank to the power spectra to get mel filterbank powers |
| 637 | 4. Take the logarithm of the mel filterbank powers at each frame |
| 638 | 5. Take the discrete cosine transform (DCT) of the log filterbank |
| 639 | energies and retain only the first k coefficients to further reduce |
| 640 | the dimensionality |
| 641 | |
| 642 | MFCCs were developed in the context of HMM-GMM automatic speech recognition |
| 643 | (ASR) systems and can be used to provide a somewhat speaker/pitch |
| 644 | invariant representation of phonemes. |
| 645 | |
| 646 | Parameters |
| 647 | ---------- |
| 648 | x : :py:class:`ndarray <numpy.ndarray>` of shape `(N,)` |
| 649 | A 1D signal consisting of N samples |
| 650 | fs : int |
| 651 | The sample rate/frequency for the signal. Default is 44000. |
| 652 | n_mfccs : int |
| 653 | The number of cepstral coefficients to return (including the intercept |
| 654 | coefficient). Default is 13. |
| 655 | alpha : float in [0, 1) |
| 656 | The preemphasis coefficient. A value of 0 corresponds to no |
| 657 | filtering. Default is 0.95. |
| 658 | center : bool |
| 659 | Whether to the kth frame of the signal should *begin* at index ``x[k * |
| 660 | stride_len]`` (center = False) or be *centered* at ``x[k * stride_len]`` |
| 661 | (center = True). Default is True. |
| 662 | n_filters : int |
| 663 | The number of filters to include in the Mel filterbank. Default is 20. |
| 664 | normalize : bool |
| 665 | Whether to mean-normalize the MFCC values. Default is True. |
| 666 | lifter_coef : int in :math:[0, + \infty]` |
| 667 | The cepstral filter coefficient. 0 corresponds to no filtering, larger |
| 668 | values correspond to greater amounts of smoothing. Default is 22. |
| 669 | window : {'hamming', 'hann', 'blackman_harris'} |
| 670 | The windowing function to apply to the signal before taking the DFT. |