%clear
%0close all

z_re = linspace(-2,2,1e3);
z_im = linspace(-2,2,1e3);
[Zre,Zim] = meshgrid(z_re,z_im);

poles = [];
zeros = [-1];
k = 1/2;

Z = Zre + 1i*Zim;

if isempty(zeros)
    num = 1;
else
    num = reshape(prod(bsxfun(@minus,Z(:),zeros),2),size(Z,1),size(Z,2));
end
if isempty(poles)
    denum = 1;
else
    denum = reshape(prod(bsxfun(@minus,Z(:),poles),2),size(Z,1),size(Z,2));
end
H = k*num./denum;

figure
subplot(1,2,1)
pcolor(z_re, z_im, 20*log10(abs(H))); shading interp
hold on
fi = linspace(0,2*pi,60);
plot( cos( fi ), sin( fi ), '--w' )
axis equal tight
subplot(1,2,2)
surf(z_re, z_im, 20*log10(abs(H))); shading interp
hold on
fi = linspace(0,2*pi,60);
plot( cos( fi ), sin( fi ), '--w' )
%%
w = 2*pi*linspace(0,1,100);
zout = exp(1i*w');
H0 = H(:);
Z0 = Z(:);
h_out = 0*zout;
for j = 1 : length(zout)
    [~,ind] = min(abs(zout(j)-Z0));
    h_out(j) = H0(ind);
end
figure
plot(w,abs(h_out));
