
% Butter filter example

Fs = 8192;
n = 0:2*Fs; % 2 seconds of samples

% Input signals
F1 = 1000;
x1 = 0.5*cos(2*pi*F1/Fs*n);
F2 = 2000;
x2 = 0.5*cos(2*pi*F2/Fs*n);
x = 0.5*x1 + 0.5*x2;

% Play sounds
sound(x1,Fs);
sound(x2,Fs);
sound(x,Fs);

% Create Butterworth filter
N = 5;
Wn = 0.3; % Note normalization where fs/2 correstponds to 1
[B,A] = butter(N,Wn);

% View zero pole plot
figure(1); zplane(B,A);

% Plot responce
figure(2); freqz(B,A);

% Filter signal
y = filter(B,A,x);
sound(y,Fs);
sound(x1,Fs);



