PDA

查看完整版本 : [求助]请问我这个程序怎么无法运行


angel427
2009-02-23, 09:52
close all;
clear all;
[x,fs,bit]=wavread('a.wav');%读语音数据,数据放入了X,fs代表采样率,bit代表采样位数
framelength=240;%设置帧长,%30ms under 8khz
framenumber=fix(length(x)/(framelength));%总的数据帧数
totaltime=length(x)/fs;%该段语音总的时间长度
sp1=x(fix(1.1*fs):(fix(1.1*fs)+framelength+framelength-1));%1.1*fs=8.8秒处为浊音始点,取两帧
sp2=x(0.8*fs:(0.8*fs+framelength+framelength-1));%0.8*fs=6.4秒处为清音始点,取两帧
d=0;%初始化,浊音波峰判断
R1=0;%初始化,浊音一个基音周期内帧数
%计算每帧的能量
for i=1:framenumber;
E(i)=0;%短时能量初始化
Z(i)=0;%短时过零率初始化
M(i)=0;%短时平均幅度初始化
K(i)=0;%短时零能比初始化
for j=(framelength*(i-1)+1):framelength*i;
E(i)=E(i)+x(j)*x(j); %第i帧短时能量
end
for j=(framelength*(i-1)+2):framelength*i;
Z(i)=Z(i)+abs(sign(x(j)-0.2)-sign(x(j-1)));%第i帧短时过零率
end
for j=(framelength*(i-1)+1):framelength*i;
M(i)=M(i)+abs(x(j));
end
M(i)=M(i)/framelength;%第i帧短时平均幅度
K(i)=Z(i)/E(i);%第i帧短时零能比
end
for i=1:framelength;
R(i)=0;
for j=1:framelength;
R(i)=R(i)+sp1(j)*sp1(i+j);%浊音的短时自相关函数
end
if (R(i)>=110.11)
R(i)=110.11;%修正最高波峰最大值为110.11
d=d+1;%当波峰为110.11时,自加一
end
if (d==1)%以第一个波峰110.11为起始点,下一个波峰110.11为终点
R1=R1+1;%计算一个基音周期内帧数
end
end
for i=1:framelength;
r(i)=0;
for j=1:framelength;
r(i)=r(i)+sp2(j)*sp2(i+j);%清音的自相关函数
end
end
%思考为什么取sign(x(j)-0.2)
%把数据点转化为时间长度
for i=1:framenumber;
anyfrequency(i)=totaltime*i/framenumber;
end
for i=1:length(x);
anytime(i)=i*totaltime/length(x);
end
figure(1)
subplot(2,1,1);plot(anytime,x);title('语音图');%语音图
subplot(2,1,2);plot(anyfrequency,E);title('短时能量');%短时能量
figure(2)
subplot(2,1,1);plot(anytime,x);title('语音图');%语音图
subplot(2,1,2);plot(anyfrequency,M);title('短时平均幅度');%短时平均幅度
figure(3)
subplot(2,1,1);plot(anytime,x);title('语音图');%语音图
subplot(2,1,2);plot(anyfrequency,Z);title('短时过零率');%短时过零率
figure(4)
subplot(4,1,1);plot(anytime,x);title('语音图');%语音图
subplot(4,1,2);plot(anyfrequency,Z);title('短时过零率');%短时过零率
subplot(4,1,3);plot(anyfrequency,E);title('短时能量');%短时能量
subplot(4,1,4);plot(anyfrequency,K);title('短时零能比');%短时零能比
figure(5)
subplot(3,1,1);plot(R);title('浊音短时自相关函数');%浊音短时自相关函数
subplot(3,1,2);plot(sp1);
subplot(3,1,3);plot(x);
figure(6)
subplot(3,1,1);plot(r);title('清音短时自相关函数');%清音短时自相关函数
subplot(3,1,2);plot(sp2);
subplot(3,1,3);plot(x);
T=R1/fs%浊音段语音的基音周期,单位为秒(s)
f=fs/R1%浊音段语音的基音频率,单位为赫兹(Hz)

麻烦各位帮忙看看,谢谢。