function [clean] = method1(corrupt, noise, cleanphrase)

% use these functions first
% noise=wavread('noise');
% corrupt=wavread('corrupt');
% cleanphrase=wavread('cleanphrase');


[N, trash]=size(corrupt);

noise=noise(1:N);
corruptFFT=fft(corrupt);
noiseFFT=fft(noise);

DELTAF=1/(N*1/11025);
FREQ=0:DELTAF:11025/2;
FREQ=FREQ';

figure(1)
plot(FREQ(1:N/2), abs(noiseFFT(1:N/2)));
figure(2)
plot(FREQ(1:N/2), abs(corruptFFT(1:N/2)));

npc = abs(noiseFFT) .* abs(noiseFFT);
% npc = powerspectrum of the noise
cpc = abs(corruptFFT) .* abs(corruptFFT);

cleanSound= cpc-npc;
for n = 1:N,
    if cleanSound(n) < 0
        cleanSound(n) = 0;
    end
end 

cleanSound = sqrt(cleanSound);
phase = angle(corruptFFT);
superClean = cleanSound.*cos(phase)+i*cleanSound.*sin(phase);
figure(3)
plot(FREQ(1:N/2), abs(superClean(1:N/2)));

clean = real(ifft(superClean));

SOUNDSC(real(clean), 11025);
pause
SOUNDSC(corrupt, 11025);
pause
SOUNDSC(cleanphrase, 11025);

