Forums

something went wrong

Started by khurram712 July 16, 2008
 hi everyone..

i tried spectral subtraction method for removal of noise from speech
signal
but the sound that i hear now seems more like sound of "Alvin and
Chipmunks".can someone diagnose the problem this is my code for the
program.i hope you could help out

clc
%function [ss]=specsub1(si,fs)

[s,fs]=wavread('west.wav');
%specsub(noi,fr);

ti=16e-3;% desired frame increment (16 ms)
of=2; % overlap factor = (fft length)/(frame increment)
ri=0;
if ri
    ni=pow2(nextpow2(ti*fs*sqrt(0.5)));
else
    ni=round(ti*fs);    % frame increment in samples
end

tinc=ni/fs;          % true frame increment time

no=round(of);                                   % integer overlap factor
nf=ni*no;           % fft length
w=sqrt(hamming(nf+1))'; w(end)=[]; % for now always use sqrt hamming
window
w=w/sqrt(sum(w(1:ni:nf).^2));       % normalize to give overall gain of 1
y=enframe(s,w,ni);
yf=fft(y,nf,2);
%yf=rfft(y,nf,2);
yp=yf.*conj(yf); 

[nr,nf2]=size(yp) 

%noise estimation yet to be made....


[dp,ze]=estnoisem(yp,tinc);
ssv=zeros(ni*(no-1),1); 

ypf=sum(yp,2);%what is this??
dpf=sum(dp,2);

%noisy segmental noise ratio

for i=1:length(yp)
    nsnr(i)=10*log10(ypf(i)/dpf(i));
    if(nsnr(i)>=20)
        alpha(i)=1;
    elseif(nsnr(i)>=-6 && nsnr(i)<20)
        alpha(i)=4-(3*nsnr(i)/20);
    else
        alpha(i)=4.9;
    end
end

 %for i=1:length(yp)
     sp_eh_sp=yp(:,:)-dp(:,:);
 %end
 
 beta=0.005;
 
for i=1:size(sp_eh_sp,1)
    for j=1:size(sp_eh_sp,2)
        if(sp_eh_sp(i,j)>beta*dp(i,j))
            sp_eh_sp(i,j)=yp(i,j)-alpha(i)*dp(i,j);
        else
            sp_eh_sp(i,j)=beta*dp(i,j);
        end
    end
end

     sp_eh_sp=sqrt(sp_eh_sp);
     sp_eh=exp(sqrt(-1)*angle(yf)).*sp_eh_sp;
     
     se=ifft(sp_eh,nf,2).*repmat(w,nr,1);
    % se=(irfft((sp_eh_sp).',nf).').*repmat(w,nr,1); 
    
    
    ss=zeros(ni*(nr+no-1),no);                      % space for overlapped
output speech
    ss(1:ni*(no-1),end)=ssv;
    for i=1:no
        nm=nf*(1+floor((nr-i)/no));  % number of samples in this set
        ss(1+(i-1)*ni:nm+(i-1)*ni,i)=reshape(se(i:no:nr,:)',nm,1);
    end
    ss=sum(ss,2);
     
     
     
     %s=sum(abs(s),2)
     wavplay(abs(ss),fs)

Thanks

Khurram Hameed