close all;clear
n=[0:15].'
N=length(n)

fc=[0:N/2]./N
fcl = length(fc)
cossigs=cos(2*pi*n*fc)

figure
for m=1:fcl
   subplot(fcl,1,m);bar(n,cossigs(:,m))
   axis([n(1)-0.5 n(end)+0.5 -1 1])
   ylabel(num2str(fc(m)))
end
subplot(fcl,1,1);title('cos(2\pi fc n)')
subplot(fcl,1,fcl);xlabel('n')

h3pt = [1 1 1].'/3

ycos=filter(h3pt,1,cossigs)

figure
for m=1:fcl
    subplot(fcl,1,m);bar(n,ycos(:,m))
    axis([n(1)-0.5 n(end)+0.5 -1 1])
    ylabel(num2str(fc(m)))
end
subplot(fcl,1,1);title('filtered cos(2\pi fc n)')
subplot(fcl,1,fcl);xlabel('n')

h3ptN = [h3pt;zeros(N-length(h3pt),1)];
fk = [0:N-1].'/N;
figure
subplot(2,1,1);bar(fk,abs(fft(h3ptN)));axis tight;title('|H|')
 xlabel('f');ylabel('magnitude')
subplot(2,1,2);bar(fk,unwrap(angle(fft(h3ptN)))/(2*pi));title('\angle H')
 xlabel('f');ylabel('phase (cyles)')

Ngraph=256;

[H,w]=freqz(h3pt,1,Ngraph);
f = w/(2*pi);
figure
subplot(2,1,1);plot(f,abs(H));title('|H|');xlabel('f');ylabel('magnitude')
subplot(2,1,2);plot(f,unwrap(angle(H))/(2*pi));title('\angle H')
 xlabel('f');ylabel('phase (cyles)')

[H,w]=freqz(h3pt,1,Ngraph,'whole');
f = w/(2*pi);
figure
subplot(2,1,1);plot(f,abs(H));title('|H|');xlabel('f');ylabel('magnitude')
subplot(2,1,2);plot(f,unwrap(angle(H))/(2*pi));title('\angle H')
 xlabel('f');ylabel('phase (cyles)')

