function [clean] = method3(corrupt, frequency)
% Fighting Corrupt Speech: method3
% <cleaned-data> = method3( <corrupt-data>, <frequency> )
%
% Attempts to clean up the corrupt voice data by simply
% removing the specified frequencies and its harmonics.
%
% This function takes the corrupt signal, as read
% by the wavread function, and the frequency (in Hz) to
% filter out.  The function assumes 11.025 kHz 
% recording.  Example usage:
%
% >> corrupt = wavread('corrupt');
% >> data = method3(corrupt, 385);
% >> soundsc(data, 11025);
%

% subtract the dc offset from the input
corrupt = losedcoff(corrupt);

corruptFFT = fft(corrupt);
[N, trash] = size( corruptFFT );

FS = 11025;
Ts = 1/FS;
DELTAF = 1 / ( N * Ts );
FREQ = 0:DELTAF:FS/2;
FREQ = FREQ';
size(FREQ)
plot(FREQ(1:N/2), abs(corruptFFT(1:N/2)));
pause

F = frequency;
while F < FS/2
   
    for I=1:N/2
        if FREQ(I) > F-5 & FREQ(I) < F+5
            corruptFFT(I) = corruptFFT(I) * 0.001;
            corruptFFT(N-I) = corruptFFT(N-I) * 0.001;
        end
    end
       
    F = F + frequency;
end

plot(FREQ(1:N/2), abs(corruptFFT(1:N/2)));
title('Rebuilt Speech Data After method3 Processing (f=385Hz)');
clean = real(ifft(corruptFFT));




