已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
附录2:训练函数:train.mdisp(正在生成训练参数);for i=1:20 fname=sprintf(train%d0.wav,i); k,fs=audioread(fname); StartPoint,EndPoint=vad_m(k,fs); cc=mfcc(k); cc=cc(StartPoint-2:EndPoint-2,:); ref(i+1).StartPoint=StartPoint; ref(i+1).EndPoint=EndPoint; ref(i+1).mfcc=cc;enddisp(正在存储模板库);save mfcc.mat ref;disp(存储完毕)附录3:测试函数:dtwtest.mclear;close all;clc;disp(正在导入参考模板参数.);load mfcc.mat;disp(正在计算测试模板的参数.)for i=0:3fname = sprintf(test%d1.wav,i); k,fs=audioread(fname); StartPoint,EndPoint=vad_m(k,fs); cc=mfcc(k); cc=cc(StartPoint-2:EndPoint-2,:); test(i+1).StartPoint=StartPoint; test(i+1).EndPoint=EndPoint; test(i+1).mfcc=cc;enddisp(正在进行模板匹配.)dist = zeros(1,20);for i=1:4 for j=1:20 dist(i,j) = dtw(test(i).mfcc, ref(j).mfcc); endenddisp(正在计算匹配结果.)for i=1:4d,j = min(dist(i,:); if (j=1 & j= 6 & j=11 & j=16 & j=20) fprintf(测试模板%d1.wav 的识别结果为:右转n,i-1); endendclose all;附录4:特征提取函数:vad_m.mfunction StartPoint,EndPoint=vad(k,fs)% StartPoint,EndPoint=vad(k,fs)% 语音信号端点检测程序,k为语音信号,% fs为其采样频率,程序绘制出语音信号% 相关波形图并返回起止端点所对帧号 close all% 幅度归一化到-1,1k=double(k);k=k./max(abs(k);%-% 显示波形%-SNR=5; % 设置SNRsignal=Gnoisegen(k,SNR); % 叠加噪声snr1=SNR_singlech(k,signal); % 计算叠加噪声后的信噪比N=length(k); % 信号长度t=(0:N-1)/fs; % 设置时间IS=.25; % 设置IS% 调用WienerScalart96m_2函数做维纳滤波output=WienerScalart96m_2(signal,fs,IS,0.12);ol=length(output); % 把output补到与x等长if olN output=output; zeros(N-ol,1);endsnr2=SNR_singlech(k,output); % 计算维纳滤波后的信噪比snr=snr2-snr1;fprintf(snr1=%5.4f snr2=%5.4f snr=%5.4fn,snr1,snr2,snr);subplot 311; plot(t,k,k); grid; axis tight;title(纯语音波形); ylabel(幅值)subplot 312; plot(t,signal,k); grid; axis tight;title(带噪语音 信噪比= num2str(SNR) dB); ylabel(幅值)subplot 313; plot(t,output,k);grid; ylim(-1 1);title(维纳滤波后波形); ylabel(幅值); xlabel(时间/s);disp(显示原始波形图);t=0:1/fs:(length(k)-1)/fs;% subplot(3,1,1);plot(t,k);axis(0,(length(k)-1)/fs,min(k),max(k);title(语音信号波形);xlabel(Time:s);ylabel(Amplitude(normalized);disp(显示语音起始处放大波形图);t1=0.2:1/fs:0.3;k1=k(0.2*fs:0.3*fs);subplot(3,1,2);plot(t1,k1);axis(0.2,0.3,min(k),max(k);title(II) “00.wav”语音起始处放大波形图);xlabel(Time:s);ylabel(Amplitude(normalized);disp(显示语音结束处放大波形图);t1=0.4:1/fs:0.5;k1=k(0.4*fs:0.5*fs);subplot(3,1,3);plot(t1,k1);axis(0.4,0.5,min(k),max(k);title(III) “00.wav”语音结束处放大波形图);xlabel(Time:s);ylabel(Amplitude(normalized);%-% 计算短时过零率%-k=output;FrameLen=240;FrameInc=80;FrameTemp1=enframe(k(1:end-1),FrameLen,FrameInc);FrameTemp2=enframe(k(2:end),FrameLen,FrameInc);signs=(FrameTemp1.*FrameTemp2)0.01;zcr=sum(signs.*diffs,2);zcrm=multimidfilter(zcr,5);disp(显示原始波形图);figure,subplot(3,1,1);plot(t,k);axis(0,(length(k)-1)/fs,min(k),max(k);title(I) 语音信号波形);xlabel(Time:s);ylabel(Amplitude(normalized);disp(显示短时过零率)zcrInd=1:length(zcrm);subplot(3,1,2);plot(zcrInd,zcr);axis(0,length(zcr),0,max(zcr);title(II) 短时过零率);xlabel(Frame);ylabel(Zcr);%-% 计算短时能量%-amp=sum(abs(enframe(filter(1 -0.9375, 1, k), FrameLen, FrameInc), 2);ampm=multimidfilter(amp,5);disp(显示短时能量)ampInd=1:length(ampm);subplot(3,1,3);plot(ampInd,amp);axis(0,length(amp),0,max(amp);title(III) 短时能量);xlabel(Frame);ylabel(Energy);% -% 设置门限%-disp(设置门限);ZcrLow=max(round(mean(zcr)*0.1),3); %过零率低门限ZcrHigh=max(round(max(zcr)*0.1),5); %过零率高门限AmpLow=min(min(amp)*10,mean(amp)*0.2,max(amp)*0.1); %能量低门限AmpHigh=max(min(amp)*10,mean(amp)*0.2,max(amp)*0.1); %能量高门限%-% 端点检测%-MaxSilence=30; %最长语音间隙时间MinAudio=15; %最短语音时间Status=0; %状态:0静音段,1过渡段,2语音段,3结束段HoldTime=0; %语音持续时间SilenceTime=0; %语音间隙时间disp(开始端点检测);for n=1:length(zcr) switch Status case0,1 if amp(n)AmpHigh | zcr(n)ZcrHigh StartPoint=n-HoldTime; Status=2; HoldTime=HoldTime+1; SilenceTime=0; elseif amp(n)AmpLow | zcr(n)ZcrLow Status=1; HoldTime=HoldTime+1; else Status=0; HoldTime=0; end case 2, if amp(n)AmpLow | zcr(n)ZcrLow HoldTime=HoldTime+1; else SilenceTime=SilenceTime+1; if SilenceTimeMaxSilence HoldTime=HoldTime+1; elseif (HoldTime-SilenceTime)MinAudio Status=0; HoldTime=0; SilenceTime=0; else Status=3; end end case 3, break; end if Status=3 break; endendHoldTime =HoldTime-SilenceTime;EndPoint=StartPoint+HoldTime;disp(显示端点);figure,subplot(3,1,1);plot(k);axis(1,length(k),min(k),max(k);title(I) 语音信号);xlabel(Sample);ylabel(Speech);line(StartPoint*FrameInc,StartPoint*FrameInc,min(k),max(k),color,red);line(EndPoint*FrameInc,EndPoint*FrameInc,min(k),max(k),color,red);subplot(3,1,2);plot(zcr);axis(1,length(zcr),0,max(zcr);title(II) 短时过零率);xlabel(Frame);ylabel(ZCR);line(StartPoint,StartPoint,0,max(zcr),Color,red);line(EndPoint,EndPoint,0,max(zcr),Color,red);subplot(3,1,3);plot(amp);axis(1,length(amp),0,max(amp);title(III) 短时能量);xlabel(Frame);ylabel(Energy);line(StartPoint,StartPoint,0,max(amp),Color,red);line(EndPoint,EndPoint,0,max(amp),Color,red);附录5:DTW算法function dist = dtw(test, ref)global x y_min y_maxglobal t rglobal D dglobal m nt = test;r = ref;n = size(t,1);m = size(r,1);d = zeros(m,1);D = ones(m,1) * realmax;D(1) = 0;% 如果两个模板长度相差过多,匹配失败if (2*m-n3) | (2*n-mxa%xbxa, 按下面三个区域匹配% 1 :xa% xa+1:xb% xb+1:Nfor x = 1:xay_max = 2*x;y_min = round(0.5*x);warpendfor x = (xa+1):xby_max = round(0.5*(x-n)+m);y_min = round(0.5*x);warpendfor x = (xb+1):ny_max = round(0.5*(x-n)+m);y_min = round(2*(x-n)+m);warpendelseif xaxb%xaxb, 按下面三个区域匹配% 0 :xb% xb+1:xa% xa+1:Nfor x = 1:xby_max = 2*x;y_min = round(0.5*x);warpendfor x = (xb+1):xay_max = 2*x;y_min = round(2*(x-n)+m);warpendfor x = (xa+1):ny_max = round(0.5*(x-n)+m);y_min = round(2*(x-n)+m);warpendelseif xa=xb%xa=xb, 按下面两个区域匹配% 0 :xa% xa+1:Nfor x = 1:xay_max = 2*x;y_min = round(0.5*x);warpendfor x = (xa+1):ny_max = round(0.5*(x-n)+
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 双方超市转让合同协议
- 公司转让合同解除协议
- 加盟合同终止协议模板
- 区域承包协议合同范本
- 农民工怎样签协议合同
- 合开服装店合同协议书
- 合同名称变更补充协议
- 可转租的店面合同范本
- 古建砖瓦出售合同范本
- 加盟合同弄成合作协议
- 油浸式变压器电抗器检修检查与处理规范
- 英语FCE语用词汇-必备词缀
- 写字楼物业服务投标方案
- 蒋廷黻中国近代史
- 组团儿上春晚《八戒返乡》小品台词
- 河津市兴耿福利煤化有限公司煤焦油项目环境影响报告书
- 湖北省荆州市《公共基础知识》国考招聘考试真题含答案
- 腰椎退行性疾病课件
- 幼儿园小班社会:《红绿灯》 课件
- ISO 31000-2018 风险管理标准-中文版
- 六年级班会 我的理想职业课件
评论
0/150
提交评论