% Demonstrate how flatness is related to killing polynomial signals
N = 256;
T = (2/N)*((-N/2+1):N/2);
dt = (T(N)-T(1))/N;
X0 = ones(size(T));
X1 = T;
X2 = T.^2;
X3 = T.^3;
figure(1)
plot(T,X0,T,X1,T,X2,T,X3);
title('power signals')
disp('Press a key')
pause

h1 = [1 -1]/dt;
hX0 = circconv(X0,h1);
hX1 = circconv(X1,h1);
hX2 = circconv(X2,h1);
hX3 = circconv(X3,h1);

s = [length(h1):length(T)-length(h1)];

figure(2)
plot(T(s),hX0(s),T(s),hX1(s),T(s),hX2(s),T(s),hX3(s));
title('power signals filtered once')
disp('Press a key')
pause

h2 = conv(h1,h1);
hX0 = circconv(X0,h2);
hX1 = circconv(X1,h2);
hX2 = circconv(X2,h2);
hX3 = circconv(X3,h2);

s = [length(h2):length(T)-length(h2)];

figure(3)
plot(T(s),hX0(s),T(s),hX1(s),T(s),hX2(s),T(s),hX3(s));
title('power signals filtered twice')
disp('Press a key')
pause

figure(4)
h1e = [h1,zeros(1,N-length(h1))];
h2e = [h2,zeros(1,N-length(h2))];
h1e = h1e/sum(abs(h1e)); % normalize filters
h2e = h2e/sum(abs(h2e));
FD = (0:(N-1))-N/2;
plot(FD, fftshift(abs(fft(h1e))),FD, fftshift(abs(fft(h2e))));