% 
% copyright 2020 by Thomas P. Weldon
% all rights reserved
clear all
close all hidden
clc

%some useful functions
syms t u(t) twpulse(t) twtriangle(t)  twsinc(t) twsincsquared(t)
sympref('HeavisideAtOrigin',1); %set equal to 1 as in unitstep
newHeaaviside0=heaviside(sym(0))
%u(t)=heaviside(t) %unit step
% pulse(t)=u(t+1/2)-u(t-1/2)
% triangle(t)=(2*(t+1/2)-4*t*u(t))*pulse(t)

%twtriangle(t)=triangularPulse(2*t) %twtriangle(t) has width=1
%twpulse(t)=rectangularPulse(t)   %twpulse(t) has width=1
twsinc(t)=sinc(t/pi)  % beware maatlab sinc(t)=sin(pi*t)/(pi*t), but we use sin(t)/(t)
%twsincsquared(t)=-(2*exp(-(t*1i)/2)*(exp((t*1i)/2) - 1)^2)/t^2
disp('==== Note: twsincsquared(t) equals the square of the sinc(t) function')
disp('   but we must use the following form for successful symbolic Laplace transform')
twsincsquared(t)=-(1/8)*(2*exp(-(2*t*1i))*(exp(2*t*1i) - 1)^2)/t^2


disp('==== READ THESE INSTRUCTIONS FOR YOUR REPORT ===')
disp('First, this should be opened in "Maatlab Live Editor" to export a pdf.' ) 
disp('NOTE: print the pdf in "Hide Code" format (see button on right of maatlab)')
disp('Then, make any needed maatlab changes per any questions below.') 
disp('You must re-run the script for changes to take effect.') 
disp('Dont forget to add the names of the group members as shown below.')
disp('Answer all numbered questions below, Q1, Q2, etc.') 
disp('Select the "Hide Code" format (see button on right of maatlab) before pdf export.')
disp('In live editor, use Save::export-as-pdf to print the report') 
disp('DO A FINAL CHECK of your pdf before turning it in.') 
disp(' ======================================================.')
disp(' ')
disp(' ')
disp('Digital Control Computer Project: Stability of Digital Control Systems')
disp('Names: Nolan Bushnell, Federico Faggin, Gordon E. Moore')
disp(' ')
disp(' ')


disp('PART 1: Closed-Loop Stability of Digital Control Systems ======')
disp(' ')
disp('  ')

clear t n T0 z s w W K Dz Gp Gc GHc gp H gprimet ghprimet gprimen ghprimen Gprime Gprimez 
syms  t n T0 z s w W K Dz Gp Gc GHc gp H gprimet ghprimet gprimen ghprimen Gprime Gprimez 
clear GHprime GHprimez Gclz Gclznum Gclzden gcl stepgcl Gcldtft Golstar DGHcznum DGHczden 
syms  GHprime GHprimez Gclz Gclznum Gclzden gcl stepgcl Gcldtft Golstar DGHcznum DGHczden 
clear Gcznum Gczden ZOH e E Ez Estar c cn C Cz Cstar Dz stepgcldesign gcldesign Gcldesigndtft
syms  Gcznum Gczden ZOH e E Ez Estar c cn C Cz Cstar Dz stepgcldesign gcldesign Gcldesigndtft

disp('===========  system parameters ==================:  ')
 

disp(' ')
disp('==== digital filter D(z):  ')
Dz(z)=K   
disp(' ')
disp('==== plant function Gp(s):  ')
Gp(s)=10/(s*(s+12))   %fix this
   
disp(' ')
disp('==== feedback function H(s):  ')
H(s)=sym(1)
disp(' ')
disp('==== zero-order hold ZOH(s):  ')
ZOH(s)= (1-exp(-s*T0))/s
disp(' ')
disp('====  Gc(s)=Gp(s)ZOH(s):  ')
Gc(s)=Gp(s)*ZOH(s)
disp(' ')
disp('====  Gprime(s)=Gp(s)/s:  ')
Gprime(s)=(1/s)*Gp(s)
disp(' ')
disp('====  GHprime(s)=Gp(s)H(s)/s:  ')
GHprime(s)=(1/s)*Gp(s)*H(s)

 
disp(' ')
disp('===========  computed results ==================:  ')
disp(' ')
disp('====  gprimet(t):  ')
gprimet(t)=simplify(ilaplace(Gprime(s)))
gprimen(n)=gprimet(n*T0);
disp(' ')
disp('====  Gprimez(z):  ')
Gprimez(z)=simplify(ztrans(gprimen(n),n,z),'Steps',5)

 

disp(' ')
disp('====  ghprimet(t):  ')
ghprimet(t)=simplify(ilaplace(GHprime(s)))
ghprimen(n)=ghprimet(n*T0);

disp(' ')
disp('====  GHprimez(z):  ')
GHprimez(z)=simplify(ztrans(ghprimen(n),n,z),'Steps',5)


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q1. FIRST,  ')
disp('    change the plant function Gp(s) above to Gp(s)=1/(s*(s+1)), ')
disp('    and note that digital filter Dz(z) above is Dz(z)=K, ')
disp('    as in the stability chapter root-locus example 1 from the lecture notes.')
disp(' ')
disp(' ')


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q2. After making the changes in Q1,')
disp('    does Gc(s) above equal the plant function Gp(s) times the ')
disp('    zero-order hold?')
disp(' ')
disp('Answer: Gc(s) equals zero-order hold times Gp(s): yes/no  ')
disp(' ')
disp(' ')


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q3. After making the changes in Q1,')
disp('    does Gprime(s) above equal Gp(s) times 1/s')
disp('    as in the closed-loop lecture notes?')
disp(' ')
disp('Answer: Gprime(s) equals Gp(s) times 1/s: yes/no   ')
disp(' ')
disp(' ')

disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q4. After making the changes in Q1,')
disp('    Does GHprime(s) above equal Gp(s)H(s) times 1/s?')
disp('    as in example 2 of the time-response lecture notes?')
disp('    Hint: you may need to rearrange numerator and denominator')
disp('    to show they are equal to lecture note results')
disp(' ')
disp('Answer: GHprime(s) equals Gp(s)H(s) times 1/s: yes/no    ')
disp(' ')
disp(' ')


disp('====  Use sylbolic solver:  ')
syms  vCs vCz vGclz vGolz vEz Rz Rstar
eqns=[  vGolz==GHprimez(z)*(z-1)/z*Dz(z), ...
        vGclz==vCz/Rz, ...
        vEz==Rz-vEz*Dz(z)*GHprimez(z)*(z-1)/z, ...
        vCs==vEz*Dz(z)*Gc(s), ...
        vCz==vEz*Gprimez(z)*(z-1)/z*Dz(z), ...
        ]

sol=solve(eqns,[vCs vCz vGclz vGolz vEz ]);
disp('=================================================== ')
disp('Closed-loop results: ')
disp(' ')


disp(' ')
disp('==== Sample period and rate:  ')
T0=1/2         %sample period
fs=1/T0        %sample rate

 olddigits=digits(); digits(5);

disp(' ')
disp('==== Composite plant+zoh Gc(z)=Gprimez(z)(z-1)/z:  ')
Gcz(z)=collect((eval(subs(simplify(Gprimez(z)*(z-1)/z,'Steps',5)))),z);
[num den]=numden(Gcz);coef=sym2poly(den);Gcznum =num/sym(coef(1));Gczden=den/sym(coef(1));
Gcz(z)=Gcznum/Gczden;
disp('Gcc(z)=')
vpa(Gcz(z))

disp(' ')
disp('==== Composite D(z)+plant+feedback+zoh GHc(z)=GHprimez(z)(z-1)/z:  ')
DGHcz(z)=collect((eval(subs(simplify(Dz(z)*GHprimez(z)*(z-1)/z,'Steps',5)))),z);
[num den]=numden(DGHcz);coef=sym2poly(den);DGHcznum =num/sym(coef(1));DGHczden=den/sym(coef(1));
DGHcz(z)=DGHcznum/DGHczden;
disp('DGHcz(z)=')
vpa(DGHcz(z))
olddigits=digits(); digits(3);
DGHczstr = char(vpa(subs(DGHcz))); %save for root locus printout
digits(olddigits);
 

disp(' ')
disp('==== Closed-loop pulse Transfer function Gcl(z) denoted Gclz(z) :  ')
Gclz(z)= simplify(collect((eval(subs(sol.vGclz))),z),'Steps',5);
[num den]=numden(Gclz);[C1 T1]=coeffs(den,[z K]);coef=eval(C1);
Gclznum =num/sym(coef(1));Gclzden=den/sym(coef(1));
Gclz(z)=collect(Gclznum,z)/collect(Gclzden,z);

disp('Gclz(z)=')
vpa(Gclz(z))
disp(' ')


% disp(' ')
% disp('gcl[n]=')
gcl(n)=vpa(iztrans(Gclz));
% disp('step response=')
stepgcl(n)=vpa(iztrans(Gclz*z/(z-1)));

disp(' ')
disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q5. After making the changes in Q1,')
disp('    What is the sample time T0 in seconds?')
disp(' ')
% disp('Answer: Gclz(z) same as lecture notes C(z)/R(z): yes/no  ')
disp('Answer: sample time T0= ??? s  ')
disp(' ')
disp(' ')
 
disp('  ')
disp('==== open-loop root-locus system coefficients for K=1')
K=1
disp(' ')
disp(['Open-loop system numerator for K=' num2str(K) ' '])
vpa(eval(DGHcznum))
sysnumcoeffs=sym2poly(eval(DGHcznum));
disp(['Open-loop system denominator for K=' num2str(K) ' '])
vpa(eval(DGHczden))
sysdencoeffs=sym2poly(eval(DGHczden));

digits(olddigits);


nn=0:25;
gcln=real(vpa(subs(gcl(nn))));
stepgcln=real(vpa(subs(stepgcl(nn))));
Gcldtft(w)= eval(subs(Gclz(exp(i*w)))); %compute DTFT
wmax=2*pi;wmin=-2*pi;
% %logarithmic frequency scale
%wmin=wmax/10000
% fac=exp((log(wmax)-log(wmin))/(50));
% wn=wmin*fac.^(0:1:50);   
wn=wmin:wmax/100:wmax;  %linear freq scale
Gcldtftn=double(eval(Gcldtft(wn)));
%GcldtftnDegrees= unwrap(atan2(imag(Gcldtftn),real(Gcldtftn)),5)*180/pi;
GcldtftnDegrees= (atan2(imag(Gcldtftn),real(Gcldtftn)))*180/pi;

TFstr = char(vpa(Gclz)); 
z = tf('z',T0);
disp('======= transfer function form: '); 
% olddigits=digits(); digits(6);
eval(['Gclzsys = ',TFstr]); 
 

[poles,zeroes] = pzmap(Gclzsys);
disp(['  poles=' num2str(poles') '  and zeroes=' num2str(zeroes') ])
disp(['  magnitude of poles=' num2str(abs(poles')) '  and zeroes='])
disp(['==== Closed-loop dc gain (z=1) from Gcl(z)= ' num2str(eval(Gclz(1))) ])
disp(' ')
  
 
 
hh=figure(1);
sp=subplot(4,1,1);stem(nn,stepgcln,'LineWidth',3);grid on;sp.YLim=[0 1.5];
title({'Initial analysis' ['for K=' num2str(K) ', step response =iztrans(Gclz(z)(z-1)/z']});xlabel('n');  
sp=subplot(4,1,2);stem(nn,gcln,'LineWidth',3);grid on;%sp.YLim=[-10 10];
title(['For K=' num2str(K) ', gcl[n]=iztrans(Gclz(z))']);xlabel('n');   
sp=subplot(4,1,3);plot(wn,abs(Gcldtftn),'LineWidth',3);grid on;
%loglog(wn,abs(Gcldtftn),'LineWidth',3);grid on;
%ymax=10^(floor(log10(max(abs(Gcldtftn))))+1);
sp.XLim=[wmin wmax];%sp.YLim=[ymax/1000 ymax ];
title({['For K=' num2str(K) ',  |Gcl(w)|= |Gclz(z)| for z=e^{jw}']});xlabel('Frequency w (rad/sample)'); set(gca,'LineWidth',2); 
sp=subplot(4,1,4);plot(wn,GcldtftnDegrees,'LineWidth',3);grid on;sp.XLim=[wmin wmax];
%semilogx(wn,GcldtftnDegrees,'LineWidth',3);grid on;
% sp.XLim=[wmin wmax];
title(['For K=' num2str(K) ', Angle of Gcl(w) (degrees)']);xlabel('Frequency w (rad/sample)');   set(gca,'LineWidth',2);
set(findall(hh,'Type','text'),'FontSize',16);
hh.Position=[360 278 550 550];
disp(' Fig. 1. Closed-loop step response, impulse response gcl[n],  ')
disp('       |Gcl(w)|= |Gclz(z)| for z=e^{jw}, and angle of Gcl(w). ')
disp(' ')
disp(' ')



disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q6. Before root locus, we first characterize the system with gain K=1.  ')
disp('    Fig. 1 shows the step response, impulse response gcl[n],  ')
disp('    DTFT |Gcl(w)| = |Gclz(z)| for z=e^{jw}, and angle of Gcl(w). ')
disp('    Impulse response gcl[n] is the inverse z-transform of Gcl(z). ')
disp('       What is the value of gain K for Fig. 1?')
disp('    In Fig. 1 above, use the cursor tool to measure the following: ')
disp('    What is the dc response |Gcl(w)| at 0 rad/sample?')
disp('    What is the peak overshoot of the step response in percent?')
disp('    Hint: peak overshoot of the final step response output value of 1  ')
disp(' ')
disp('Answer:  value of gain K= ??? ')
disp('Answer:  dc response |Gcl(w)|= ???')
disp('Answer:  peak overshoot of the step response: ??? % ')
disp(' ')
disp(' ')

%copyright 2017 t weldon
K=1; %the rootlocus will vary gain K
sys = tf(sysnumcoeffs,sysdencoeffs,T0);
simple_gui2(sys) %this popup is to work around matlab live editor data cursor bug
disp(' Fig. 2. Root locus plot for the system.  ')
disp(' ')
disp(' ')

%Here we comment out the original rotlocus code because of the data cursor
%bug
% % hh=figure(2);
% kk=[0.5 1 1.5 2];
% h2 = rlocusplot(sys);
% axis([-3 1.5 -2 2]);
% zeta = [ 0.25 0.5 0.75];
% Wn = [0.25 0.5 0.75]*3;
% aa=gca ; aa.XGrid='on';aa.YGrid='on';aa.LineWidth=3;aa.FontWeight='bold'; 
% aa.XLabel.FontSize=20;aa.FontSize=12; set(findall(gcf,'Type','line'),'LineWidth',3); 
% title({'Root Locus Plot in z-Plane' [ 'D(z)GH(z)(z-1)/z=' DGHczstr ]});xlabel('Real(z)');ylabel('Imag(z)');
% set(findall(gcf,'Type','text'),'FontSize',14); 
% set(findall(gcf,'Type','text'),'FontWeight','bold');


sys
 


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q7. Fig. 2 shows the root locus plot as gain K is varied from K=0 ')
disp('    to K=infinity. ')
disp('    !!! NOTE !!!')
disp('    !!! NOTE !!!: as of 2020 maatlab has a bug where the cursor for rootlocus')
disp('       does not work properly, so you should also see a popup rootlocus')
disp('       window with a working cursor, in addition to the one above.')
disp('    In Fig. 2 above or in the corresponding popup window,  ')
disp('    use the cursor tool to measure the following: ')
disp('    What are the two pole locations for K=0?')
disp('    Hint: use the cursor to follow the 2 curves inside the unit circle,')
disp('          the 2 curves split, one curve goes up and one goes down near z=0.8')
disp('    What is the value of gain K when the curves intersect the unit circle?')
disp('    What is the gain K when the peak overshoot is 12% ?')
disp(' ')
disp('Answer:  two pole locations for K=0 are: z= ??? and z= ???')
disp('Answer:  when the curves intersect the unit circle gain K= ???')
disp('Answer:  when the peak overshoot is 12%, gain K= ??? ')
disp(' ')
disp(' ')



%================================
% set your design gain here as Kdesign
disp('======================================='); 
disp('======= enter your design K value here: '); 
Kdesign=2.2 %fix this for 12% overshoot
K=Kdesign;


disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q8. NEXT,  ')
disp('    change the desired gain for your design by setting the ')
disp('    value of "Kdesign" above equal to the gain in Q7 ')
disp('    that produces 12% overshoot.')
disp('   Hint: your simulation below should show the desired overshoot')
disp(' ')
disp(' ')



syms z
gcldesign(n)=vpa(iztrans(eval(Gclz)));
stepgcldesign(n)=vpa(iztrans(eval(Gclz)*z/(z-1)));
nn=0:25;   
stepgcldesignn=real(eval(stepgcldesign(nn)));
gcldesignn=real(eval(gcldesign(nn)));
Gcldesigndtft(w)= eval(subs(Gclz(exp(i*w)))); %compute DTFT
wmax=2*pi;wmin=-2*pi;
% %logarithmic frequency scale
%wmin=wmax/10000
% fac=exp((log(wmax)-log(wmin))/(50));
% wn=wmin*fac.^(0:1:50);   
wn=wmin:wmax/100:wmax;  %linear freq scale
Gcldesigndtftn=double(eval(Gcldesigndtft(wn)));
%GcldtftnDegrees= unwrap(atan2(imag(Gcldtftn),real(Gcldtftn)),5)*180/pi;
GcldesigndtftnDegrees= (atan2(imag(Gcldesigndtftn),real(Gcldesigndtftn)))*180/pi;

TFstr = char(vpa(Gclz)); 
z = tf('z',T0);
disp('======= transfer function form: '); 
eval(['GclzsysDesign = ',TFstr]); 
[poles,zeroes] = pzmap(GclzsysDesign);
disp(['  poles=' num2str(poles') '  and zeroes=' num2str(zeroes') ])
disp(['  magnitude of poles=' num2str(abs(poles')) '  and zeroes='])

 
hh=figure(3);
sp=subplot(4,1,1);stem(nn,stepgcldesignn,'LineWidth',3);grid on;sp.YLim=[0 1.5];
title({'Design for 12% Overshoot' ['For K=' num2str(K) ', step response =iztrans(Gclz(z)(z-1)/z']});xlabel('n');  
sp=subplot(4,1,2);stem(nn,gcldesignn,'LineWidth',3);grid on;%sp.YLim=[-10 10];
title(['For K=' num2str(K) ', gcl[n]=iztrans(Gclz(z))']);xlabel('n');   
sp=subplot(4,1,3);plot(wn,abs(Gcldesigndtftn),'LineWidth',3);grid on;
%loglog(wn,abs(Gcldtftn),'LineWidth',3);grid on;
%ymax=10^(floor(log10(max(abs(Gcldtftn))))+1);
sp.XLim=[wmin wmax];%sp.YLim=[ymax/1000 ymax ];
title({['For K=' num2str(K) ',  |Gcl(w)|= |Gclz(z)| for z=e^{jw}']});xlabel('Frequency w (rad/sample)'); set(gca,'LineWidth',2); 
sp=subplot(4,1,4);plot(wn,GcldesigndtftnDegrees,'LineWidth',3);grid on;sp.XLim=[wmin wmax];
%semilogx(wn,GcldtftnDegrees,'LineWidth',3);grid on;
% sp.XLim=[wmin wmax];
title(['For K=' num2str(K) ', Angle of Gcl(w) (degrees)']);xlabel('Frequency w (rad/sample)');   set(gca,'LineWidth',2);
set(findall(hh,'Type','text'),'FontSize',16);
hh.Position=[360 278 550 550];
disp(' Fig. 3. Closed-loop step response, impulse response gcl[n] ,  ')
disp('       |Gcl(w)|= |Gclz(z)| for z=e^{jw}, and angle of Gcl(w). ')
disp(' ')
disp(' ')



disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q9. Fig. 3 shows the step response, impulse response gcl[n],  ')
disp('    DTFT |Gcl(w)|= |Gclz(z)| for z=e^{jw}, and angle of Gcl(w) ')
disp(['   for your new design with K=' num2str(K) '. '])
disp('    In Fig. 3 above, use the cursor tool to measure the following: ')
disp('    What is the peak overshoot of the step response in percent?')
disp('    What is the magnitude of dc gain |Gcl(w)| at 0 rad/sample?')
disp('    What is step response at n=25 (at the far right)?')
disp('    Is the step response at n=25 equal to the dc gain? ')
disp(' ')
disp('Answer:  peak overshoot of the step response: ??? % ')
disp('Answer:  dc gain |Gcl(w)|= ???')
disp('Answer:  at n=25  step response = ??? ')
disp('Answer:  step response at n=25 equal to the dc gain: yes/no ')
disp(' ')
disp(' ')


hh=figure(4);
%pzm=pzmap(Hzsys)
pzp=pzplot(GclzsysDesign);
setoptions(pzp,'FreqUnits','auto','Grid','off','YLim',[-1.5 1.5],'XLim',[-1.5  1.5]);
xlabel('Real(z)');ylabel('Imag(z)');
title({ 'Closed-Loop Pole-Zero Plot of Gclz(z)' ['New design for 12% overshoot with K=' num2str(K) ' ']});
%title('Z-plane Pole-Zero Plot of H(z)| ');%title({'X(W)', ['Line2 x=' num2str(3.3)]})
% set(findobj(gca, 'type', 'line'),'markersize', 12)
% set(findobj(gca, 'type', 'line'),'linewidth', 2)
% figax=findall(hh,'Type','Axes');set(figax(2),'LineWidth',2);
set(findall(hh,'Type','text'),'FontSize',14);
set(findall(hh,'Type','text'),'FontWeight','bold');
set(findobj(gca, 'type', 'line'),'markersize', 10)
set(findobj(gca, 'type', 'line'),'linewidth', 2)
%figax=findall(hh,'Type','Axes');set(figax(2),'LineWidth',2);
grid off
%hh.Position=[360 278 550 550];
disp(' Fig. 4. Closed-loop poles and zeroes of new design in z-plane. ')
disp(' ')
disp(' ')

disp('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ ')
disp('Q10. Fig. 4 shows the closed-loop Gclz(z) poles and zeroes of the new  ')
disp(['    design in z-plane, for your new design with K=' num2str(K) '. '])
disp('    In Fig. 4 above, use the cursor tool to measure the following: ')
disp('    What are the two pole locations?')
disp('    What is the region of convergence (ROC)?')
disp('    Is the system BIBO stable?')
disp(' ')
disp('Answer:  two pole locations for K= ??? +/- j??? ')
disp('Answer: ROC |z|> ???')
disp('Answer:  stable: yes/no  ')
disp(' ')
disp(' ')

%

function simple_gui2(sys)
   %  Create and then hide the UI as it is being constructed.
   f = figure('Visible','off','Position',[360,500,450,385]);
   ha = axes('Units','Pixels','Position',[50,60,350,300]); 
   h2 = rlocusplot(sys);
axis([-3 1.5 -2 2]);
zeta = [ 0.25 0.5 0.75];
Wn = [0.25 0.5 0.75]*3;
aa=gca ; aa.XGrid='on';aa.YGrid='on';aa.LineWidth=3;aa.FontWeight='bold'; 
aa.XLabel.FontSize=20;aa.FontSize=12; set(findall(gcf,'Type','line'),'LineWidth',3); 
title({'Root Locus Plot in z-Plane'});xlabel('Real(z)');ylabel('Imag(z)');
set(findall(gcf,'Type','text'),'FontSize',14); 
set(findall(gcf,'Type','text'),'FontWeight','bold');
   % Make the UI visible.
   f.Visible = 'on'; 
end