% butter_filter.m  4th order Butterworth filter
[b, a] = butter(4, [0.01, 0.1]);   % b and a are filter coefficients.  They define filter.
                                   % 4 = # poles of filter.  More poles means sharper
                                   %   cutoff frequencies.
                                   % This filter lets frequencies between 0.01 and 1.0
                                   %  times the frequency for the sampling rate / 2.

% load handel
y = randn(1,16000);   % Generate some noise.  Sounds like a hiss.  2 seconds long.
y = y(1:16000);

% Plot the spectrum of the noise signal.
plot(abs(fft(y)))

% Filter y using filter defined by coefficients in a and b.
vo_t = filter(b,a,y);  % Apply digital filter

% Play the sound.
y = vo_t;
y = y*10;  % Make the sound a bit louder.  Most of it was filtered out.
sound(y)

% Plot the spectrum to show the frequencies that got thru the filter.
plot(abs(fft(vo_t)))
