-
Notifications
You must be signed in to change notification settings - Fork 20
/
VQlinspace3.m
56 lines (48 loc) · 1.8 KB
/
VQlinspace3.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
function [ Qlin, Vlin, Tlin ] = VQlinspace3( cycle )
%VQlinspace2 returns a linearly-spaced V vs Q curve
% Inputs: cycle (i.e. batch(i).cycles(j))
% Outputs: Qlin, Vlin = linearly spaced Qdis vs Vdis
%VQlinspace2 uses time/current to generate discharge capacity due to
%discrepancy for Qdischarge. This produces a "smoother" and more
%physically meaningful discharge curve
% Last modified October 31, 2017
%% 1. Create Vlin
n_points = 1000; % number of points to linearly interpolate between
V1 = 2.0;
V2 = 3.5;
% Old code below - use Vlin to keep consistent with IDCA (only one vector)
% spacing = (V2 - V1) / (n_points - 1);
% Vlin = V1:spacing:V2; % voltage range for interpolation
Vlin=linspace(V2,V1,n_points);
%% 2. Get the indices of all currents ~ -4 C, i.e. discharge indices.
% OLD: For all policies, we discharge at 4C (= -4.4A)
Irounded = round(cycle.I);
Idischarge = mode(Irounded(cycle.I<0));
indices = find(abs(cycle.I+(-Idischarge)) < 0.05);
% Remove trailing data points
[~, index2] = min(cycle.V(indices(1:end-2)));
indices = indices(1:index2);
%% 3. Extract Q_dis:
V_dis_raw = cycle.V(indices);
try % Q_dis_raw occasionally gives errors
Q_dis_raw = -(cycle.t(indices)-cycle.t(indices(1)))./60.*cycle.I(indices).*1.1;
%% 4. Fit to function. Ensure data is nearly untransformed
VQfit = fit(V_dis_raw,Q_dis_raw, 'smoothingspline');
%% 5. Linearly interpolate
Qlin = VQfit(Vlin);
catch
warning('VQlinspace2 failed - Qlin')
Qlin = zeros(length(Vlin),1);
end
%% 6. Extract T_dis
T_dis_raw = cycle.T(indices);
try
%% 7. Fit to function. Ensure data is nearly untransformed
VTfit = fit(V_dis_raw,T_dis_raw, 'smoothingspline');
%% 8. Linearly interpolate
Tlin = VTfit(Vlin);
catch
warning('VQlinspace2 failed - Tlin')
Tlin = zeros(length(Vlin),1);
end
end