语音信号特征提取程序设计代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
主程序:
%
fs=22050; %抽样频率
x=wavread('2.wav');
figure(1);subplot(211);plot(x);
title('原始语音信号波形','fontsize',16,'fontweight','bold'); xlabel('样点数','fontsize',16,'fontweight','bold'); ylabel('幅值','fontsize',16,'fontweight','bold');grid on;
N=128;
n=0:N-1;
y=fft(x);
mag=abs(y);
f=(0:length(y)-1)'*fs/length(y);%进行对应的频率转换figure(1);subplot(212);plot(f,mag);
title('原始信号频谱图','fontsize',16,'fontweight','bold'); xlabel('频率(Hz)','fontsize',16,'fontweight','bold'); ylabel('幅值','fontsize',16,'fontweight','bold');grid on;
y=wavread('2.wav');
%预加重
figure();subplot(211);plot(x);
xlabel('样点数','fontsize',16,'fontweight','bold'); ylabel('原始波形(幅值)','fontsize',16,'fontweight','bold');
xx=double(y);
subplot(212);plot(xx);
xlabel('样点数','fontsize',16,'fontweight','bold'); ylabel('预加重波形(幅值)','fontsize',16,'fontweight','bold');
%对指定帧位置进行加窗处理
Q=y';
N=256;%窗长
Hamm=hamming(N);%加窗(汉明窗)Rect=rectwin(N);%加窗(矩形窗)frame=60;%需要处理的帧位置
M=Q(((frame-1)*(N/2)+1):((frame-1)*( N/2)+N));
Frame=M.*Hamm';%加窗后的语音帧frame=M.*Rect';
figure();subplot(211);plot(Frame); ylabel('汉明窗','fontsize',16,'fontweight','bold');subplot(212);plot(frame);
ylabel('矩形窗','fontsize',16,'fontweight','bold');
%语音信号分帧
figure();subplot(211);plot(y);
xlabel('样点数','fontsize',16,'fontweight','bold'); ylabel('原始','fontsize',16,'fontweight','bold');
y=enframe(y,256,80);
subplot(212);plot(y);xlabel('帧数','fontsize',16,'fontweight','bold'); ylabel('分帧','fontsize',16,'fontweight','bold');
%端点检测
[x1,x2]=vad(x);%调用函数vad实现
%浊音,取13270--13510个点
%短时自相关函数
temp=y(13271:13510);
Rn1=zeros(1,240);
for nn=1:240
for ii=1:240-nn
Rn1(nn)=Rn1(nn)+temp(ii)*temp(nn+ii );
end
end
figure(6);
subplot(211);jj=1:240;plot(jj,Rn1,'b');titl e('浊音自相关函数','fontsize',16,'fontweight','bold'); xlabel('帧数','fontsize',16,'fontweight','bold');ylabel('短时自相关函数','fontsize',16,'fontweight','bold');grid on;
%清音,取12120--12360个点
%短时自相关函数
temp=y(12121:12360);
Rn2=zeros(1,240);
for nn=1:240
for ii=1:240-nn
Rn2(nn)=Rn2(nn)+temp(ii)*temp(nn+ii );
end
end
figure(6);
subplot(212);jj=1:240;plot(jj,Rn2,'b'); title('清音自相关函数
','fontsize',16,'fontweight','bold'); xlabel('帧数','fontsize',16,'fontweight','bold'); ylabel('短时自相关函数','fontsize',16,'fontweight','bold');grid on;
分帧功能子程序:
function f=enframe(x,win,inc)
% F = ENFRAME(X,LEN) splits the vector X(:) up into
% frames. Each frame is of length LEN and occupies
% one row of the output matrix. The last few frames of X
% will be ignored if its length is not divisible by LEN.
% It is an error if X is shorter than LEN.
nx=length(x(:));
nwin=length(win);
if (nwin == 1)
len = win;
else
len = nwin;
end
if (nargin < 3)
inc = len;
end
nf = fix((nx-len+inc)/inc);
f=zeros(nf,len);
indf= inc*(0:(nf-1)).';
inds = (1:len);
f(:) =