Reply by January 28, 20082008-01-28
Hi everybody,

I use the below matlab implementation of a Wiener filter, but I get
strange artifacts when i process the noisy audio file.
Can somebody take a look at my code and tell me if there is something
wrong, or suspicios. When I process my noisy signal with this prgramm
i get strange artifacts, for example i see in the spectogram that some
coefficients  in the noise speech at very high frequencies where the
did not used to be any energy in the clean signal.

Thanks for you time

Jan

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function [output] = denoising2( clean_speech, noise_signal, FS)

%==========================================================================
noisy_speech = clean_speech+noise_signal;

 DFT_LENGTH         = 256;
 DOUBLE_DFT_LENGTH  = 256;
 BLOCK_LENGTH       = DFT_LENGTH/2;
 NBITS              = 16;

 
%==========================================================================
 size_speech        = size(clean_speech);
 signal_length      = size_speech(1,2);


 noisy_speech =[noisy_speech, zeros(1,1*DFT_LENGTH)];
 noise_signal =[noise_signal, zeros(1,1*DFT_LENGTH)];
 clean_speech =[clean_speech, zeros(1,1*DFT_LENGTH)];

 extended_size = size(noisy_speech);
 BlockNo = floor( signal_length /BLOCK_LENGTH);

%==========================================================================
% initialize fields

 denoised_abs   = zeros(extended_size); % Holds the calculation
 clean_end      = zeros(extended_size); % Holds the calculation

 % create the window function
 window=hann(DFT_LENGTH);

% beginning of high level loop
tic
for k = 1:1:BlockNo
    startxi  = (k-1)*BLOCK_LENGTH;
    stopxi   = startxi+DFT_LENGTH;

% the different SIGNALS are chopped in BLOCKS of DFT_LENGTH size
    dirty = noisy_speech (1,startxi+1:stopxi);
    noise = noise_signal (1,startxi+1:stopxi);
    clean = clean_speech (1,startxi+1:stopxi);

% window the
    dirty_windowed  = dirty.*window';
    noise_windowed  = noise.*window';
    clean_windowed  = clean.*window';

    DIRTYW    = fft(dirty_windowed, DOUBLE_DFT_LENGTH);
    NOISE     = fft(noise_windowed, DOUBLE_DFT_LENGTH);
    CLEAN     = fft(clean_windowed, DOUBLE_DFT_LENGTH);

    D = abs(DIRTYW);
    N = abs(NOISE);
    C = abs(CLEAN);

    C2 = C.*C;
    N2 = N.*N;

    % a-priori-SNR
    nu = C2./N2;

    %wiener-filter
    H_abs = nu./(nu+1);

    H_abs = max(0, H_abs);


    CL = H_abs.*DIRTYW;
    den = ifft(CL);

    cl_end = ifft(CLEAN);

    temp3 = denoised_abs (:,(k-1)*BLOCK_LENGTH+1:(k-1)* BLOCK_LENGTH +
DOUBLE_DFT_LENGTH);
            denoised_abs (:,(k-1)*BLOCK_LENGTH+1:(k-1)* BLOCK_LENGTH +
DOUBLE_DFT_LENGTH) = temp3 + den ;

    tempC = clean_end    (:,(k-1)*BLOCK_LENGTH+1:(k-1)* BLOCK_LENGTH +
DOUBLE_DFT_LENGTH);
            clean_end    (:,(k-1)*BLOCK_LENGTH+1:(k-1)* BLOCK_LENGTH +
DOUBLE_DFT_LENGTH) = tempC + cl_end ;

%=========================================================================
end
toc

%=========================================================================
    output.denoised_abs =   denoised_abs;%(:, BLOCK_LENGTH
+1:BLOCK_LENGTH+1+signal_length-1);
    output.clean_end = clean_end;

% writing the files
save_file = denoised_abs;
wavwrite( 0.9/max(abs(save_file))*save_file ,FS,NBITS,  './
denoised_ABS.wav');


save_file = clean_end;
wavwrite( 0.9/max(abs(save_file))*save_file ,FS,NBITS,  './
rebuild_clean.wav');