close all;clear
h=[1/4;1/2;1/4]
Ngraph=256

[H,w]=freqz(h,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)')

[H,w]=freqz(h,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)')

figure
freqz(h,1,Ngraph,1)

figure
freqz(h,1,Ngraph) % Misleading! (Matlab "convention")

htimes2=h*2
figure
freqz(htimes2,1,Ngraph,1)

figure
grpdelay(h,1,Ngraph,1)


fft(h)
figure
bar(abs(fft(h)))

h8=[h;0;0;0;0;0]
fft(h8)
figure
bar([0:7],abs(fft(h8)))

hN=[h;zeros(Ngraph-length(h),1)];
figure
bar(abs(fft(hN)))
figure
plot(abs(fft(hN)))
figure
plot([0:Ngraph-1].'/Ngraph,abs(fft(hN)))
figure
plot([0:Ngraph-1].'/Ngraph,20*log10(abs(fft(hN))))

h=kaiser(30,3)/20;

[H,w]=freqz(h,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)')

figure
freqz(h,1,Ngraph,1)

figure
grpdelay(h,1,Ngraph,1)

figure
plot(f(1:end-1),diff(unwrap(angle(H))/(2*pi))./diff(f));title('Group Delay')

