function [dt_data1]=dtwvar(dj,min_d,max_d)
%DTWVAR Summary of this function goes here
%  Detailed explanation goes here
data=dj(min_d:max_d,2);
dt=dj(min_d:max_d,1);
[wr,wc]=size(data);
g_data.ss=data;
y=data;
t1=ones(wr,1);
t2=1:wr; t2=t2';
t=[t1 t2];
A=inv(t'*t)*t'*y;
yr=A(1)+A(2)*t2'; yr=yr';
dt_data=data-yr;
dt_data1=[dt dt_data];
g_data.ss1=dt_data;

[wr,wc]=size(g_data.ss);
figure(1); subplot(2,1,1); plot(g_data.ss); grid on;
[wr,wc]=size(g_data.ss);
XMIN=0; YMIN=min(g_data.ss)-1; 
XMAX=wr; YMAX=max(g_data.ss)+1;
axis([XMIN XMAX YMIN YMAX]);

[wr,wc]=size(g_data.ss1);
figure(1); subplot(2,1,2); plot(g_data.ss1); grid on;
[wr,wc]=size(g_data.ss1);
XMIN=0; YMIN=min(g_data.ss1)-1; 
XMAX=wr; YMAX=max(g_data.ss1)+1;
axis([XMIN XMAX YMIN YMAX]);