function handlesout = recal(handles, option)
% Update H(z)

N = 512;
pt = 25;

switch option
    case 'pole_to_poly'
        handles.a   = poly(handles.poleloc);
        handles.b   = poly(handles.zeroloc);
        handles.hz  = fftshift((fft(handles.k*handles.b,N))./(fft(handles.a,N)));
        handles.hn  = filter(handles.k*handles.b,handles.a,[1, zeros(1,pt-1)]);
    case 'poly_to_pole'
        handles.poleloc   = roots(handles.a).';
        handles.zeroloc   = roots(handles.b).';
        handles.hz  = fftshift((fft(handles.k*handles.b,N))./(fft(handles.a,N)));
        handles.hn  = filter(handles.k*handles.b,handles.a,[1, zeros(1,pt-1)]);
    otherwise
end

tol = 0.001;
n = length(handles.poleloc);
delete(findall(0,'tag','peztext'));
shift = 0.1;
    
if n ~= 0
    
    listpez = zeros(2,n);
    listpez(1,:) = nan;

    for i = 1:n
        listpez(1,i) = handles.poleloc(i);
        listpez(2,i) = 1;
        for j = 1:i-1
            if abs(real(handles.poleloc(i))-real(handles.poleloc(j)))<tol & abs(imag(handles.poleloc(i))-imag(handles.poleloc(j)))<tol
                listpez(1,i) = nan;
                listpez(2,j) = listpez(2,j) + 1;
            end
        end
    end

    multipez = find((listpez(2,:) > 1) & ~isnan(listpez(1,:)));

    if ~isempty(multipez)
        text(real(listpez(1,multipez))+shift,imag(listpez(1,multipez))+shift,...
            num2str(listpez(2,multipez).'),...
            'tag','peztext',...
            'parent',handles.axes_pzplot);
        text(real(listpez(1,multipez))+shift,imag(listpez(1,multipez))+shift,...
            num2str(listpez(2,multipez).'),...
            'tag','peztext',...
            'parent',handles.showplot_h.axes_pzplot);
    end    
    
end

n = length(handles.zeroloc);

if n ~= 0
    
    listpez = zeros(2,n);
    listpez(1,:) = nan;

    for i = 1:n
        listpez(1,i) = handles.zeroloc(i);
        listpez(2,i) = 1;
        for j = 1:i-1
            if abs(real(handles.zeroloc(i))-real(handles.zeroloc(j)))<tol & abs(imag(handles.zeroloc(i))-imag(handles.zeroloc(j)))<tol
                listpez(1,i) = nan;
                listpez(2,j) = listpez(2,j) + 1;
            end
        end
    end

    multipez = find((listpez(2,:) > 1) & ~isnan(listpez(1,:)));

    if ~isempty(multipez)
        text(real(listpez(1,multipez))+shift,imag(listpez(1,multipez))+shift,...
            num2str(listpez(2,multipez).'),...
            'tag','peztext',...
            'parent',handles.axes_pzplot);
        text(real(listpez(1,multipez))+shift,imag(listpez(1,multipez))+shift,...
            num2str(listpez(2,multipez).'),...
            'tag','peztext',...
            'parent',handles.showplot_h.axes_pzplot);        
    end    
    
end

% Zero-padding
m = length(handles.poleloc);
handles.pole0 = zeros(1,n-m);
if length(handles.pole0) > 1
    text(shift,shift,num2str(length(handles.pole0)),...
        'tag','peztext',...
        'parent',handles.axes_pzplot);
    text(shift,shift,num2str(length(handles.pole0)),...
        'tag','peztext',...
        'parent',handles.showplot_h.axes_pzplot);
end
handles.zero0 = zeros(1,m-n);
if length(handles.zero0) > 1
    text(shift,shift,num2str(length(handles.zero0)),...
        'tag','peztext',...
        'parent',handles.axes_pzplot);
    text(shift,shift,num2str(length(handles.zero0)),...
        'tag','peztext',...
        'parent',handles.showplot_h.axes_pzplot);
end

handlesout = handles;