% file: task23.m
% (1) create 3 cosines
Fs  = 10000;  % sampling frequency 10 kHz
t   = [1 : 10000]/Fs;  % time-axis
x1  = 2 * cos(2*pi*250*t);
x2  = 3 * cos(2*pi*2500*t + pi/4);
x3  = 1 * cos(2*pi*4700*t - pi/5);
x   = x1 + x2 + x3;
xF  = fft(x); % Fourier-transform
w   = linspace(0, Fs, length(xF)); % freq. axis
figure(1); clf; subplot(3,1,1);
plot(w, abs(xF));
hold on; xlabel('frequency (Hz)'); grid on;
axis([0 Fs/2 0 max(abs(xF))]);  % zoom

% (2) highpass filter
B   = [1  -1];
A   = [1  1.7  0.72];
[H, f] = freqz(B, A, 1024, Fs);
subplot(3,1,2); 
plot(f, abs(H));  grid on;

% (3) filter the signal
y   = filter(B, A, x);
yF  = fft(y);
subplot(3,1,3);
plot(w, abs(yF)); grid on;
axis([0 Fs/2 0 max(abs(yF))]);  % zoom

% quickly: sptool