卡尔曼滤波用于语音增强的一个经典代码matlab副本.docx
- 文档编号:24829781
- 上传时间:2023-06-01
- 格式:DOCX
- 页数:13
- 大小:18.77KB
卡尔曼滤波用于语音增强的一个经典代码matlab副本.docx
《卡尔曼滤波用于语音增强的一个经典代码matlab副本.docx》由会员分享,可在线阅读,更多相关《卡尔曼滤波用于语音增强的一个经典代码matlab副本.docx(13页珍藏版)》请在冰豆网上搜索。
卡尔曼滤波用于语音增强的一个经典代码matlab副本
卡尔曼滤波用于语音增强的一个经典代码matlab-副本
functionoutput=KalmanSignalDenoiser(Noisy,Clean,fs)
%OUTPUT=KALMANSIGNALDENOISER(NOISY,CLEAN,FS)
%thispurposeofthisfunctionistodemonstratethecapabilityofkalman%filterfordenoisingnoisyspeech(corruptedbywhitenoise).Kalman%filteringofnoisyspeechusuallyhavetwosteps:
%1.EstimatingtheARparametersofspeechsegment
%2.Filteringthesegment
%TherearedifferentapproachesforextractingARparametersofnoisy%speechintheliterature,however,inthisfunctionnoneisimplemented.%Cleanspeechsignalshouldbeprovidedforthispurpose.%
%ARGUMENTS
%NOISY:
noisecontaminatedspeech
%CLEAN:
cleanspeechsignal
%FS:
Samplingfrequencywhichshouldbethesameforbothsignals%
%Outputisthedenoisedspeechsignal
%
%Requiredfunctions:
%SEGMENT
%Sep-04
%EsfandiarZavarehei
W=fix(.025*fs);%Windowlengthis25ms
SP=1;%Shiftpercentageis40%(10ms)%Overlap-Addmethodworksgoodwiththisvalue(.4)
SpecP=13;
Window=ones(W,1);
x=segment(Clean,W,SP,Window);
y=segment(Noisy,W,SP,Window);
n=segment(Noisy-Clean,W,SP,Window);
R=var(n);
H=[zeros(1,SpecP-1)1];
G=H';GGT=G*H;
FUpper=[zeros(SpecP-1,1)eye(SpecP-1)];
I=eye(SpecP);
[AQ]=lpc(x,SpecP);
P=diag(repmat(R
(1),1,SpecP));
o=zeros(1,W*size(x,2));%allocatingmemorytotheoutputinadvancesavealotof
computationtime
o(1:
SpecP)=y(1:
SpecP,1)';
hwb=waitbar(0,'Pleasewait...','Name','Processing');start=SpecP+1;
Sp=o(1:
SpecP)';
t=SpecP+1;
forn=1:
size(x,2)
waitbar(n/size(x,2),hwb,['Pleasewait...'num2str(fix(100*n/size(x,2)))
'%'])
F=[FUpper;fliplr(-A(n,2:
end))];
fori=start:
W
S_=F*Sp;
e=y(i,n)-S_(end);%innovation
P_=F*P*F'+GGT*Q(n);
K=(P_*H')/(H*P_*H'+R(n));
SOut=S_+K*e;
o(t-SpecP+1:
t)=SOut';%NoticethatthepreviousSpecP-1outputsamplesare
updatedagain
P=(I-K*H)*P_;
Sp=SOut;
t=t+1;
end
start=1;
end
close(hwb)
output=o;
functionFormantTrack=FTrackSig(signal,fs)
%F=FTRACKSIG(S)
%FormantTracking
%Inputs:
S,signal,thespeechsignalwithMotorolaFormatandsampling
%frequencyfs(default=16000KHz)
%Outputs:
F,FormantTrackisamatrixeachrowofwhichisatrackofoneof
%theformants
%
%ImportantVariablesintheprogram:
Thereareseveralimportantvariables
%intheprogram:
%MainFunction(FTrackSig)
%MaxFormantFreq:
Themaximumfrequencyoftheformant%MaxBWFreq:
ThemaximumBandWidthoftheformant%SegLength:
Numberofsampleineachframe,
%SP:
ShiftPercentageofframes,(1-SPisoverlappercentage)%NumberOfFormants:
Thenumberofformantstobechosen%PreEmphFact:
thepre-emphasisfactor
%fs:
samplingfrequency
%FormantCandfunction
%P:
orderofLPCmodel
%----------------------------------
%Whatdoesthisprogramdo:
%Thespeechsignalisfirstchopedintosegmentsandthepre-emphasize,%thenwindowed.ThentheLPCModelforthesesegmentsareextracted.using%thesecoefficientstheroor=tsoftheLPmodeliscalculated,sortedby%increasingfrequencyandtheextremepolesareeliminated.(anextreme%ploeisonewithzerofrequencyoroutofrangefrequency,orrather%largebandwidth).ifthenumberofpolesarenotsufficientthesegments%willberemodeledusingalargerorderforLPC(THISISSTILLTOBE%DISCUSSEDACTUALLY).thesesortedpolesarethengroupedwithregardsto%thenumberofpolesrequired.ifthereweremorethanonegroupeach%groupwillbeevaluatedwithregardstothedifferentdistributionsof%phonemswhichareloadedfromanotherfile,andthenevaluatedinterms%ofthetrajectorycontinueity.thebestformantwillbechosenthenusing%theseevaluations.
%
%
%AuthorEsfandiarZavarehei
%Date5-Nov-2003
%Revised:
19-Nov-2003
%Revised:
21-Nov-2003
%
%
%Notes:
%TheMAXIMUMFREQUENCYisacrucialparameterifyouhavea%lowsamplingfrequencyyouhavetoadjustityourself.%TheNUMBEROFFORMANTSis5ifyouhavealowsamplingfrequency%tryindecreasethisnumber.
ifnargin<2
fs=16000;%TheSamplingfrequency
end
SegLength=.025*fs;%Thisisequalto25ms
SP=.4;%ShiftPercentage
PreEmphFact=-0.98;
NumberOfFormants=5;
MaxFormantFreq=5000;
MaxBWFreq=600;
FreqRes=512;
sigLength=length(signal);
NumSeg=fix(sigLength-SegLength+SegLength*SP)/(SegLength*SP);signal=real(filter([1PreEmphFact],1,signal));%Pre-emphasizing
BegPtr=1;
FCFreq=[];
FCBW=[];
hamwin=hamming(SegLength);
AddP=1;
forn=1:
NumSeg
segment=signal(BegPtr:
(BegPtr+SegLength-1));%Chopping
segment=segment.*hamwin;%Windowing
segment=[segment;zeros((FreqRes-SegLength),1)];%adjustingfrequency
resoloution
Candidates=FormantCand(segment);
FCseg=angle(Candidates)*fs/(2*pi);
FCBW=abs(log(abs(Candidates))*fs/pi);
FCseg=FCseg(find(FCBW FCseg=FCseg(find(FCseg while(NumberOfFormants>length(FCseg)) Candidates=FormantCand(segment,AddP); FCseg=angle(Candidates)*fs/(2*pi); FCBW=abs(log(abs(Candidates))*fs/pi); FCseg=FCseg(find(FCBW FCseg=FCseg(find(FCseg AddP=AddP+1; end if(n>1) Formants=distFormant(FCseg,NumberOfFormants,LastFormant); else Formants=distFormant(FCseg,NumberOfFormants); end ForMat=Formants.FM; chance=1./Formants.dst; [ab]=max(chance); LastFormant=ForMat(: b); FormantTrack(: n)=LastFormant; AddP=1; BegPtr=BegPtr+fix(SegLength*SP);%Movingthepointertonextsegment end %-----------------------------extracting,andchoosingtheappropriatepolesofeachsegment functionCandidates=FormantCand(segment,AddP) %5NOV2003 %ThisProgramreturnstheFormantcandidateofasegment%thesegment,whichisprobablyapieceofspeechsignal,%isnotwindowed,pre-emphasized,zeropadded,etc.inthisprogram.if(nargin<2) AddP=0;%ThenumbertobeaddedtotheLPOrder,ifitdidnothaveenoughPoles extracted end P=15+AddP;%numberofLPCCoefitions lpccof=lpc(segment,P); rts=roots(lpccof); Phase=angle(rts); Amp=abs(rts); posPhaseIndex=find((Phase>0.000001)&(Phase<(pi-0.000001)));Phase=Phase(posPhaseIndex); Amp=Amp(posPhaseIndex); [PhasesIndex]=sort(Phase); Amp=Amp(sIndex); %Candidates Candidates=Amp.*exp(j*Phase); %-------------------------------------------DISTFORMANTfunctiondist=distFormant(Poles,numberOfFormants,LastChosenFormant)%THISFUNCTIONCALCULATETHEDISTANCETHELASTFORMANTWITHALLAVAILABLE%CANDIDATESANDRETURNAVECTOR(ROWVWCTOR)THATCONTAINSTHESEDISTANCES.%Formantsarerowvectorsinthisprogram %if(length(Poles) %dist.FM=[Poles;NaN*ones(numberOfFormants-length(Poles),1)]; %dist.dst=1; %return %end FormantMat=(nchoosek(Poles,numberOfFormants))';numberOfCands=size(FormantMat,2); if(nargin==3) dst=sum((FormantMat-LastChosenFormant(: ones(1,numberOfCands))).^2); elseif(nargin==2) dst=ones(1,size(FormantMat,2)); else error('notappropriatenumberofinputs')end dist.FM=FormantMat; dist.dst=dst; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55 functionvec=mat2vec(mat) %VEC=MAT2VEC(MAT) %ThisfunctionaugmentstherowsoftheinputmatrixMAT %formingavectorVEC % %Example: % %A=[1216 %2419]; %B=mat2vec(MAT); %ThenBewillbe: %B=[12162419]; % %Sep-04 %EsfandiarZavarehei numofrow=size(mat,1); vec=[]; fori=1: numofrow vec=[vecmat(i,: )]; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%functionReconstructedSignal=OverlapAdd(XNEW,yphase,windowLen,ShiftLen); %Y=OverlapAdd(X,A,W,S); %Yisthesignalreconstructedsignalfromitsspectrogram.Xisamatrix %witheachcolumnbeingthefftofasegmentofsignal.Aisthephase%angleofthespectrumwhichshouldhavethesamedimensionasX.ifitis%notgiventhephaseangleofXisusedwhichinthecaseofrealvaluesis%zero(assumingthatitsthemagnitude).Wisthewindowlengthoftime%domainsegmentsifnotgiventhelengthisassumedtobetwiceaslongas%fftwindowlength.Sistheshiftlengthofthesegmentationprocess(for%exampleinthecaseofnonoverlappingsignalsitisequaltoWandinthe%caseof%50overlapisequaltoW/2.ifnotgivvenW/2isused.Yisthe%reconstructedtimedomainsignal. %Sep-04 %EsfandiarZavarehei ifnargin<2 yphase=angle(XNEW); end ifnargin<3 windowLen=size(XNEW,1)*2; end ifnargin<4 ShiftLen=windowLen/2; end [FreqResFrameNum]=size(XNEW); sig=zeros((FrameNum-1)*ShiftLen+windowLen,1); fori=1: FrameNum start=(i-1)*ShiftLen+1; spec=[XNEW(: i).*exp(j*yphase(: i))]; spec=[spec;flipud(conj(spec))]; sig(start: start+windowLen-1)=sig(start: start+windowLen-1)+real(ifft(spec,windowLen)); end ReconstructedSignal=sig; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555 functionSeg=segment(signal,W,SP,Window) %SEGMENTchopsasignaltooverlappingwindowedsegments %A=SEGMENT(X,W,SP,WIN)returnsamatrixwhichitscolumnsaresegmented%andwindowedframesoftheinputonedimentionalsignal,X.Wisthe%numberofsamplesperwindow,defaultvalueW=256.SPistheshift%percentage,defaultvalueSP=0.4.WINisthewindowthatismultipliedby%eachsegmentanditslengthshouldbeW.thedefaultwindowishamming %window. %06-Sep-04 %EsfandiarZavarehei ifnargin<3 SP=.4; end ifnargin<2 W=256; end ifnargin<4 Window=hamming(W); end L=length(signal); SP=fix(W.*SP); N=fix((L-W)/SP+1);%numberofsegments Index=(repmat(1: W,N,1)+repmat((0: (N-1))'*SP,1,W))'; hw=repmat(Window,1,N); Seg=signal(Index).*hw; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function[NoiseFlag,SpeechFlag,NoiseCounter, Dist]=vad(signal,noise,NoiseCounter,NoiseMargin,Hangover) %[NOI
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 卡尔曼滤波用于语音增强的一个经典代码matlab 副本 卡尔 滤波 用于 语音 增强 一个 经典 代码 matlab