function handlesout = initialize_pez(handles_main,filename)

% Globals
handles_main.LineWidth  = 2;
showgphhandles          = showgph;

% Update Show Plot colors
set(showgphhandles,'color',get(handles_main.figure_pez,'color'));
set(findobj(showgphhandles,'style','text')','back',get(handles_main.figure_pez,'color'));
handles_showplot = guihandles(showgphhandles);

%--- Correct Slider Position ---
apos = get(handles_main.axes_pzplot,'position');
spos = get(handles_main.slider,'position');
set(handles_main.slider,'position',[apos(1)+apos(3)-spos(3) apos(2)+apos(4) spos(3) spos(4)]);  
%------------------------------
handles_main.linemag     = line (0,0,'LineWidth',handles_main.LineWidth,'Parent',handles_main.axes_mag);
handles_main.linephase   = line (0,0,'LineWidth',handles_main.LineWidth,'Parent',handles_main.axes_phase);

handles_main.lineimpimg_cir = line (0,0,...
                                'Parent',handles_main.axes_imp,...
                                'LineStyle','None',...
                                'Marker','o',...
                                'Color',[1,0,1],...
                                'LineWidth',handles_main.LineWidth,...                                
                                'Visible', 'off');
handles_main.lineimpimg_lin = line (0,0,...
                                'Parent',handles_main.axes_imp,...
                                'LineStyle','-',...
                                'Color',[1,0,1],...
                                'LineWidth',handles_main.LineWidth,...                                
                                'Visible', 'off');
                            
handles_main.lineimp_cir = line (0,0,...
                                'Parent',handles_main.axes_imp,...
                                'LineStyle','None',...
                                'Marker','o',...
                                'Color',[0,0,1],...
                                'LineWidth',handles_main.LineWidth,...
                                'MarkerFaceColor',[0,0,1]);
handles_main.lineimp_lin = line (0,0,...
                                'Parent',handles_main.axes_imp,...
                                'LineStyle','-',...
                                'LineWidth',handles_main.LineWidth,...                                
                                'Color',[0,0,1]);
    
%------- Plot Pole Zero plot background -------%
handles_main.linepezx   = line (zeros(1,length([-3:0.5:3])),[-3:0.5:3],...
                                'Parent',handles_main.axes_pzplot,...
                                'Color',[0,0,0],...
                                'LineStyle',':',...
                                'HitTest','off');
                       %         'EraseMode', 'Xor');
handles_main.linepezy   = line ([-3:0.5:3],zeros(1,length([-3:0.5:3])),...
                                'Parent',handles_main.axes_pzplot,...
                                'Color',[0,0,0],...
                                'LineStyle',':',...
                                'HitTest','off');
                                %,...
                                %'EraseMode', 'Xor');
handles_main.linepezuc  = line (sin(0:2*pi/20:2*pi),cos(0:2*pi/20:2*pi),...
                                'Parent',handles_main.axes_pzplot,...
                                'Color',[0,0,0],...
                                'LineStyle',':',...
                                'HitTest','off');
                                %,...
                                %'EraseMode', 'Xor');
                            
handles_main.pzpatch = patch([5,5,-5,-5],[5,-5,-5,5], [1,0.6,0.6],...
                            'EraseMode','background',...
                            'HitTest','off',...
                            'Visible','off',...
                            'Parent', handles_main.axes_pzplot);                            
handles_main.ucpatch = patch(sin(0:2*pi/20:2*pi),cos(0:2*pi/20:2*pi), 'w',...
                            'EraseMode','background',...
                            'HitTest','off',...
                            'Visible','off',...
                            'Parent', handles_main.axes_pzplot);

%----------------------------------------------%
handles_main.linepezpole = line ( 0,0,...
                                'Parent',handles_main.axes_pzplot,...
                                'Marker','x',...
                                'MarkerSize',10,...
                                'HitTest','off',...
                                'LineStyle','none',...
                                'LineWidth',handles_main.LineWidth,...                                
                                'EraseMode','normal');
handles_main.linepezzero = line ( 0,0,...
                                'Parent',handles_main.axes_pzplot,...
                                'Marker','o',...
                                'MarkerSize',8,...
                                'HitTest','off',...
                                'LineStyle','none',...
                                'LineWidth',handles_main.LineWidth,...
                                'EraseMode','normal');

handles_main.selectedpole = line ( 0,0,...
                                'Parent',handles_main.axes_pzplot,...
                                'Marker','x',...
                                'MarkerSize',10,...
                                'HitTest','off',...
                                'Color',[1,0,1],...
                                'LineStyle','none',...
                                'LineWidth',handles_main.LineWidth,...                                
                                'EraseMode','normal');
handles_main.selectedzero = line ( 0,0,...
                                'Parent',handles_main.axes_pzplot,...
                                'Marker','o',...
                                'MarkerSize',8,...
                                'HitTest','off',...
                                'Color',[1,0,1],...
                                'LineStyle','none',...
                                'LineWidth',handles_main.LineWidth,...                                
                                'EraseMode','normal');

set(handles_main.linepezpole,'XData',[],'YData',[]);
set(handles_main.linepezzero,'XData',[],'YData',[]);

set(handles_main.selectedpole,'XData',[],'YData',[]);
set(handles_main.selectedzero,'XData',[],'YData',[]);

% Showplot %
%----------------------------------------------%
handles_showplot.linemag     = line (0,0,'LineWidth',handles_main.LineWidth,'Parent',handles_showplot.axes_mag);
handles_showplot.linephase   = line (0,0,'LineWidth',handles_main.LineWidth,'Parent',handles_showplot.axes_phase);

handles_showplot.lineimpimg_cir = line (0,0,...
                                'Parent',handles_showplot.axes_imp,...
                                'LineStyle','None',...
                                'Marker','o',...
                                'Color',[1,0,1],...
                                'LineWidth',handles_main.LineWidth,...                                
                                'Visible','off');
handles_showplot.lineimpimg_lin = line (0,0,...
                                'Parent',handles_showplot.axes_imp,...
                                'LineStyle','-',...
                                'Color',[1,0,1],...
                                'LineWidth',handles_main.LineWidth,...                                
                                'Visible','off');
handles_showplot.lineimp_cir = line (0,0,...
                                    'Parent',handles_showplot.axes_imp,...
                                    'LineStyle','None',...
                                    'Marker','o',...
                                    'Color',[0,0,1],...
                                    'LineWidth',handles_main.LineWidth,...                                    
                                    'MarkerFaceColor',[0,0,1]);
handles_showplot.lineimp_lin = line (0,0,...
                                    'Parent',handles_showplot.axes_imp,...
                                    'LineStyle','-',...
                                    'LineWidth',handles_main.LineWidth,...                                    
                                    'Color',[0,0,1]);

                            
%------- Plot Pole Zero plot background -------%
handles_showplot.linepezx   = line (zeros(1,length([-3:0.5:3])),[-3:0.5:3],...
                                    'Parent',handles_showplot.axes_pzplot,...
                                    'Color',[0,0,0],...
                                    'LineStyle',':',...
                                    'HitTest','off',...
                                    'EraseMode', 'Xor');
handles_showplot.linepezy   = line ([-3:0.5:3],zeros(1,length([-3:0.5:3])),...
                                    'Parent',handles_showplot.axes_pzplot,...
                                    'Color',[0,0,0],...
                                    'LineStyle',':',...
                                    'HitTest','off',...
                                    'EraseMode', 'Xor');
handles_showplot.linepezuc  = line (sin(0:2*pi/20:2*pi),cos(0:2*pi/20:2*pi),...
                                    'Parent',handles_showplot.axes_pzplot,...
                                    'Color',[0,0,0],...
                                    'LineStyle',':',...
                                    'HitTest','off',...
                                    'EraseMode', 'Xor');
handles_showplot.pzpatch = patch([5,5,-5,-5],[5,-5,-5,5], [1,0.6,0.6],...
                            'EraseMode','background',...
                            'HitTest','off',...
                            'Visible','off',...
                            'Parent', handles_showplot.axes_pzplot);                            
handles_showplot.ucpatch = patch(sin(0:2*pi/20:2*pi),cos(0:2*pi/20:2*pi), 'w',...
                            'EraseMode','background',...
                            'HitTest','off',...
                            'Visible','off',...
                            'Parent', handles_showplot.axes_pzplot);
                        
%----------------------------------------------%
handles_showplot.linepezpole = line (0,0,...
                                    'Parent',handles_showplot.axes_pzplot,...
                                    'Marker','x',...
                                    'MarkerSize',10,...
                                    'LineStyle','none',...
                                    'LineWidth',handles_main.LineWidth,...
                                    'HitTest','off',...
                                    'EraseMode','normal');
handles_showplot.linepezzero = line (0,0,...
                                    'Parent',handles_showplot.axes_pzplot,...
                                    'Marker','o',...
                                    'MarkerSize',8,...
                                    'LineStyle','none',...
                                    'LineWidth',handles_main.LineWidth,...
                                    'HitTest','off',...
                                    'EraseMode','normal');
handles_showplot.selectedpole = line ( 0,0,...
                                    'Parent',handles_showplot.axes_pzplot,...
                                    'Marker','x',...
                                    'MarkerSize',10,...
                                    'HitTest','off',...
                                    'Color',[1,0,1],...
                                    'LineStyle','none',...
                                    'LineWidth',handles_main.LineWidth,...                                    
                                    'EraseMode','normal');
handles_showplot.selectedzero = line ( 0,0,...
                                    'Parent',handles_showplot.axes_pzplot,...
                                    'Marker','o',...
                                    'MarkerSize',8,...
                                    'HitTest','off',...
                                    'Color',[1,0,1],...
                                    'LineStyle','none',...
                                    'LineWidth',handles_main.LineWidth,...
                                    'EraseMode','normal');                                

set(handles_showplot.linepezpole,'XData',[],'YData',[]);
set(handles_showplot.linepezzero,'XData',[],'YData',[]);
set(handles_showplot.selectedpole,'XData',[],'YData',[]);
set(handles_showplot.selectedzero,'XData',[],'YData',[]);

%----------------------------------------------%
% Set Ray Lines
handles_main.lineray_main  = line([0 1/sqrt(2)],[0 1/sqrt(2)], ...
    'parent',handles_main.axes_pzplot, ...
    'ButtonDownFcn',[filename,'(''startdrag_RAY'',[],[],guidata(gcbo))'], ...
    'color','r','LineWidth',handles_main.LineWidth,'vis','on');
handles_main.lineray_mag   =  line([pi/4 pi/4],[-2 4],'parent',handles_main.axes_mag, ...
    'color','r','LineWidth',handles_main.LineWidth,'vis','on');
handles_main.lineray_phase = line([pi/4 pi/4],[-4 4],'parent',handles_main.axes_phase, ...
    'color','r','LineWidth',handles_main.LineWidth,'vis','on');
%----------------------------------------------%
handles_main.k          = 1;
handles_main.a          = [];
handles_main.b          = [];
handles_main.hz         = [];
handles_main.hn         = [];
handles_main.poleloc    = [];
handles_main.zeroloc    = [];
handles_main.showplot_h = handles_showplot;
handles_main.connection = [];
handles_main.connecttype= [];
handles_main.tempvalue  = [];
handles_main.repeatedadd= 'off';
handles_main.changed    = 'off';
handles_main.text       = [];

handles_main.pole0      = [];
handles_main.zero0      = [];

handles_main.textcolor = findobj(handles_main.figure_pez,'tag','realtxtcolor');

handles_main.outparm             = [];
handles_main.outparm.poleconnect = [];
handles_main.outparm.zeroconnect = [];
handles_main.outparm.type        = [];

handles_main.pezpb = [findall(0,'tag','pb_pp'), findall(0,'tag','pb_zz'), findall(0,'tag','pb_pz'),...
                   findall(0,'tag','pb_-p'), findall(0,'tag','pb_-z'), findall(0,'tag','pb_-a')];

set(handles_main.figure_pez,'HandleVisibility','on', ...
    'WindowButtonMotionFcn',[filename,'(''WindowButtonMotion'',[],[],guidata(gcbo))'], ...
    'WindowButtonUpFcn',[filename, '(''resetclickpt'', [],[],guidata(gcbo))']);
handles_main.grp_zoomtag    = [findobj(handles_main.figure_pez,'Tag','zoom25');...
                               findobj(handles_main.figure_pez,'Tag','zoom50');...
                               findobj(handles_main.figure_pez,'Tag','zoom100');...
                               findobj(handles_main.figure_pez,'Tag','zoom200')];
handles_main.grp_widthtag   = [findobj(handles_main.figure_pez,'Tag','width1');...
                               findobj(handles_main.figure_pez,'Tag','width2');...
                               findobj(handles_main.figure_pez,'Tag','width3');...
                               findobj(handles_main.figure_pez,'Tag','width4')];
handles_main.grp_colortag   = [findobj(handles_main.figure_pez,'Tag','colorblack');...
                               findobj(handles_main.figure_pez,'Tag','colorblue');...
                               findobj(handles_main.figure_pez,'Tag','colorred');...
                               findobj(handles_main.figure_pez,'Tag','colorgreen');...
                               findobj(handles_main.figure_pez,'Tag','coloryellow')];
set(handles_main.figure_pez,'HandleVisibility','off');

handles_main = recal(handles_main, 'pole_to_poly');
handles_main = plot_gph(handles_main);

set(findall(0,'tag','tb_addconjugate'), 'Value', 1);
handlesout = handles_main;