% dimmer.m
%
% Comparison of the lighting control between the Allsmartlife MNTK-133944 dimmer and with my homebrew design

%  Allsmartlife MNTK-133944 dimmer -----------------------------------------------------------------------

p1 = [.73    .65   .60   .55   .50   .45   .40   .35   .30   .25   .20   .15   .10   .05   0   ];  % slider position (in inches from bottom)
v1 = [10.76 10.30  9.91  9.34  8.78  8.16  7.45  6.72  5.71  4.85  3.86  2.64  1.49  0.56  0.56];  % lamp dimmer voltage
a1 = [2.105 2.104 2.103 2.099 2.097 2.043 1.799 1.564 1.293 1.084 0.853 0.583 0.364 0.069 0.069];  % voltage accross shunt (13.2 ohms)
w1 = a1 * 120 / 13.2;                                                                              % lamp power (watts)

%  Homebrew dimmer

p2 = [ 2.34  2.20  2.0  1.9  1.8   1.7   1.6   1.5  1.4  1.3  1.2  1.1  1.0  0.9  0.8  0.7  0.6  0.5  0.4  0.3  0.2   0.0];
v2 = [10.26 10.18 8.43 7.69  6.73  5.84  4.95  4.03 2.84 2.23 2.05 1.93 1.81 1.69 1.55 1.41 1.28 1.17 1.04 0.91 0.47  0.37];
a2 = [ 2.1   2.1   2.1 1.867 1.565 1.351 1.097 .891 .617 .485 .464 .444 .424 .382 .357 .335 .307 .284 .254 .222 .063 .063];
w2 = a2 * 120 / 13.2;

plt(p1,v1,p1,w1,p2,v2,p2,w2,'right',[1 3],'xlabel','slider position (inches)','marker','o',...
    'ylabel',{'lamp power (watts)' 'lamp dimmer voltage'},...
    'TraceID',['MNTK v'; 'MNTK w'; 'home v'; 'home w'],...
    'TraceC',[0 1 0; 1 0 1],'+Ycolor',[1 0 1],'-Ycolor',[0 1 0],'HelpText',...
    {'All Smart Life' 'dimmer' .21+.77i 'fontsize' 18 -2i 'My dimmer' .72+.58i});
plt xright TGLgrid;               % solid grid lines looks good here

% same plot as above except using relative position in place of absolute position

p1 = 100*p1/p1(1);
p2 = 100*p2/p2(1);
plt(p1,v1,p1,w1,p2,v2,p2,w2,'right',[1 3],'xlabel','slider position (percent)','marker','o',...
    'ylabel',{'lamp power (watts)' 'lamp dimmer voltage'},...
    'TraceID',['MNTK v'; 'MNTK w'; 'home v'; 'home w'],...
    'TraceC',[0 1 0; 1 0 1],'+Ycolor',[1 0 1],'-Ycolor',[0 1 0],'HelpText',...
    {'All Smart Life' 'dimmer' .2+.78i 'fontsize' 18 -2i 'My dimmer' .72+.48i});
plt xright TGLgrid;               % solid grid lines looks good here

% plot power vs. lamp dimmer voltage
[v,i] = sort([v1 v2]);  w = [w1 w2];  % combine both data sets (sorted by voltage)
plt(v,w(i),'marker','o','xlabel','lamp dimmer voltage','ylabel','lamp power (watts)');