% FFT demo: process a sound signal and filter the low and high frequencies
%
%  works only with N = 4k+1 samples 
%
%  this will not work as is in octave
%
%  uncomment the sound commands below to hear the difference
%

% load one of Matlab's default sounds
load handel
% sound(y,Fs); % play signal
figure(1);
plot(y);
N = length(y);

Y = fft(y);       % zero frequency is first element of vector Y
Ys = fftshift(Y); % puts zero frequency in the middle of vector Ys

% plot spectrum of sound signal
figure(2);
Y = plot(abs(Ys));


% low pass filter: a frequency window centered at zero frequency
LF = zeros(N,1);
LF( 1 + (N-1)/2 + (-(N-1)/4:(N-1)/4) ) = 1;
YL = ifftshift(Ys.*LF);
yl = ifft(YL);
% sound(yl,Fs); % play signal

% high pass filter: everything that blocked by the low pass filter
HF = 1-LF;
YH = ifftshift(Ys.*HF);
yh = ifft(YH);
% sound(yh,Fs); % play signal

