clc
clear all
load B0005
load B0006
load B0007
load B0018
D_cycle1={B0005.cycle.type};
D_cycle2={B0006.cycle.type};
D_cycle3={B0007.cycle.type};
D_cycle4={B0018.cycle.type};
D_cycle1=D_cycle1';
D_cycle2=D_cycle2';
D_cycle3=D_cycle3';
D_cycle4=D_cycle4';
index1 = find(ismember(D_cycle1, 'discharge'))
index2 = find(ismember(D_cycle2, 'discharge'))
index3 = find(ismember(D_cycle3, 'discharge'))
index4 = find(ismember(D_cycle4, 'discharge'))
for i=1:length(index1)
capacity1(i)=B0005.cycle(index1(i,1)).data.Capacity
end
index=[]
for i=1:length(index2)
capacity2(i)=B0006.cycle(index2(i,1)).data.Capacity
end
index2=[]
for i=1:length(index3)
capacity3(i)=B0007.cycle(index3(i,1)).data.Capacity
end
index3=[]
for i=1:length(index4)
capacity4(i)=B0018.cycle(index4(i,1)).data.Capacity
end
index4=[]
capacity1 = capacity1'
capacity2 = capacity2'
capacity3 = capacity3'
capacity4 = capacity4'
capacity = [capacity1;capacity2;capacity3;capacity4]
C_cycle1={B0005.cycle.type};
C_cycle2={B0006.cycle.type};
C_cycle3={B0007.cycle.type};
C_cycle4={B0018.cycle.type};
C_cycle1= C_cycle1';
C_cycle2= C_cycle2';
C_cycle3= C_cycle3';
C_cycle4= C_cycle4';
index5= find(ismember(C_cycle1,'charge'))
index6= find(ismember(C_cycle2,'charge'))
index7= find(ismember(C_cycle3,'charge'))
index18= find(ismember(C_cycle4,'charge'))
cnt=0
for i=1:length(index5);
for ii=1:round(length(B0005.cycle(index5(i)).data.Voltage_measured)/10):length(B0005.cycle(index5(i)).data.Voltage_measured);
cnt=cnt+1 ;
voltage1(i,cnt)=B0005.cycle(index5(i)).data.Voltage_measured(ii);
current1(i,cnt)=B0005.cycle(index5(i)).data.Current_measured(ii);
temperature1(i,cnt)=B0005.cycle(index5(i)).data.Temperature_measured(ii);
end
cnt=0;
end
index5=[]
for i=1:length(index6);
for ii=1:round(length(B0006.cycle(index6(i)).data.Voltage_measured)/10):length(B0006.cycle(index6(i)).data.Voltage_measured);
cnt=cnt+1 ;
voltage2(i,cnt)=B0006.cycle(index6(i)).data.Voltage_measured(ii);
current2(i,cnt)=B0006.cycle(index6(i)).data.Current_measured(ii);
temperature2(i,cnt)=B0006.cycle(index6(i)).data.Temperature_measured(ii);
end
cnt=0;
end
index=[]
for i=1:length(index7);
for ii=1:round(length(B0007.cycle(index7(i)).data.Voltage_measured)/10):length(B0005.cycle(index7(i)).data.Voltage_measured);
cnt=cnt+1 ;
voltage3(i,cnt)=B0007.cycle(index7(i)).data.Voltage_measured(ii);
current3(i,cnt)=B0007.cycle(index7(i)).data.Current_measured(ii);
temperature3(i,cnt)=B0007.cycle(index7(i)).data.Temperature_measured(ii);
end
cnt=0;
end
index=[]
for i=1:length(index18);
for ii=1:round(length(B0018.cycle(index18(i)).data.Voltage_measured)/10):length(B0018.cycle(index18(i)).data.Voltage_measured);
cnt=cnt+1 ;
voltage4(i,cnt)=B0018.cycle(index18(i)).data.Voltage_measured(ii);
current4(i,cnt)=B0018.cycle(index18(i)).data.Current_measured(ii);
temperature4(i,cnt)=B0018.cycle(index18(i)).data.Temperature_measured(ii);
end
cnt=0;
end
index=[]
voltage1(:,11)=[]
current1(:,11)=[]
temperature1(:,11)=[]
voltage2(:,11)=[]
current2(:,11)=[]
temperature2(:,11)=[]
voltage3(:,11)=[]
current3(:,11)=[]
temperature3(:,11)=[]
voltage4(:,11)=[]
current4(:,11)=[]
temperature4(:,11)=[]
for vk1=1:size(voltage1,1)
for i = 1 : find(voltage1(vk1,:),1,'last')
D_voltage1(vk1).voltage1(i)=voltage1(vk1,i)
D_voltage1(vk1).current1(i)=current1(vk1,i)
D_voltage1(vk1).temperature1(i)=temperature1(vk1,i)
end
if vk1<=length(capacity1)
D_voltage1(vk1).capacity1=capacity1(vk1)
else
continue
end
end
for vk2=1:size(voltage2,1)
for i = 1 : find(voltage2(vk2,:),1,'last')
D_voltage2(vk2).voltage2(i)=voltage2(vk2,i)
D_voltage2(vk2).current2(i)=current1(vk2,i)
D_voltage2(vk2).temperature2(i)=temperature2(vk2,i)
end
if vk2<=length(capacity2)
D_voltage2(vk2).capacity2=capacity2(vk2)
else
continue
end
end
for vk3=1:size(voltage3,1)
for i = 1 : find(voltage3(vk3,:),1,'last')
D_voltage3(vk3).voltage3(i)=voltage3(vk3,i)
D_voltage3(vk3).current3(i)=current3(vk3,i)
D_voltage3(vk3).temperature3(i)=temperature3(vk3,i)
end
if vk3<=length(capacity3)
D_voltage3(vk3).capacity3=capacity3(vk3)
else
continue
end
end
for vk4=1:size(voltage4,1)
for i = 1 : find(voltage4(vk4,:),1,'last')
D_voltage4(vk4).voltage4(i)=voltage4(vk4,i)
D_voltage4(vk4).current4(i)=current4(vk4,i)
D_voltage4(vk4).temperature4(i)=temperature4(vk4,i)
end
if vk4<=length(capacity4)
D_voltage4(vk4).capacity4=capacity4(vk4)
else
continue
end
end
D_voltage1(169:170) = [];
D_voltage2(169:170) = [];
D_voltage3(169:170) = [];
D_voltage4(133:134) = [];
for i=1:length(D_voltage1)
input1(i,:)=[D_voltage1(i).voltage1 D_voltage1(i).current1 D_voltage1(i).temperature1 D_voltage1(i).capacity1]
end
for i=1:length(D_voltage2)
input2(i,:)=[D_voltage2(i).voltage2 D_voltage2(i).current2 D_voltage2(i).temperature2 D_voltage2(i).capacity2]
end
for i=1:length(D_voltage3)
input3(i,:)=[D_voltage3(i).voltage3 D_voltage3(i).current3 D_voltage3(i).temperature3 D_voltage3(i).capacity3]
end
for i=1:length(D_voltage4)
input4(i,:)=[D_voltage4(i).voltage4 D_voltage4(i).current4 D_voltage4(i).temperature4 D_voltage4(i).capacity4]
end
input = [ input1; input2; input3; input4 ]
output1=capacity1;
output2=capacity2;
output3=capacity3;
output4=capacity4;
for u=1:size((input),2)
normalize(:,u) = ((input(:,u)-min(input(:,u)))./(max(input(:,u))-min(input(:,u))).*2)-1;
end
input = normalize;
target = capacity;
data_2 = input(169:504,:)
data_1 = input(1:168,:)
data_train = input(169:504,:)';
data_test = input(1:168,:)';
target_train=target(169:504,:)'
target_test=target(1:168,:)
for pp=1:2
tic
net=newff(minmax(data_train),[20 1],{'logsig','purelin'},'trainlm');
net.trainParam.epochs=1000;
net.trainParam.goal=1e-6;
net.trainParam.lr= 0.5;
net.performFcn = 'mse';
[net, tr] = train(net, data_train, target_train);
capacity_estimated=(sim(net, data_test))';
capacity_error = gsubtract(target_test,capacity_estimated);
RMSE = rms(capacity_error)*100
MSE=(mean((capacity_estimated-target_test).^2))*100
MAPE=(sum(abs((capacity_estimated-target_test)./(capacity_estimated)))./length(target_test))*100
MAPE2=(sum(abs((target_test-capacity_estimated)./(capacity_estimated)))./length(target_test))*100
MAE=(sum(abs(capacity_estimated-target_test))./length(target_test))*100
SD=(std(capacity_estimated-target_test))*100
check1(pp)=RMSE;
check2(pp)=MSE;
check3(pp)=MAPE;
check4(pp)=MAE;
check5(pp)= SD
check6(pp,:)=capacity_estimated
check7(pp,:)=capacity_error
end
[RMSE_BPNN,clm]=min(check1)
MSE_BPNN=min(check2(:,clm))
MAPE_BPNN=min(check3(:,clm))
MAE_BPNN=min(check4(:,clm))
SD_BPNN=min(check5(:,clm))
capacity_estimated_BPNN = check6(clm,:)
capacity_error_BPNN= check7(clm,:)
toc
Best Answer