-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOCV_fit.m
86 lines (66 loc) · 2.14 KB
/
OCV_fit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
clear;
OCV_data = readtable('10_16_2015_Initial capacity_SP20-1 (1).csv');
% voltage by time
voltages = OCV_data{:, 'Voltage_V_'};
times = OCV_data{:, 'Test_Time_s_'};
% state of charge (charging)
x_charging = OCV_data{1:12970, 'SOC_sum_A__As_'};
x_charging = x_charging(1:12970/7121:12970, 1);
% state of charge (discharging)
x_discharging = OCV_data{12970:20090, 'SOC_sum_A__As_'};
% voltage (charging)
y_charging = OCV_data{1:12970, 'Voltage_V__1'};
y_charging = y_charging(1:12970/7121:12970, 1);
% voltage (discharging)
y_discharging = OCV_data{12970:20090, 'Voltage_V__1'};
y_discharing = flip(y_discharging);
% averaging
x = x_charging;
% y = (y_charging + flip(y_discharging)) / 2;
y = y_charging;
number_of_terms = 4;
A = zeros(number_of_terms, number_of_terms);
b = zeros(number_of_terms, 1);
[rows, columns] = size(x);
% plotting stress-strain diagram
figure(1)
hold on
plot(x_charging, y_charging, 'MarkerFaceColor', 'g', 'linewidth', 3, 'color', 'g');
plot(x_discharging, y_discharging, 'MarkerFaceColor', 'r', 'linewidth', 3, 'color', 'r');
plot(x, y, 'MarkerFaceColor', 'b', 'linewidth', 3, 'color', 'b');
grid
title('OCV vs. SOC')
xlabel('SOC')
ylabel('OCV (V)')
legend('charging', 'discharging', 'averaged');
set(gca, 'fontsiz', 16)
figure(2)
plot(times, voltages, 'MarkerFaceColor', 'b', 'linewidth', 3, 'color', 'b');
xlabel('time (sec)');
ylabel('voltage (V)');
hold on
% create the A matrix and b vector for a number_of_terms degree polynomial
for i = 1:number_of_terms
for j = 1:number_of_terms
A(i,j) = sum(x.^(i+j-2));
end
%A(1,1) = columns; % this is only for when you want to force the first point through zero
b_element = sum(y .* x.^(i-1));
b(i) = b_element;
b(1) = sum(y);
end
z = A \ b;
z = flip(z); % descending order
Sample_Domain = linspace(0, 1.0, 100);
Y = polyval(z, Sample_Domain);
% plotting OCV curve
figure(3)
hold on
plot(x, y, 'MarkerFaceColor', 'r', 'linewidth', 3, 'color', 'r')
plot(Sample_Domain, Y, '--', 'linewidth', 3, 'color', [0 0 0])
grid
legend('data', 'polynomial of best fit', 'Location', 'southeast')
title('OCV(SOC) polynomial')
xlabel('SOC')
ylabel('OCV (V)')
set(gca, 'fontsiz', 16)