% extract signal from sine curves (with noise)
i512 = (0:511);
S1 = sin(i512/45056*2*pi*440);
S2 = .5*sin(i512/45056*2*pi*880);
S12 = S1 + S2;
fS1=abs(fft(S1));
fS12 = abs(fft(S12));
figure(1), hold off, clf, plot(i512,S1), axis([0 511,-1,1])
title('Signal at 440 Hz, for .01 secs, sampled at 45KHz')
xlabel('x(i) = sin(2*pi*400*t(i)) with t(i) = i/45056')
pause
figure(2),hold off, clf, plot(i512,S12), axis([0 511,-1.5,1.5])
title('Sum of signals at 440, 880 Hz, for .01 secs, sampled at 45KHz')
xlabel('x(i) = sin(2*pi*440*t(i)) + .5*sin(2*pi*880*t(i)) with t(i) = i/45056')
pause
i100=(0:99)';
figure(3), hold off, clf, plot(i100,fS1(1:100),'+'), 
title('FFT of signal at 440 Hz')
pause
figure(4), hold off, clf, plot(i100,fS12(1:100),'+'), 
title('FFT of signal at 440 + 880 Hz')
S12n = S12 + (rand(size(i512))-.5);
pause
figure(5), hold off, clf, plot(i512,S12n), axis([0 511,-2,2])
title('Sum of signals at 440, 880 Hz + noise'),
pause
fS12n = abs(fft(S12n));
figure(6), hold off, clf, plot(i100,fS12n(1:100),'+'), 
title('FFT of signal + noise')