?? estnoisem.m
字號:
nsms=10.^(nsmdb*nv*tinc/10); % [8 4 2 1.2] in paper
qeqimax=1/qeqmin; % maximum value of Qeq inverse (23)
qeqimin=1/qeqmax; % minumum value of Qeq per frame inverse
if isempty(yf) % provide dummy initialization
ac=1; % correction factor (9)
subwc=nv; % force a buffer switch on first loop
ibuf=0;
p=x; % smoothed power spectrum
sn2=p; % estimated noise power
pb=p; % smoothed noisy speech power (20)
pb2=pb.^2;
pminu=p;
actmin=repmat(Inf,1,nrf); % Running minimum estimate
actminsub=actmin; % sub-window minimum estimate
actbuf=repmat(Inf,nu,nrf); % buffer to store subwindow minima
lminflag=zeros(1,nrf); % flag to remember local minimum
else
if ~nrcum % initialize values for first frame
p=yf(1,:); % smoothed power spectrum
ac=1; % correction factor (9)
sn2=p; % estimated noise power
pb=p; % smoothed noisy speech power (20)
pb2=pb.^2;
pminu=p;
actmin=repmat(Inf,1,nrf); % Running minimum estimate
actminsub=actmin; % sub-window minimum estimate
subwc=nv; % force a buffer switch on first loop
actbuf=repmat(Inf,nu,nrf); % buffer to store subwindow minima
ibuf=0;
lminflag=zeros(1,nrf); % flag to remember local minimum
end
% loop for each frame
for t=1:nr % we use t instead of lambda in the paper
yft=yf(t,:); % noise speech power spectrum
acb=(1+(sum(p)./sum(yft)-1).^2).^(-1); % alpha_c-bar(t) (9)
ac=aca*ac+(1-aca)*max(acb,acmax); % alpha_c(t) (10)
ah=amax*ac.*(1+(p./sn2-1).^2).^(-1); % alpha_hat: smoothing factor per frequency (11)
snr=sum(p)/sum(sn2);
ah=max(ah,min(aminh,snr^snrexp)); % lower limit for alpha_hat (12)
p=ah.*p+(1-ah).*yft; % smoothed noisy speech power (3)
b=min(ah.^2,bmax); % smoothing constant for estimating periodogram variance (22 + 2 lines)
pb=b.*pb + (1-b).*p; % smoothed periodogram (20)
pb2=b.*pb2 + (1-b).*p.^2; % smoothed periodogram squared (21)
qeqi=max(min((pb2-pb.^2)./(2*sn2.^2),qeqimax),qeqimin/(t+nrcum)); % Qeq inverse (23)
qiav=sum(qeqi)/nrf; % Average over all frequencies (23+12 lines) (ignore non-duplication of DC and nyquist terms)
bc=1+av*sqrt(qiav); % bias correction factor (23+11 lines)
bmind=1+2*(nd-1)*(1-md)./(qeqi.^(-1)-2*md); % we use the simplified form (17) instead of (15)
bminv=1+2*(nv-1)*(1-mv)./(qeqi.^(-1)-2*mv); % same expression but for sub windows
kmod=bc*p.*bmind<actmin; % Frequency mask for new minimum
if any(kmod)
actmin(kmod)=bc*p(kmod).*bmind(kmod);
actminsub(kmod)=bc*p(kmod).*bminv(kmod);
end
if subwc>1 && subwc<nv % middle of buffer - allow a local minimum
lminflag=lminflag | kmod; % potential local minimum frequency bins
pminu=min(actminsub,pminu);
sn2=pminu;
else
if subwc>=nv % end of buffer - do a buffer switch
ibuf=1+rem(ibuf,nu); % increment actbuf storage pointer
actbuf(ibuf,:)=actmin; % save sub-window minimum
pminu=min(actbuf,[],1);
i=find(qiav<qith);
nsm=nsms(i(1)); % noise slope max
lmin=lminflag & ~kmod & actminsub<nsm*pminu & actminsub>pminu;
if any(lmin)
pminu(lmin)=actminsub(lmin);
actbuf(:,lmin)=repmat(pminu(lmin),nu,1);
end
lminflag(:)=0;
actmin(:)=Inf;
subwc=0;
end
end
subwc=subwc+1;
x(t,:)=sn2;
qisq=sqrt(qeqi);
% empirical formula for standard error based on Fig 15 of [2]
xs(t,:)=sn2.*sqrt(0.266*(nd+100*qisq).*qisq/(1+0.005*nd+6/nd)./(0.5*qeqi.^(-1)+nd-1));
end
end
if nargout>1 % we need to store the state for next time
zo.nrcum=nrcum+nr; % number of frames so far
zo.p=p; % smoothed power spectrum
zo.ac=ac; % correction factor (9)
zo.sn2=sn2; % estimated noise power
zo.pb=pb; % smoothed noisy speech power (20)
zo.pb2=pb2;
zo.pminu=pminu;
zo.actmin=actmin; % Running minimum estimate
zo.actminsub=actminsub; % sub-window minimum estimate
zo.subwc=subwc; % force a buffer switch on first loop
zo.actbuf=actbuf; % buffer to store subwindow minima
zo.ibuf=ibuf;
zo.lminflag=lminflag; % flag to remember local minimum
zo.tinc=tinc; % must be the last one
zo.qq=qq;
end
if ~nargout
plot((1:nr),10*log10([sum(x,2)/nrf sum(yf,2)/nrf]))
legend('noise','input');
ylabel('Power (dB)');
xlabel(sprintf('Time (%d ms frames)',round(tinc*1000)));
end
end
function [m,h,d]=mhvals(d)
% Values are taken from Table 5 in [2]
%[2] R. Martin,"Bias compensation methods for minimum statistics noise power
% spectral density estimation", Signal Processing Vol 86, pp1215-1229, 2006.
% approx: plot(d.^(-0.5),[m 1-d.^(-0.5)],'x-'), plot(d.^0.5,h,'x-')
persistent dmh
if isempty(dmh)
dmh=[
1 0 0;
2 0.26 0.15;
5 0.48 0.48;
8 0.58 0.78;
10 0.61 0.98;
15 0.668 1.55;
20 0.705 2;
30 0.762 2.3;
40 0.8 2.52;
60 0.841 3.1;
80 0.865 3.38;
120 0.89 4.15;
140 0.9 4.35;
160 0.91 4.25;
180 0.92 3.9;
220 0.93 4.1;
260 0.935 4.7;
300 0.94 5];
end
if nargin>=1
i=find(d<=dmh(:,1));
if isempty(i)
i=size(dmh,1);
j=i;
else
i=i(1);
j=i-1;
end
if d==dmh(i,1)
m=dmh(i,2);
h=dmh(i,3);
else
qj=sqrt(dmh(i-1,1)); % interpolate using sqrt(d)
qi=sqrt(dmh(i,1));
q=sqrt(d);
h=dmh(i,3)+(q-qi)*(dmh(j,3)-dmh(i,3))/(qj-qi);
m=dmh(i,2)+(qi*qj/q-qj)*(dmh(j,2)-dmh(i,2))/(qi-qj);
end
else
d=dmh(:,1);
m=dmh(:,2);
h=dmh(:,3);
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -