functionr =mfcc(s, fs)% MFCC参数提取% Reference: 论文《MFCC和LPCC特征参数在说话人识别中的研究》%% Inputs: s contains the signal to analize% fs is the sampling rate of the signal%% Output: r contains the transformed signal%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%n=256;% 帧长m=100;% 帧移l=length(s);% 信号总长度nbFrame=floor((l-n)/m)+1;% 信号总帧数fori=1:nforj=1:nbFrameM(i,j)=s(((j-1)m)+i);% 分帧endendh=hamming(n);% Hamming窗w = 0.54 - 0.46cos(2pix);M2=diag(h)M;% 对M加窗,形成对角矩阵M2fori=1:nbFrameframe(:,i)=fft(M2(:,i));% 进行快速傅里叶变换,将其转换到频域上endt=n/2;% tmax = l / fs;m=melfb(20,n,fs);% 调用20阶MEL滤波器组进行滤波n2=1+floor(t);z=mabs(frame(1:n2,:)).^2;% 取前n2行帧列向量的平方r=dct(log(z));% 取对数后进行反余弦变换%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%functionm =melfb(p, n, fs)% MELFB Determine matrix for a mel-spaced filterbank%% Inputs: p number of filters in filterbank% n length of fft% fs sample rate in Hz%% Outputs: x a (sparse) matrix containing the filterbank amplitudes% size(x) = [p, 1+floor(n/2)]%% Usage: For example, to compute the mel-scale spectrum of a% colum-vector signal s, with length n and sample rate fs:% f = fft(s);% m = melfb(p, n, fs);% n2 = 1 + floor(n/2);% z = m * abs(f(1:n2)).^2;%% z would contain p samples of the desired mel-scale spectrum%% To plot filterbanks e.g.:% plot(linspace(0, (12500/2), 129), melfb(20, 256, 12500)'),% title('Mel-spaced filterbank'), xlabel('Frequency (Hz)');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%f0=700/fs;fn2=floor(n/2);lr=log(1+0.5/f0)/(p+1);% convert to fft bin numbers with 0 for DC termbl=n(f0(exp([01pp+1]lr)-1));b1=floor(bl(1))+1;b2=ceil(bl(2));b3=floor(bl(3));b4=min(fn2,ceil(bl(4)))-1;pf=log(1+(b1:b4)/n/f0)/lr;fp=floor(pf);pm=pf-fp;r=[fp(b2:b4)1+fp(1:b3)];c=[b2:b41:b3]+1;v=2[1-pm(b2:b4)pm(1:b3)];m=sparse(r,c,v,p,1+fn2);