% E04_1.m                     gr 16.3.18
% A simple highpass filter (and its zero-phase version) -- slide 04.1-36
clear all; clf;

b = [-6.76  13.45   -6.76];    % Set up the filter coefficients
zi = [0 0];    %  Set initial conditions to zero values
n = 0:99;   % Generate the two sinusoidal sequences
x1 = cos(0.1*n);
x2 = cos(0.4*n);
y = filter(b, 1, x1+x2, zi);   %  Generate the filter output sequence

% Note:
% y(0) = -6.76 * 2 * cos(0) = -13.52;   
% y(1) = 13.45 * 2 * cos(0) - 6.76 * ( cos(.1) + cos(.4) ) = 13.95

% y = filtfilt(b, 1, x1+x2);   %  zero-phase filter (slide 04.3-33)
% it cancels the delay but has a different freq. response in general

plot(n,y,'r-',n,x2,'b--',n,x1,'g-.');grid    
axis([0 100 -1.2 4]);
ylabel('Amplitude'); xlabel('Time index n');
legend('y[n]','x2[n]','x1[n]')

% fvtool(b,1);
