[x]=wavread('song1.wav');
x=x/max(abs(x));
figure;
subplot(3,1,1);
plot(x);
axis([1 length(x) -1 1]);
ylabel('Speech');
FrameLen=240;
FrameInc=80;
yframe=enframe(x,FrameLen,FrameInc);
amp1=sum(abs(yframe),2);
subplot(3,1,2);
plot(amp1);
axis([1 length(amp1) 0 max(amp1)]);
ylabel('Amplitude');
legend('amp1=∑│x│');
amp2=sum(abs(yframe.*yframe),2);
subplot(3,1,3);
plot(amp2);
axis([1 length(amp2) 0 max(amp2)]);
ylabel('Energy');
legend('amp1=∑│x*x│');
短时过零率matlab实现:
[x]=wavread('song1.wav');
figure;
subplot(3,1,1);
plot(x);
axis([1 length(x) -1 1]);
ylabel('Speech');
FrameLen = 240;
FrameInc = 80;
amp = sum(abs(enframe(filter([1 -0.9375], 1, x), FrameLen, FrameInc)), 2);
subplot(312)
plot(amp);
axis([1 length(amp) 0 max(amp)])
ylabel('Energy');
tmp1 = enframe(x(1:end-1), FrameLen, FrameInc);
tmp2 = enframe(x(2:end) , FrameLen, FrameInc);
signs = (tmp1.*tmp2)<0;
diffs = (tmp1 -tmp2)>0.02;
zcr = sum(signs.*diffs, 2);
subplot(3,1,3);
plot(zcr);
axis([1 length(zcr) 0 max(zcr)])
ylabel('ZCR');
语音信号的端点检测matlab实现:
[x,fs,nbits]=wavread('song1.wav');
x = x / max(abs(x));%幅度归一化到[-1,1]
%参数设置
FrameLen = 256; %帧长
inc = 90; %未重叠部分
amp1 = 10; %短时能量阈值
amp2 = 2;
zcr1 = 10; %过零率阈值
zcr2 = 5;
minsilence = 6; %用无声的长度来判断语音是否结束
minlen = 15; %判断是语音的最小长度
status = 0; %记录语音段的状态
count = 0; %语音序列的长度
silence = 0; %无声的长度
%计算过零率
tmp1 = enframe(x(1:end-1), FrameLen,inc);
tmp2 = enframe(x(2:end) , FrameLen,inc);
signs = (tmp1.*tmp2)<0;
diffs = (tmp1 -tmp2)>0.02;
zcr = sum(signs.*diffs,2);
%计算短时能量
amp = sum((abs(enframe(filter([1 -0.9375], 1, x), FrameLen, inc))).^2, 2);
%调整能量门限
amp1 = min(amp1, max(amp)/4);
amp2 = min(amp2, max(amp)/8);
%开始端点检测
for n=1:length(zcr)
goto = 0;
switch status
case {0,1} % 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 % 可能处于语音段
status = 1;
count = count + 1;
else % 静音状态
status = 0;
count = 0;
end
case 2, % 2 = 语音段
if amp(n) > amp2 ||zcr(n) > zcr2 % 保持在语音段
count = count + 1;
else % 语音将结束
silence = silence+1;
if silence < minsilence % 静音还不够长,尚未结束
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(3,1,1)
plot(x)
axis([1 length(x) -1 1])
ylabel('Speech');
line([x1*inc x1*inc], [-1 1], 'Color', 'red');
line([x2*inc x2*inc], [-1 1], 'Color', 'red');
subplot(3,1,2)
plot(amp);
axis([1 length(amp) 0 max(amp)])
ylabel('Energy');
line([x1 x1], [min(amp),max(amp)], 'Color', 'red');
line([x2 x2], [min(amp),max(amp)], 'Color', 'red');
subplot(3,1,3)
plot(zcr);
axis([1 length(zcr) 0 max(zcr)])
ylabel('ZCR');
line([x1 x1], [min(zcr),max(zcr)], 'Color', 'red');
line([x2 x2], [min(zcr),max(zcr)], 'Color', 'red');