MFCC

function [cepstra, aspectrum, pspectrum] = melfcc(samples, sr, wintime, steptime, nfilts, numcep, preemph)
% [cepstra, aspectrum, pspctrum] = melfcc(samples, sr, wintime, steptime, numcep, preemph)
%   - take power spectra of the STFT
%   - warp to a mel frequency scale
%   - take the DCT of the log-Mel-spectrum
%   - return the first <numcep> components
%   samples:                        vector of signal
%   sr:                                  sample rate
%   wintime (0.025):             window length in second
%   steptime (0.010):           step between successive windows in second
%   numcep (13):                 number of cepstra to return
%   nfilts (40):                       number of triangle filter to use
%   preemph (0.97):             pre-emphasis filter coefficient

if nargin < 2;      sr = 16000;               end
if nargin < 3;      wintime = 0.025;       end
if nargin < 4;      steptime = 0.010;     end
if nargin < 5;      numcep = 13;           end
if nargin < 6;      nfilts = 40;                end
if nargin < 7;      preemph = 0.97;       end

winpts = round(wintime*sr);
steppts = round(steptime*sr);
NFFT = 2^(ceil(log2(winpts)));

samples = filter([1, -preemph], 1, samples);

%   compute FFT power spectrum
%pspectrum = powspec(samples, sr, wintime, steptime, NFFT);
%pspectrum = abs(spectrogram(samples*32768, winpts, winpts - round(steptime*sr), NFFT)).^2;

[frame, tc] = enframe(samples, hamming(winpts), steppts);
pspectrum = abs(fft(frame', NFFT)).^2;

%   obtain mel filter bank
filterBank = melFilterBank(NFFT, sr, nfilts);

%   auditory spectrum
aspectrum = filterBank * pspectrum;

%   apply DCT to convert aspectrum to mel cepstrum
logAspec = log(aspectrum);
cepstra = dct(logAspec);
cepstra = cepstra(1:numcep,:);

if nargout < 1
    [nf, nc] = size(cepstra);
    imh = imagesc(tc/sr, 1:nf, cepstra);
    axis('xy');
    xlabel('Time (s)');
    ylabel('Mel-cepstrum coefficient');
    map = (0:63)' / 63;
    colormap([map, map, map]);
    colorbar;
end
end

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值