卡尔曼滤波用于语音增强的一个经典代码matlab - 副本
function output=KalmanSignalDenoiser(Noisy,Clean,fs)
% OUTPUT=KALMANSIGNALDENOISER(NOISY,CLEAN,FS)
% this purpose of this function is to demonstrate the capability of kalman % filter for denoising noisy speech (corrupted by white noise). Kalman % filtering of noisy speech usually have two steps:
% 1 . Estimating the AR parameters of speech segment
% 2 . Filtering the segment
% There are different approaches for extracting AR parameters of noisy % speech in the literature, however, in this function none is implemented. % Clean speech signal should be provided for this purpose. %
% ARGUMENTS
% NOISY : noise contaminated speech
% CLEAN : clean speech signal
% FS : Sampling frequency which should be the same for both signals %
% Output is the denoised speech signal
%
% Required functions:
% SEGMENT
%Sep-04
%Esfandiar Zavarehei
W=fix(.025*fs); %Window length is 25 ms
SP=1; %Shift percentage is 40% (10ms) %Overlap-Add method works good with this value(.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);
[A Q]=lpc(x,SpecP);
P=diag(repmat(R(1),1,SpecP));
o=zeros(1,W*size(x,2));% allocating memory to the output in advance save a lot of
computation time
o(1:SpecP)=y(1:SpecP,1)';
hwb = waitbar(0,'Please wait...','Name','Processing'); start=SpecP+1;
Sp=o(1:SpecP)';
t=SpecP+1;
for n=1:size(x,2)
waitbar(n/size(x,2),hwb,['Please wait... ' num2str(fix(100*n/size(x,2)))
' %'])
F=[FUpper; fliplr(-A(n,2:end))];
for i=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'; %Notice that the previous SpecP-1 output samples are
updated again
P=(I-K*H)*P_;
Sp=SOut;
t=t+1;
end
start=1;
end
close(hwb)
output=o;
function FormantTrack=FTrackSig(signal,fs)
% F=FTRACKSIG(S)
% Formant Tracking
% Inputs: S, signal, the speech signal with Motorola Format and sampling
% frequency fs (default=16000 KHz)
% Outputs: F, FormantTrack is a matrix each row of which is a track of one of
% the formants
%
% Important Variables in the program: There are several important variables
% in the program:
% Main Function (FTrackSig)
% MaxFormantFreq : The maximum frequency of the formant % MaxBWFreq : The maximum BandWidth of the formant % SegLength: Number of samplein each frame,
% SP: Shift Percentage of frames, (1-SP is overlap percentage) % NumberOfFormants: The number of formants to be chosen % PreEmphFact: the pre-emphasis factor
% fs: sampling frequency
% FormantCand function
% P: order of LPC model
%----------------------------------
% What does this program do:
% The speech signal is first choped into segments and the pre-emphasize, % then windowed. Then the LPC Model for these segments are extracted. using % these coefficients the roor=ts of the LP model is calculated, sorted by % increasing frequency and the extreme poles are eliminated. (an extreme % ploe is one with zero frequency or out of range frequency, or rather % large bandwidth). if the number of poles are not sufficient the segments % will be re modeled using a larger order for LPC (THIS IS STILL TO BE % DISCUSSED ACTUALLY). these sorted poles are then grouped with regards to % the number of poles required. if there were more than one group each % group will be evaluated with regards to the different distributions of % phonems which are loaded from another file, and then evaluated in terms % of the trajectory continueity. the best formant will be chosen then using % these evaluations.
%
%
% Author Esfandiar Zavarehei
% Date 5-Nov-2003
% Revised: 19-Nov-2003
% Revised: 21-Nov-2003
%
%
% Notes:
% The MAXIMUM FREQUENCY is a crucial parameter if you have a % low sampling frequency you have to adjust it your self. % The NUMBER OF FORMANTS is 5 if you have a low sampling frequency % try in decrease this number.
if nargin<2
fs=16000; % The Sampling frequency
end
SegLength=.025*fs; % This is equal to 25ms
SP=.4; % Shift Percentage
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([1 PreEmphFact],1,signal)); %Pre-emphasizing
BegPtr=1;
FCFreq=[];
FCBW=[];
hamwin=hamming(SegLength);
AddP=1;
for n=1:NumSeg
segment=signal(BegPtr:(BegPtr+SegLength-1)); %Chopping
segment=segment.*hamwin; %Windowing
segment=[segment;zeros((FreqRes-SegLength),1)]; %adjusting frequency
resoloution
Candidates=FormantCand(segment);
FCseg=angle(Candidates)*fs/(2*pi);
FCBW=abs(log(abs(Candidates))*fs/pi);
FCseg=FCseg(find(FCBWlength(FCseg))
Candidates=FormantCand(segment,AddP);
FCseg=angle(Candidates)*fs/(2*pi);
FCBW=abs(log(abs(Candidates))*fs/pi);
FCseg=FCseg(find(FCBW1)
Formants=distFormant(FCseg,NumberOfFormants,LastFormant);
else
Formants=distFormant(FCseg,NumberOfFormants);
end
ForMat=Formants.FM;
chance=1./Formants.dst;
[a b]=max(chance);
LastFormant=ForMat(:,b);
FormantTrack(:,n)=LastFormant;
AddP=1;
BegPtr=BegPtr+fix(SegLength*SP); %Moving the pointer to next segment
end
%-----------------------------extracting, and choosing the appropriate poles of each segment
function Candidates=FormantCand(segment,AddP)
%5 NOV 2003
%This Program returns the Formant candidate of a segment %the segment, which is probably a piece of speech signal, %is not windowed, pre-emphasized, zero padded, etc. in this program. if (nargin<2)
AddP=0; %The number to be added to the LP Order, if it did not have enough Poles
extracted
end
P=15+AddP; %number of LPC Coefitions
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);
[Phase sIndex]=sort(Phase);
Amp=Amp(sIndex);
%Candidates
Candidates=Amp.*exp(j*Phase);
%-------------------------------------------DISTFORMANT function dist=distFormant(Poles,numberOfFormants,LastChosenFormant) %THIS FUNCTION CALCULATE THE DISTANCE THE LAST FORMANT WITH ALL AVAILABLE %CANDIDATES AND RETURN A VECTOR (ROW VWCTOR) THAT CONTAINS THESE DISTANCES. %Formants are row vectors in this program
% if (length(Poles) Hangover)
SpeechFlag=0;
else
SpeechFlag=1;
end
本文档为【卡尔曼滤波用于语音增强的一个经典代码matlab - 副本】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。