
% Notch filter demo

% Input signal
Fs = 8192;
n = 0:2*Fs; % 2 seconds of samples
F1 = 1000;
x1 = 0.5*cos(2*pi*F1/Fs*n);
F2 = 2000;
x2 = 0.5*cos(2*pi*F2/Fs*n);
x = 0.1*x1 + (1-0.1)*x2;

% Zeros and poles
phi = 2*pi*F2/Fs;
z1 = exp(j*phi);
p1 = 0.999*exp(j*phi);

% Create filter vectors
B = (1/0.1)*real(conv([1 -z1],[1 -z1']))
A = real(conv([1 -p1],[1 -p1']));

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

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

sound(x,Fs); % Play composite sound
y = filter(B,A,x); % Filter with notch filter
sound(y,Fs); % Play filtered sound
sound(x1,Fs); % Play original clean signal
