% real_fft.m  Demo of changing spectrum of sound
%
% Takes fft (Fast Fourier Transform) of snippet from Handel's "Messiah",
% Takes real part of fft, (fft is complex,
%  it is equivalent to phasors for the frequencies in the signal).
% Takes ifft (Inverse FFT) of the result to get back to time domain.
% Takes real part of time-domain signal.  (This turns out to be unnecessary, but
%   we do this step because it is a reminder that in other alterations of the
%   spectrum it may be necessary.)

% Get snippet of sound.
load handel

y = y(1:24000);  % 3 sec of sound

% vi_t is input sound
vi_t = y;

% Find spectrum of input sound by taking Fast Fourier Transform
Vi_k = fft(vi_t);   % Freq domain signal

% Filter by removing imaginary part of spectrum
Vo_k = real(Vi_k);

% Convert back to time domain
vo_t = real(ifft(Vo_k));  % Signal must be real in time domain.

% Create array of time samples
t = 0:1/8000:3;

% Remove last sample so size matches sound
t(end) = [ ];

% Put final sound in y so "listen" script may be used, if desired.
y = vo_t;

% Plot first part of sound waveform as blue line.
plot(t(1:200),vo_t(1:200),'b-')

% listen to sound
sound(y)

% Done.  Return to command prompt.
return

