语音信号的分帧加窗的matlab实现functionSeg=segment(signal,W,SP,Window)ifnargin3SP=.4;endifnargin2W=256;endifnargin4Window=hamming(W);endWindow=Window(:);%makeitacolumnvectorL=length(signal);SP=fix(W.*SP);N=fix((L-W)/SP+1);%numberofsegmentsIndex=(repmat(1:W,N,1)+repmat((0:(N-1))'*SP,1,W))';hw=repmat(Window,1,N);Seg=signal(Index).*hw;语音信号处理预加重、加窗分帧matlab程序%获取语音信号[filename,pathname]=uigetfile('*.wav','chooseaaudiofile:');[wavin,fs,nbits]=wavread([pathnamefilename]);wav_l=length(wavin);%采样点数,length()返回值是标量frame_l=0.04*fs;%根据fs选择帧长,step_l=floor(0.5*frame_l);%设置帧移num_frame=floor((wav_l-frame_l)/step_l)+1;%确定帧数win_ham=hamming(frame_l);%在做fft之前,为移除直流分量和加重高频分量,采用汉明窗,对信号进行加权%加窗处理用来消除分帧时带来的截断效应%加窗,分帧(矩阵每一行为一帧)fori=1:num_framen1=(i-1)*step_l+1;n2=(i-1)*step_l+frame_l;zy(i,:)=(win_ham').*(yt(n1:n2)');%存储每一帧噪音(行向量)%win_ham、yt是列向量,需转置yy(i,:)=(win_ham').*(wavin(n1:n2)');%存储每一帧纯净语音end关于matlab中的语音识别在用DFT求得倒普之后。为什么需要加上倒普提升窗口呢??谢谢!窗函数是这样的:w=1+6*sin(pi*[1:12]./12);为什么要这样计算呢??以下是具体的程序~~%%%%%文件mfcc.mfunctionccc=gbfcosmfcc(x)%归一化mel滤波器组系数bank=melbankm(24,256,16000,0,0.5,'m');bank=full(bank);bank=bank/max(bank(:));%DCT系数,12*24fork=1:12n=0:23;dctcoef(k,:)=cos((2*n+1)*k*pi/(2*24));end%归一化倒谱提升窗口w=1+6*sin(pi*[1:12]./12);w=w/max(w);%预加重滤波器xx=double(x);xx=filter([1-1],1,xx);xx=x;%zhangadd%语音信号分帧%xx=enframe(xx,256,80);xppl=length(xx);j=1;fori=65:80:xppl-256,xx1(j,:)=xx(i:i+256-1)';j=j+1;endxx=xx1;%计算每帧的MFCC参数fori=1:size(xx,1)y=xx(i,:);s=y'.*hamming(256);t=abs(fft(s));t=t.^2;t=t+2*realmin;log(bank*t(1:129))c1=dctcoef*log(bank*t(1:129))c11=Disfrcthe(1,24)*log(bank*t(1:129))c2=c1.*w';m(i,:)=c2';end%差分参数dtm=zeros(size(m));fori=3:size(m,1)-2dtm(i,:)=-2*m(i-2,:)-m(i-1,:)+m(i+1,:)+2*m(i+2,:);enddtm=dtm/3;%合并mfcc参数和一阶差分mfcc参数ccc=[mdtm];%去除首尾两帧,因为这两帧的一阶差分参数为0ccc=ccc(3:size(m,1)-2,:);return利用MATLAB录制并保存声音文件R=audiorecorder(44100,16,2);%创建一个保存音频信息的对象,它包含采样率,时间和录制的音频信息等等record(R);%开始录制,此时对着麦克风说话即可。pause(R);%暂停录制。play(R)%播放录制的声音。myspeech=getaudiodata(R);%得到以n*2列数字矩阵存储的刚录制的音频信号。savespmyspeechplot(myspeech)%画出波形声音信号时域分析程序wavwrite(myspeech,44100,16,'myspeech');%myspeech表示要存入的波形矩阵,44100表采样率,16为以16bits存储,'myspeech'为存储的文件名。waveFile='myspeech';[y,fs,nbits]=wavread(myspeechfile);a=0.95;y2=filter([1,-a],1,y);time=(1:length(y))/fs;wavwrite(y2,fs,nbits,'whatFood_preEmphasis.wav');subplot(2,1,1);plot(time,y);title('Originalwave:s(n)');subplot(2,1,2);plot(time,y2);title(sprintf('Afterpre-emphasis:s_2(n)=s(n)-a*s(n-1),a=%f',a));subplot(2,1,1);set(gca,'unit','pixel');axisPos=get(gca,'position');uicontrol('string','Play','position',[axisPos(1:2),60,20],'callback','sound(y,fs)');subplot(2,1,2);set(gca,'unit','pixel');axisPos=get(gca,'position');uicontrol('string','Play','position',[axisPos(1:2),60,20],'callback','sound(y2,fs)');