function[cycle2] = cycle(cycle1,deltat,name)
%creates a drive cycle object (class 'cycle') starting from
%cycle1, which is the path to an excel file with 3 columns
%existing of
% time in s in column 1
% speeds in km/h in column2
% slope in % in column3
%deltat is the required time step to get a good idea of the speed and slope changes during the drive cycle.
%typical value is 0.5s.
%name should be the name of the cycle which will be used for further processing
%The output cycle is an object with 5 fields
% cycle.t=times in s
% cycle.v=speeds in km/h
% cycle.s=slopes in %
% cycle.a=accelerations in m/s^2
% cycle.dt=time step in s
if nargin == 0
cycle2.t=[];
cycle2.v=[];
cycle2.s=[];
cycle2.a=[];
cycle2.dt=[];
cycle2.name=[];
cycle2=class(cycle2,'cycle');
elseif isa(cycle1,'cycle')
cycle2 = cycle1;
else
cycle1=xlsread(cycle1);
[a b]=size(cycle1);
end
if b~=3
error('wrong input type for first argument, the excel file should contain 3 columns (time[s],speed[km/h],slope[%]')
else
dt=deltat;
%times where speed or slope changes
tc=cycle1(:,1);
%speedlist
vc=cycle1(:,2)/3.6;
%slopelist
slopec=cycle1(:,3);
tmax=tc(length(tc));
time=0:deltat:tmax;
for i=1:length(tc)-1
ac(i)=(vc(i+1)-vc(i))/(tc(i+1)-tc(i));
end
%opstellen snelheidsprofiel-hellingsprofiel ifv de tijd
k=1;
for i=1:length(tc)-1
while k<=length(time)
if time(k)<=tc(i+1)
speed(k)=3.6*(vc(i)+ac(i)*(time(k)-tc(i)));
acc(k)=ac(i);
slope(k)=slopec(i);
k=k+1;
else
break
end
end
end
cycle2.t=time.';
cycle2.v=speed.';
cycle2.s=slope.';
cycle2.a=acc.';
cycle2.dt=dt.';
cycle2.name=(name').';
cycle2=class(cycle2,'cycle');
end