%demonstrace vlnek v obrazu pri pouziti ostreho cutoff-filtru


n=0:1:63;
sqw = [ones(1,32) -1*ones(1,32)];

ssp = fft(sqw);

%sharp filter mask
masks = [ones(1,4) zeros(1,60)];

%buffer filter mask
bfn = 1;
bD = 5;
maskb = 1./( 1+(n./bD).^(2*bfn));

%fitered with sharp:
sqw_fs=ifft(ssp.*masks);

%fitered with butter:
sqw_fb=ifft(ssp.*maskb);

%print:
figure(1);
clf;
PM=2;
PN=3;
%squarewave
subplot(PM,PN,1);
plot(sqw,'r'); grid on;
title('input sq.wave (black&white transitions)');

%sq. w. spectra
subplot(PM,PN,4);
stem(abs(ssp)); grid on;
title('spectra of squarewave');

%freq.filter response (sharp)
subplot(PM,PN,2);
plot(masks); grid on;
title('sharp filter');

%freq.filter response (butter)
subplot(PM,PN,5);
plot(maskb); grid on;
title('smooth (butterw) filt.');

%filterd sq with sharp:
subplot(PM,PN,3);
plot(n,sqw_fs); grid on;
title('response: sharp');

%filterd sq with butter:
subplot(PM,PN,6);
plot(n,sqw_fb); grid on;
title('response: butterworth');
