vad.m
上传用户:luvkyhj
上传日期:2013-06-25
资源大小:3k
文件大小:2k
- function [x1,x2]=vad(x)%端点检测子程序
- %幅度归一化到(-1,1)
- x=double(x);
- x=x/max(abs(x));
- FrameLen=160;
- FrameInc=80;
- amp1=10;
- amp2=2;
- zcr1=10;
- zcr2=5;
- ener1=0.1;
- ener2=0.05;
- maxsilence=3;
- minlen=15;
- status=0;
- count=0;
- silence=0;
- tmp1=enframe(x(1:length(x)-1),FrameLen,FrameInc);
- tmp2=enframe(x(2:length(x)),FrameLen,FrameInc);
- signs=(tmp1.*tmp2)<0;
- diffs=abs(tmp1-tmp2)>0.02;
- zcr=sum(signs.*diffs,2);
- amp=sum(abs(enframe(filter([1 -0.9375],1,x),FrameLen,FrameInc)),2);
- amp1=min(amp1,max(amp)/4);
- amp2=min(amp2,max(amp)/8);
- ener=sum((enframe(filter([1 -0.9375],1,x),FrameLen,FrameInc)).^2,2);
- ener1=min(ener1,max(ener)/8);
- x1=0;
- x2=0;
- for n=1:length(zcr)
- goto=0;
- switch status
- case{0,1}
- if amp(n)>amp1
- x1=max(n-count-1,1);
- status=2;
- silence=0;
- count=count+1;
- elseif amp(n)>amp2 | zcr(n)>zcr2|ener(n)>ener2
- status=1;
- count=count+1;
- else
- status=0;
- count=0;
- end
- case 2,
- if amp(n)>amp2 | zcr(n)>zcr2|ener(n)>ener2
- count=count+1;
- else
- silence=silence+1;
- if silence<maxsilence
- count=count+1;
- elseif count<minlen
- status=0;
- silence=0;
- count=0;
- else
- status=3;
- end
- end
- case 3,
- break;
- end
- end
- count=count-silence/2;
- x2=x1+count-1;
- subplot(313)
- plot(x);
- axis([1 length(x)/2 -1 1])
- ylabel('speech');
- xlabel('time');
- line([x1*FrameInc x1*FrameInc],[-1 1],'Color','red');
- line([x2*FrameInc x2*FrameInc],[-1 1],'Color','red');
- %subplot(412)
- %plot(amp)
- %axis([1 length(amp) 0 max(amp)])
- %ylabel('Amplitude');
- %xlabel('帧');
- %line([x1 x1],[min(amp),max(amp)],'Color','red');
- %line([x2 x2],[min(amp),max(amp)],'Color','red');
- %subplot(413)
- %plot(ener)
- %axis([1 length(ener) 0 max(ener)])
- %ylabel('Energy');
- %xlabel('帧');
- %line([x1 x1],[min(ener),max(ener)],'Color','red');
- %line([x2 x2],[min(ener),max(ener)],'Color','red');
- %subplot(414)
- %plot(zcr)
- %axis([1 length(zcr) 0 max(zcr)])
- %ylabel('ZCR');
- %xlabel('帧');
- %line([x1 x1],[min(zcr),max(zcr)],'Color','red');
- %line([x2 x2],[min(zcr),max(zcr)],'Color','red');