function discrete_time_notch_zeros_poles_demo()
clf;

r = 0.9; % Radius of pole
f = 0.1; % Frequency of pole
make_plot(r,f);

hui = uicontrol('style','slider','value',r,'min',0,'max',1,...
                'position',[10 10 300 20],'callback',{@nestfunc});

huj = uicontrol('style','slider','value',f,'min',0,'max',0.5,...
                'position',[400 10 300 20],'callback',{@nestfunc});

function [num,den]=make_sys(r,f)
    w = 2*pi*f;
    num = [1,-2*cos(w),1];
    den = [1,-2*r*cos(w),r^2];
    num = num*(sum(den)/sum(num));
end
    
function make_plot(r,f)
    NFFT = 2^10;
    [num,den]=make_sys(r,f);
    subplot(221);
    zplane(num,den);
    [H,W]=freqz(num,den,NFFT,'whole');
    f = W/pi;
    subplot(222);
    plot(f,20*log10(abs(H)));
    subplot(223);
    plot(f,angle(H),'b'); hold on;
    plot(f,phase(H),'Color',[0 0.5 0]); hold off;
    subplot(224);
    [G,W]=grpdelay(num,den,NFFT,'whole');
    plot(f,G);
end

function nestfunc(src,evd)
r = get(hui,'Value');
f = get(huj,'Value');
make_plot(r,f);
end

end

