clc; clear all; close all;

%% Figure light theme

set(0, "defaultAxesColorOrder", [
        1.0000 0.0000 0.0000;  # red
        0.0000 0.0000 1.0000;  # blue
        1.0000 0.4980 0.0549;  # orange
        0.1725 0.6275 0.1725;  # green
        0.5804 0.4039 0.7412;  # purple
        0.5490 0.3373 0.2941;  # brown
        0.8902 0.4667 0.7608;  # pink
        0.4980 0.4980 0.4980;  # gray
]);

set(0, "DefaultFigureColor", [1 1 1]);
set(0, "DefaultAxesColor", [1 1 1]);
set(0, "DefaultAxesXColor", [0 0 0]);
set(0, "DefaultAxesYColor", [0 0 0]);
set(0, "DefaultTextColor", [0 0 0]);

set(0, "DefaultAxesGridColor", [0 0 0]);
set(0, 'DefaultAxesGridAlpha', 1.00);

set(0, "DefaultAxesMinorGridColor", [0 0 0]);
set(0, 'DefaultAxesMinorGridAlpha', 0.20);

set(0, "DefaultLineLinewidth", 3.00);
set(0, "DefaultAxesFontSize", 16);
set(0, "DefaultTextFontSize", 16);
set(0, "DefaultAxesLineWidth", 1.00);

set(0, "DefaultAxesXGrid", "on");
set(0, "DefaultAxesYGrid", "on");
set(0, "DefaultAxesZGrid", "on");
set(0, "DefaultAxesXMinorGrid", "on");
set(0, "DefaultAxesYMinorGrid", "on");
set(0, "DefaultAxesXMinorTick", "on");
set(0, "DefaultAxesYMinorTick", "on");

set(0, 'DefaultAxesGridAlpha', 0.50);

omega = 2*pi*250;

t = linspace(0.00, 0.10, 4000);

% y = (-0.49 .* exp(-500 .* t) + ...
%       12.4 .* exp(-889 .* t) .* cos(3900 .* t - 1.24) + ...
%       7.37 .* cos(6283 .* t + 2.05)) .* (t >= 0);

y = (12*4000^2*1e-9) .* ...
    ( -9.41 .* exp(-500 .* t) + ...
      29.39 .* exp(-889 .* t) .* cos(3900 .* t + 1.108) + ...
      69.83 .* cos(omega .* t - 1.62)) .* (t >= 0);

y_sine = sin(omega * t);

figure(1);
grid on;
set(gcf, "paperunits", "inches");
set(gcf, "papersize", [10 4]);
set(gcf, "paperposition", [0 0 10 4]);

% bode(H);
% grid on;

% Cambiar tamaño de las fuentes
% set(gca, "fontsize", 12);      % ejes actuales
% set(findall(gcf,"type","text"), "fontsize", 10);  % todos los textos
% set(findall(gcf,"type","line"), "linewidth", 1.25);

% diagrama de bode transferencia original
% print("bode_plot.png", "-dpng", "-r1000");

set (gca, "minorgridlinestyle", "--");   % grilla mayor con línea de guiones

plot(t*1e3, y_sine, "b", "LineWidth", 3);
hold on;
plot(t*1e3, y, "r", "LineWidth", 3);

% title("Time Response");
xlim([0 16])
xticks(0:1:16);
ylim([-15 15])

xlabel("TIEMPO  t  [ms]");
ylabel("AMPLITUD  y(t)");
legend("Señal senoidal 250Hz", "Respuesta a señal senoidal ",
        "Location", "northeast");

graphics_toolkit("qt");
% set(gcf, "renderer", "painters");
set(gcf, "renderer", "opengl");
print("sine_response_omega1.png", "-dpng", "-r500");
