%
%  In lecture, we saw two simple examples of a (nonideal) lowpass filter and highpass filter:
%

w = -pi:.01:pi;
LPF = (1 + exp(j.*w))./2;
HPF = 1 - exp(j.*w);
figure;
subplot(2,2,1); plot(w,abs(LPF)); title('LPF frequency response magnitude');
subplot(2,2,2); plot(w,angle(LPF)); title('LPF frequency response phase');
subplot(2,2,3); plot(w,abs(HPF)); title('HPF frequency response magnitude');
subplot(2,2,4); plot(w,angle(HPF)); title('HPF frequency response phase');

%
%  Try this at home!
%  Apply 2-D versions of these simple lowpass and highpass filters to
%  goldhill.gif, which can be downloaded here:
%  http://links.uwaterloo.ca/greyset2.base.html
%  You can try any of the other images in the same directory,
%  but don't forget to replace 'goldhill' with 'image_name' below.
%

A = imread('goldhill.gif','gif');
A = double(A);
figure;
imagesc(A);
colormap(gray);
title('Original Goldhill Image');


ll = [1/4 1/4; 1/4 1/4];
hh = [1 -1; -1 1];
hl = [1/2 -1/2; 1/2 -1/2];
lh = [1/2 1/2; -1/2 -1/2];


LL = conv2(A,ll);
HH = conv2(A,hh);
HL = conv2(A,hl);
LH = conv2(A,lh);
figure;
subplot(2,2,1); imagesc(LL); colormap(gray); title('LL filtered');
subplot(2,2,2); imagesc(HL); colormap(gray); title('HL filtered');
subplot(2,2,3); imagesc(LH); colormap(gray); title('LH filtered');
subplot(2,2,4); imagesc(HH); colormap(gray); title('HH filtered');

%
%  What happens when you apply the same filters to the LL filtered output above?
%

LL2 = conv2(LL,ll);
HH2 = conv2(LL,hh);
HL2 = conv2(LL,hl);
LH2 = conv2(LL,lh);
figure;
subplot(2,2,1); imagesc(LL2); colormap(gray); title('LL*LL');
subplot(2,2,2); imagesc(HL2); colormap(gray); title('LL*HL');
subplot(2,2,3); imagesc(LH2); colormap(gray); title('LL*LH');
subplot(2,2,4); imagesc(HH2); colormap(gray); title('LL*HH');


