clear all
for h=1:30
fname=sprintf('D:\\study\\音频采样\\music22050hz\\%d.wav',h);
x=wavread(fname);
x=x(:,1);
[c,l]=wavedec(x,3,'db4');
ca=appcoef(c,l,'db4',3);%近似系数
x=ca;
enframex=enframe(x,128,64);%对信号x分帧处理,每帧有128个采样点,相邻帧之间有50%的叠加率
[row,col]=size(enframex);%返回行,列,每一行代表一帧,每一列表示1到128个采样点
framelen=col;
frameinc=64;
hang=row;%计算出分帧后语音矩阵的行数
temp1=enframe(x,framelen,frameinc);%将分帧后的数据存入temp1数组矩阵
for i=1:hang;
j=1:frameinc;
z(i)=max(temp1(i,j));%求第i帧前frameinc个元素最大值并存入z(i)数组中
end
for i=1:hang;
j=framelen-frameinc:framelen;
a(i)=max(temp1(i,j));
end
i=1:hang;
c(i)=min(z(i),a(i))*0.68;%计算每帧的门限值
for i=1:hang;
for j=1:framelen;
if temp1(i,j)>c(i)
y(i,j)=temp1(i,j)-c(i);
else if abs(temp1(i,j)) y(i,j)=0;
else if temp1(i,j) y(i,j)=temp1(i,j)+c(i);
end
end
end
end
end
for i=1:hang;
if (j>=0)&(j y(i,j)=0;
end
end %将0到20点置零
for i=1:hang;
for j=framelen:450;
y(i,j)=0; %将framelen点到450点的值置零
end
end
for i=1:hang;
for j=1:framelen;
if y(i,j)>0
y1(i,j)=1;
else if y(i,j)==0;
y1(i,j)=0;
else if y(i,j) y1(i,j)=-1;
end
end
end
end
end
for i=1:hang;
if (j>=0)&(j y1(i,j)=0;
end
end %将0到20点置零
for i=1:hang;
for j=framelen:450;
y1(i,j)=0; %将framelen点到450点的值置零
end
end
for i=1:hang;
for k=1:128;
n=21:framelen;
R(i,k)=sum(y(i,n).*y1(i,n+k));
end
end
%计算每一帧y与y1的互相关值
for i=1:hang;
k=20:128;
Rmax(i)=max(R(i,k));%计算每帧的Rmax值
end
for i=1:hang;
k=20:128;
[r,kmax(i)]=max(R(i,k));%找出每帧Rmax对应的k值kmax
end
for i=1:hang;
if Rmax(i) P(i)=0;
else P(i)=kmax(i);
end
end
music(h)=0;
for i=1:hang-1;
if P(i)==P(i+1)
music(h)=music(h)+1;
end
end
musicbi(1,h)=music(h)/hang;
end
musicbi
clear all
for h=1:30
fname=sprintf('D:\\study\\音频采样\\speech22050hz\\%d.wav',h);
x=wavread(fname);
x=x(:,1);
[c,l]=wavedec(x,3,'db4');
ca=appcoef(c,l,'db4',3);%近似系数
x=ca;
enframex=enframe(x,128,64);%对信号x分帧处理,每帧有128个采样点,相邻帧之间有50%的叠加率
[row,col]=size(enframex);%返回行,列,每一行代表一帧,每一列表示1到128个采样点
framelen=col;
frameinc=64;
hang=row;%计算出分帧后语音矩阵的行数
temp1=enframe(x,framelen,frameinc);%将分帧后的数据存入temp1数组矩阵
for i=1:hang;
j=1:frameinc;
z(i)=max(temp1(i,j));%求第i帧前frameinc个元素最大值并存入z(i)数组中
end
for i=1:hang;
j=framelen-frameinc:framelen;
a(i)=max(temp1(i,j));
end
i=1:hang;
c(i)=min(z(i),a(i))*0.68;%计算每帧的门限值
for i=1:hang;
for j=1:framelen;
if temp1(i,j)>c(i)
y(i,j)=temp1(i,j)-c(i);
else if abs(temp1(i,j)) y(i,j)=0;
else if temp1(i,j) y(i,j)=temp1(i,j)+c(i);
end
end
end
end
end
for i=1:hang;
if (j>=0)&(j y(i,j)=0;
end
end %将0到20点置零
for i=1:hang;
for j=framelen:450;
y(i,j)=0; %将framelen点到450点的值置零
end
end
for i=1:hang;
for j=1:framelen;
if y(i,j)>0
y1(i,j)=1;
else if y(i,j)==0;
y1(i,j)=0;
else if y(i,j) y1(i,j)=-1;
end
end
end
end
end
for i=1:hang;
if (j>=0)&(j y1(i,j)=0;
end
end %将0到20点置零
for i=1:hang;
for j=framelen:450;
y1(i,j)=0; %将framelen点到450点的值置零
end
end
for i=1:hang;
for k=1:128;
n=21:framelen;
R(i,k)=sum(y(i,n).*y1(i,n+k));
end
end
%计算每一帧y与y1的互相关值
for i=1:hang;
k=20:128;
Rmax(i)=max(R(i,k));%计算每帧的Rmax值
end
for i=1:hang;
k=20:128;
[r,kmax(i)]=max(R(i,k));%找出每帧Rmax对应的k值kmax
end
for i=1:hang;
if Rmax(i) P(i)=0;
else P(i)=kmax(i);
end
end
speech(h)=0;
for i=1:hang-1;
if P(i)==P(i+1)
speech(h)=speech(h)+1;
end
end
speechbi(1,h)=speech(h)/hang;
end
speechbi
clear all
for h=1:30
fname=sprintf('D:\\study\\音频采样\\speechwithmusic22050\\%d.wav',h);
x=wavread(fname);
x=x(:,1);
[c,l]=wavedec(x,3,'db4');
ca=appcoef(c,l,'db4',3);%近似系数
x=ca;
enframex=enframe(x,128,64);%对信号x分帧处理,每帧有128个采样点,相邻帧之间有50%的叠加率
[row,col]=size(enframex);%返回行,列,每一行代表一帧,每一列表示1到128个采样点
framelen=col;
frameinc=64;
hang=row;%计算出分帧后语音矩阵的行数
temp1=enframe(x,framelen,frameinc);%将分帧后的数据存入temp1数组矩阵
for i=1:hang;
j=1:frameinc;
z(i)=max(temp1(i,j));%求第i帧前frameinc个元素最大值并存入z(i)数组中
end
for i=1:hang;
j=framelen-frameinc:framelen;
a(i)=max(temp1(i,j));
end
i=1:hang;
c(i)=min(z(i),a(i))*0.68;%计算每帧的门限值
for i=1:hang;
for j=1:framelen;
if temp1(i,j)>c(i)
y(i,j)=temp1(i,j)-c(i);
else if abs(temp1(i,j)) y(i,j)=0;
else if temp1(i,j) y(i,j)=temp1(i,j)+c(i);
end
end
end
end
end
for i=1:hang;
if (j>=0)&(j y(i,j)=0;
end
end %将0到20点置零
for i=1:hang;
for j=framelen:450;
y(i,j)=0; %将framelen点到450点的值置零
end
end
for i=1:hang;
for j=1:framelen;
if y(i,j)>0
y1(i,j)=1;
else if y(i,j)==0;
y1(i,j)=0;
else if y(i,j) y1(i,j)=-1;
end
end
end
end
end
for i=1:hang;
if (j>=0)&(j y1(i,j)=0;
end
end %将0到20点置零
for i=1:hang;
for j=framelen:450;
y1(i,j)=0; %将framelen点到450点的值置零
end
end
for i=1:hang;
for k=1:128;
n=21:framelen;
R(i,k)=sum(y(i,n).*y1(i,n+k));
end
end
%计算每一帧y与y1的互相关值
for i=1:hang;
k=20:128;
Rmax(i)=max(R(i,k));%计算每帧的Rmax值
end
for i=1:hang;
k=20:128;
[r,kmax(i)]=max(R(i,k));%找出每帧Rmax对应的k值kmax
end
for i=1:hang;
if Rmax(i) P(i)=0;
else P(i)=kmax(i);
end
end
speechwithmusic(h)=0;
for i=1:hang-1;
if P(i)==P(i+1)
speechwithmusic(h)=speechwithmusic(h)+1;
end
end
speechwithmusicbi(1,h)=speechwithmusic(h)/hang;
end
speechwithmusicbi