clc
clear
%----------MFCC及其差分为特征参数的参考模板------------------------
disp('正在计算参考模板的参数....')
for i = 1:5
fname = sprintf('d:\\matlab6p5\\work\\single\\number\\A\\%d.wav',i);
%fname = sprintf('d:\\matlab6p5\\work\\sound\\unsime\\11\\%d.wav',i);
x = wavread(fname);
%小波消噪
[C,L] = wavedec(x,3,'db4');
[thr,sorh,keepapp] = ddencmp('den','wv',x);
de_noise = wdencmp('gbl',C,L,'db4',3,thr,sorh,keepapp);
x = de_noise;
%x = wden(x,'heursure','s','one',1,'sym8');%进行消噪处理
m = mfcc(x);%提取mel倒谱参数
%m = lpcmc(x);
%t = Pit(x);
%n = lpcc(x);
%w = [m n];
%z = [m t];
ref1(i).mfcc = m;%存储MFCC参数
end
%----------MFCC及其差分为特征参数的参考模板------------------------
disp('正在计算参考模板的参数....')
for i = 1:5
fname = sprintf('d:\\matlab6p5\\work\\single\\number\\A\\%d.wav',i);
%fname = sprintf('d:\\matlab6p5\\work\\sound\\unsime\\11\\%d.wav',i);
x = wavread(fname);
%小波消噪
[C,L] = wavedec(x,3,'db4');
[thr,sorh,keepapp] = ddencmp('den','wv',x);
de_noise = wdencmp('gbl',C,L,'db4',3,thr,sorh,keepapp);
x = de_noise;
%x = wden(x,'heursure','s','one',1,'sym8');%进行消噪处理
%m = mfcc(x);%提取mel倒谱参数
%m = lpcmc(x);
%t = Pit(x);
n = lpcc(x);
%w = [m n];
%z = [m t];
ref2(i).lpcc = n;%存储MFCC参数
end
%----------------MFCC及其差分为特征参数的测试模板---------------------------
disp('正在计算测试模板的参数....')
for i = 1:1
fname = sprintf('d:\\matlab6p5\\work\\single\\number\\E\\%d.wav',i);
%fname = sprintf('d:\\matlab6p5\\work\\sound\\unsime\\12\\%d.wav',i);
x = wavread(fname);
%小波消噪
[C,L] = wavedec(x,3,'db4');
[thr,sorh,keepapp] = ddencmp('den','wv',x);
de_noise = wdencmp('gbl',C,L,'db4',3,thr,sorh,keepapp);
x = de_noise;
%x = wden(x,'heursure','s','one',1,'sym8');%进行消噪处理
m = mfcc(x);%提取mel倒谱参数
%m =lpcmc(x);
%t = Pit(x);
%n = lpcc(x);
%w = [m n];
%z = [m,t];
test1(i).mfcc = m;%存储MFCC参数
end
%----------------LPCC及其差分为特征参数的测试模板---------------------------
disp('正在计算测试模板的参数....')
for i = 1:1
fname = sprintf('d:\\matlab6p5\\work\\single\\number\\E\\%d.wav',i);
%fname = sprintf('d:\\matlab6p5\\work\\sound\\unsime\\12\\%d.wav',i);
x = wavread(fname);
%小波消噪
[C,L] = wavedec(x,3,'db4');
[thr,sorh,keepapp] = ddencmp('den','wv',x);
de_noise = wdencmp('gbl',C,L,'db4',3,thr,sorh,keepapp);
x = de_noise;
%x = wden(x,'heursure','s','one',1,'sym8');%进行消噪处理
%m = mfcc(x);%提取mel倒谱参数
%m =lpcmc(x);
%t = Pit(x);
n = lpcc(x);
%w = [m n];
%z = [m,t];
test2(i).lpcc = n;%存储MFCC参数
end
%---------------------MFCC参考模板和测试模板用DTW算法的模板匹配----------------------
disp('正在进行模板匹配....')
dist = zeros(1,5);
for i = 1:1
for j = 1:5
dist1(i,j) = dtw(test1(i).mfcc,ref1(j).mfcc);
dist2(i,j) = dtw(test2(i).lpcc,ref2(j).lpcc);
end
end
disp('正在计算匹配结果...');
for i = 1:1
[d1,j1] = min(dist1(i,:));
[d2,j2] = min(dist2(i,:));
if j1==j2
fprintf('测试模板%d的识别结果为:%d\n',i,j);
else
fprintf('测试模板%d的语音为非法人员',i);
end
end