function grafico_resultado_filtro(X1, Y1, Y2)
%grafico_resultado_filtro(X1, Y1, Y2)
% X1: vector of x data
% Y1: vector of y data
% Y2: vector of y data
% Auto-generated by MATLAB on 12-Jul-2007 13:49:37
% Create figure
figure1 = figure('PaperSize',[20.98 29.68],'Name','Filtering Results');
% Create subplot
subplot1 = subplot(2,1,1,'Parent',figure1);
% Uncomment the following line to preserve the X-limits of the axes
xlim([5 60.55]);
% Uncomment the following line to preserve the Y-limits of the axes
ylim([-1 1]);
box('on');
grid('on');
hold('all');
% Create plot
plot(X1,Y1,'DisplayName','Dados originais','Parent',subplot1,'LineWidth',1,...
'Color',[0 0 0]);
% Create xlabel
xlabel('Tempo (s)');
% Create ylabel
ylabel('Oscilao em X');
% Create title
title('Resultado do Filtro','FontSize',12,'Color',[1 0 0]);
% Create legend
legend1 = legend(subplot1,'show');
set(legend1,'Location','SouthEast');
% Create subplot
subplot2 = subplot(2,1,2,'Parent',figure1);
% Uncomment the following line to preserve the X-limits of the axes
xlim([5 60]);
% Uncomment the following line to preserve the Y-limits of the axes
ylim([-1 1]);
box('on');
grid('on');
hold('all');
% Create plot
plot1 = plot(X1,Y2,'DisplayName','Dados ps-filtro','Parent',subplot2,...
'LineWidth',1,...
'Color',[0 0 0]);
% Create xlabel
xlabel('Tempo (s)');
% Create ylabel
ylabel('Oscilao em X');
% Get xdata from plot
xdata1 = get(plot1, 'xdata');
% Get ydata from plot
ydata1 = get(plot1, 'ydata');
% Make sure data are column vectors
xdata1 = xdata1(:);
ydata1 = ydata1(:);
% Get axes xlim
axXLim1 = get(subplot2, 'xlim');
% Find the max
ymax1 = max(ydata1);
% Get coordinates for the max line
maxValue1 = [ymax1 ymax1];
% Plot the max
statLine1 = plot(axXLim1,maxValue1,'DisplayName',' Amplitude mxima',...
'Parent',subplot2,...
'Tag','max y',...
'LineWidth',2.5,...
'LineStyle','-.',...
'Color',[0 0 1]);
% Set new line in proper position
setLineOrder(subplot2, statLine1, plot1);
% Create legend
legend2 = legend(subplot2,'show');
set(legend2,'Location','SouthEast');
%-------------------------------------------------------------------------%
function setLineOrder(axesh1, newLine1, associatedLine1)
%SETLINEORDER(AXESH1,NEWLINE1,ASSOCIATEDLINE1)
% Set line order
% AXESH1: axes
% NEWLINE1: new line
% ASSOCIATEDLINE1: associated line
% Get the axes children
hChildren = get(axesh1,'Children');
% Remove the new line
hChildren(hChildren==newLine1) = [];
% Get the index to the associatedLine
lineIndex = find(hChildren==associatedLine1);
% Reorder lines so the new line appears with associated data
hNewChildren = [hChildren(1:lineIndex-1);newLine1;hChildren(lineIndex:end)];
% Set the children:
set(axesh1,'Children',hNewChildren);