How to compute mffc
2 views (last 30 days)
Show older comments
Kamil Kacer
on 17 Nov 2020
Answered: Walter Roberson
on 17 Nov 2020
Hi i have a problem with computation of mfcc
I have function feature_mfccs which needs mfccParams which i cumputed as a stuct but idk what windowFFT is. I tried function getDFT but iam really confused how to pass it into function feature_mfccs.
I tried to train a whole dataset based on only mfccs features but iam confused about the process a bit can anyone help please ?
function [FFT, Freq] = getDFT(signal, Fs, PLOT)
%
% function [FFT, Freq] = getDFT(signal, Fs, PLOT)
%
% This function returns the DFT of a discrete signal and the
% respective frequency range.
%
% ARGUMENTS:
% - signal: vector containing the samples of the signal
% - Fs: the sampling frequency
% - PLOT: use this argument if the FFT (and the respective
% frequency values) need to be returned in the
% [-fs/2..fs/2] range. Otherwise, only half of
% the spectrum is returned.
%
% RETURNS:
% - FFT: the magnitude of the DFT coefficients
% - Freq: the corresponding frequencies (in Hz)
%
N = length(signal); % length of signal
% compute the magnitude of the spectrum
% (and normalize by the number of samples):
FFT = abs(fft(signal)) / N;
if nargin==2 % return the first half of the spectrum:
FFT = FFT(1:ceil(N/2));
Freq = (Fs/2) * (1:ceil(N/2)) / ceil(N/2); % define the frequency axis
else
if (nargin==3)
% ... or return the whole spectrum
% (in the range -fs/2 to fs/2)
FFT = fftshift(FFT);
if mod(N,2)==0 % define the frequency axis:
Freq = -N/2:N/2-1; % if N is even
else
Freq = -(N-1)/2:(N-1)/2; % if N is odd
end
Freq = (Fs/2) * Freq ./ ceil(N/2);
end
end
function ceps = feature_mfccs(windowFFT, mfccParams)
% This function computes the mfccs using the provided DFT.
% The parameters (DCT, filter banks, etc) need to have been
% computed using the feature_mfccs_init function.
%
% ARGUMENTS:
% - windowFFT: the abs(FFT) of an audio frame
% (computed by getDFT() function)
% - mfccParams: algorithm parameters, as returned
% by feature_mfccs_init()
%
% RETURNS:
% -ceps: MFCC matrix (row i corresponds to
% the i-th MFCC feature sequence)
%
% Based on Slaneys' Auditory Toolbox
% https://engineering.purdue.edu/~malcolm/interval/1998-010/
earMag = log10(mfccParams.mfccFilterWeights * windowFFT+eps);
ceps = mfccParams.mfccDCTMatrix * earMag;
0 Comments
Accepted Answer
Walter Roberson
on 17 Nov 2020
[signal, Fs] = audioread('YourFile.wav');
PLOT = true;
[windowFFT, Freq] = getDFT(signal, Fs, PLOT);
mfccParams = feature_mfccs_init();
ceps = feature_mfccs(windowFFT, mfccParams);
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!