%Simulation of relayn with sinusoidal input
%   kja 070510

aminit;

global w a b c
w=1;a=2;b=3;c=1;tmax=20;

% Load up the simulink simulation and set parametsr
relaysine
set_param('relaysine/Sine Wave', 'Amplitude', num2str(a));
set_param('relaysine/Sine Wave', 'Frequency', num2str(w));
set_param('relaysine/Relay', 'OnSwitchValue', num2str(c));
set_param('relaysine/Relay', 'OffSwitchValue', num2str(-c));
set_param('relaysine/Relay', 'OnOutputValue', num2str(b));
set_param('relaysine/Relay', 'OffOutputValue', num2str(-b));

[t,x,y]=sim('relaysine',tmax);
yfh=(4*b/pi)*sin(w*t-asin(c/a));

figure(1); clf; subplot(321); hold on;
plot(t, y(:,1), 'r--', 'LineWidth', AM_data_linewidth);
plot(t, y(:,2), 'b-', 'LineWidth', AM_data_linewidth);
plot(t, yfh, '-', 'Linewidth', AM_data_linewidth, 'Color', [0.5 0.5 0.5]);

amaxis([0 20 -4.5 6.5]); box on;
line([0 tmax], [0 0], 'LineWidth', AM_ref_linewidth);

set(gca, 'FontSize', 32/3);
lgh = legend('In', 'Out', '1st har.', 'Orientation', 'horizontal', ...
  'Location', 'North');
legend(lgh, 'boxoff');

amprint('desfcn-hystsim.eps');
