% FFT demo: process a sound signal and filter the low and high frequencies % % works only with N = 2k+1 samples % % this will not work as is in octave % % uncomment the sound commands below to hear the difference % % load cat [y,Fs,Nbits]=wavread('kitten20.wav'); % from freesound.org % make it a mono and floating point cat y = double(sum(y,2)/2); % truncate the signal so that it has 4k+1 samples y = y(1:end-1); % 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); F = 2000; % note: units are wrong! % window size WS = ceil((N-1)*(F/Fs)); LF( 1 + (N-1)/2 + (-WS:WS) ) = 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