-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdataextractor.m
More file actions
283 lines (260 loc) · 11.6 KB
/
Copy pathdataextractor.m
File metadata and controls
283 lines (260 loc) · 11.6 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
function [t, I, V, S, T, t_charge, I_charge, V_charge, S_charge, T_charge] = dataextractor (t_, I_, V_, S_, T_)
%% Find local peaks as breakpoints
[~,maxlocs] = findpeaks(S_); % find values and locations of SOC local maximums (rising edge)
[minvals,minlocs] = findpeaks(-S_);
minvals = -minvals; % find values and locations of SOC local minimums (dropping edge)
if isempty(maxlocs) ==1 && isempty(minlocs) ==1 % single segment of charge or discharge
if mean(I_) > 0 % dischagre
for pulse_head = 1:length(S_)-1 % find pulse_head - where the discharge pulse started
diffS = S_(pulse_head+1)-S_(pulse_head);
if diffS ~= 0
break
end
end
t{1,1} = t_(pulse_head:end);
I{1,1} = I_(pulse_head:end);
V{1,1} = V_(pulse_head:end);
T{1,1} = T_(pulse_head:end);
S{1,1} = S_(pulse_head:end);
t_charge{1,1} = nan;
I_charge{1,1} = nan;
V_charge{1,1} = nan;
T_charge{1,1} = nan;
S_charge{1,1} = nan;
else % chagre
for pulse_head = 1:length(S_)-1 % find pulse_head - where the charge pulse started
diffS = S_(pulse_head+1)-S_(pulse_head);
if diffS ~= 0
break
end
end
t{1,1} = nan;
I{1,1} = nan;
V{1,1} = nan;
T{1,1} = nan;
S{1,1} = nan;
t_charge{1,1} = t_(pulse_head:end);
I_charge{1,1} = I_(pulse_head:end);
V_charge{1,1} = V_(pulse_head:end);
T_charge{1,1} = T_(pulse_head:end);
S_charge{1,1} = S_(pulse_head:end);
end
end
if isempty(maxlocs) ==0 && isempty(minlocs) ==1 % first chagre segment then discharge segment
% shift the location of SOC local maximum from rising edge to dropping edge
for nn = maxlocs(1):length(S_)-1
diffS = S_(nn+1)-S_(maxlocs(1));
if diffS ~= 0
maxlocs(1) = nn;
break
end
end
t{1,1} = t_(maxlocs(1):length(S_));
I{1,1} = I_(maxlocs(1):length(S_));
V{1,1} = V_(maxlocs(1):length(S_));
T{1,1} = T_(maxlocs(1):length(S_));
S{1,1} = S_(maxlocs(1):length(S_));
for pulse_head = 1:maxlocs(1) % find pulse_head - where the charge pulse started
diffS = S_(pulse_head+1)-S_(pulse_head);
if diffS ~= 0
break
end
end
t_charge{1,1} = t_(pulse_head:maxlocs(1));
I_charge{1,1} = I_(pulse_head:maxlocs(1));
V_charge{1,1} = V_(pulse_head:maxlocs(1));
T_charge{1,1} = T_(pulse_head:maxlocs(1));
S_charge{1,1} = S_(pulse_head:maxlocs(1));
end
if isempty(maxlocs) ==1 && isempty(minlocs) ==0 % first dischagre segment then charge segment
% shift the location of SOC local minimum from dropping edge to rising edge
for nn = minlocs(1):length(S_)-1
diffS = S_(nn+1)-S_(minlocs(1));
if diffS ~= 0
minlocs(1) = nn;
break
end
end
for pulse_head = 1:length(S_)-1 % find pulse_head - where the discharge pulse started
diffS = S_(pulse_head+1)-S_(pulse_head);
if diffS ~= 0
break
end
end
t{1,1} = t_(pulse_head:minlocs(1));
I{1,1} = I_(pulse_head:minlocs(1));
V{1,1} = V_(pulse_head:minlocs(1));
T{1,1} = T_(pulse_head:minlocs(1));
S{1,1} = S_(pulse_head:minlocs(1));
t_charge{1,1} = t_(minlocs(1):length(S_));
I_charge{1,1} = I_(minlocs(1):length(S_));
V_charge{1,1} = V_(minlocs(1):length(S_));
T_charge{1,1} = T_(minlocs(1):length(S_));
S_charge{1,1} = S_(minlocs(1):length(S_));
end
if isempty(maxlocs) ==0 && isempty(minlocs) ==0 % multiple segments of both discharge and chagre
for mm = 1:length(maxlocs) % shift the locations of SOC local maximums from rising edge to dropping edge
for nn = maxlocs(mm):length(S_)-1
diffS = S_(nn+1)-S_(maxlocs(mm));
if diffS ~= 0
maxlocs(mm) = nn;
break
end
end
end
for mm = 1:length(minlocs) % shift the locations of SOC local minimums from dropping edge to rising edge
for nn = minlocs(mm):length(S_)-1
diffS = S_(nn+1)-S_(minlocs(mm));
if diffS ~= 0
minlocs(mm) = nn;
break
end
end
end
%% identify wavefrom - number and order of peaks; split dicharge and charge segments
whocomesfirst=maxlocs(1)-minlocs(1); % local maximum or local minimum comes first?
if whocomesfirst < 0 % local maximum comes first
if length(maxlocs)==length(minlocs) % same number
for kk = 1:length(maxlocs)
t{kk,1} = t_(maxlocs(kk):minlocs(kk));
I{kk,1} = I_(maxlocs(kk):minlocs(kk));
V{kk,1} = V_(maxlocs(kk):minlocs(kk));
T{kk,1} = T_(maxlocs(kk):minlocs(kk));
S{kk,1} = S_(maxlocs(kk):minlocs(kk)); % dischagre segments
if kk == 1 % chagre segments
for pulse_head = 1:maxlocs(1) % find pulse_head - where the charge pulse started
diffS = S_(pulse_head+1)-S_(pulse_head);
if diffS ~= 0
break
end
end
t_charge{kk,1} = t_(pulse_head:maxlocs(kk));
I_charge{kk,1} = I_(pulse_head:maxlocs(kk));
V_charge{kk,1} = V_(pulse_head:maxlocs(kk));
T_charge{kk,1} = T_(pulse_head:maxlocs(kk));
S_charge{kk,1} = S_(pulse_head:maxlocs(kk));
else
if kk == length(maxlocs)
t_charge{kk+1,1} = t_(minlocs(kk):length(S_));
I_charge{kk+1,1} = I_(minlocs(kk):length(S_));
V_charge{kk+1,1} = V_(minlocs(kk):length(S_));
T_charge{kk+1,1} = T_(minlocs(kk):length(S_));
S_charge{kk+1,1} = S_(minlocs(kk):length(S_));
else
t_charge{kk,1} = t_(minlocs(kk-1):maxlocs(kk));
I_charge{kk,1} = I_(minlocs(kk-1):maxlocs(kk));
V_charge{kk,1} = V_(minlocs(kk-1):maxlocs(kk));
T_charge{kk,1} = T_(minlocs(kk-1):maxlocs(kk));
S_charge{kk,1} = S_(minlocs(kk-1):maxlocs(kk));
end
end
end
else % number of local maximums (one) more than that of local minimums
for kk = 1:length(maxlocs)-1
t{kk,1} = t_(maxlocs(kk):minlocs(kk));
I{kk,1} = I_(maxlocs(kk):minlocs(kk));
V{kk,1} = V_(maxlocs(kk):minlocs(kk));
T{kk,1} = T_(maxlocs(kk):minlocs(kk));
S{kk,1} = S_(maxlocs(kk):minlocs(kk));
end
t{length(maxlocs),1} = t_(maxlocs(length(maxlocs)):length(S_));
I{length(maxlocs),1} = I_(maxlocs(length(maxlocs)):length(S_));
V{length(maxlocs),1} = V_(maxlocs(length(maxlocs)):length(S_));
T{length(maxlocs),1} = T_(maxlocs(length(maxlocs)):length(S_));
S{length(maxlocs),1} = S_(maxlocs(length(maxlocs)):length(S_)); % dischagre segments
for kk = 1:length(maxlocs) % dischagre segments
if kk == 1
for pulse_head = 1:maxlocs(1) % find pulse_head - where the charge pulse started
diffS = S_(pulse_head+1)-S_(pulse_head);
if diffS ~= 0
break
end
end
t_charge{kk,1} = t_(pulse_head:maxlocs(kk));
I_charge{kk,1} = I_(pulse_head:maxlocs(kk));
V_charge{kk,1} = V_(pulse_head:maxlocs(kk));
T_charge{kk,1} = T_(pulse_head:maxlocs(kk));
S_charge{kk,1} = S_(pulse_head:maxlocs(kk));
else
t_charge{kk,1} = t_(minlocs(kk-1):maxlocs(kk));
I_charge{kk,1} = I_(minlocs(kk-1):maxlocs(kk));
V_charge{kk,1} = V_(minlocs(kk-1):maxlocs(kk));
T_charge{kk,1} = T_(minlocs(kk-1):maxlocs(kk));
S_charge{kk,1} = S_(minlocs(kk-1):maxlocs(kk));
end
end
end
else % local minimum comes first
if length(maxlocs)==length(minlocs) % same number
for kk = 1:length(minlocs)
if kk == 1
for pulse_head = 1:minlocs(1) % find pulse_head - where the discharge pulse started
diffS = S_(pulse_head+1)-S_(pulse_head);
if diffS ~= 0
break
end
end
t{kk,1} = t_(pulse_head:minlocs(kk));
I{kk,1} = I_(pulse_head:minlocs(kk));
V{kk,1} = V_(pulse_head:minlocs(kk));
T{kk,1} = T_(pulse_head:minlocs(kk));
S{kk,1} = S_(pulse_head:minlocs(kk));
else
t{kk,1} = t_(maxlocs(kk-1):minlocs(kk));
I{kk,1} = I_(maxlocs(kk-1):minlocs(kk));
V{kk,1} = V_(maxlocs(kk-1):minlocs(kk));
T{kk,1} = T_(maxlocs(kk-1):minlocs(kk));
S{kk,1} = S_(maxlocs(kk-1):minlocs(kk));
end
end
t{length(minlocs)+1,1} = t_(maxlocs(length(maxlocs)):length(S_));
I{length(minlocs)+1,1} = I_(maxlocs(length(maxlocs)):length(S_));
V{length(minlocs)+1,1} = V_(maxlocs(length(maxlocs)):length(S_));
T{length(minlocs)+1,1} = T_(maxlocs(length(maxlocs)):length(S_));
S{length(minlocs)+1,1} = S_(maxlocs(length(maxlocs)):length(S_)); % dischagre segments
for kk = 1:length(minlocs) % chagre segments
t_charge{kk,1} = t_(minlocs(kk):maxlocs(kk));
I_charge{kk,1} = I_(minlocs(kk):maxlocs(kk));
V_charge{kk,1} = V_(minlocs(kk):maxlocs(kk));
T_charge{kk,1} = T_(minlocs(kk):maxlocs(kk));
S_charge{kk,1} = S_(minlocs(kk):maxlocs(kk));
end
else % number of local minimums (one) more than that of local maximums
for kk = 1:length(minlocs)
if kk==1
for pulse_head = 1:minlocs(1) % find pulse_head - where the discharge pulse started
diffS = S_(pulse_head+1)-S_(pulse_head);
if diffS ~= 0
break
end
end
t{kk,1} = t_(pulse_head:minlocs(kk));
I{kk,1} = I_(pulse_head:minlocs(kk));
V{kk,1} = V_(pulse_head:minlocs(kk));
T{kk,1} = T_(pulse_head:minlocs(kk));
S{kk,1} = S_(pulse_head:minlocs(kk));
else
t{kk,1} = t_(maxlocs(kk-1):minlocs(kk));
I{kk,1} = I_(maxlocs(kk-1):minlocs(kk));
V{kk,1} = V_(maxlocs(kk-1):minlocs(kk));
T{kk,1} = T_(maxlocs(kk-1):minlocs(kk));
S{kk,1} = S_(maxlocs(kk-1):minlocs(kk)); % dischagre segments
end
if kk == length(minlocs) % chagre segments
t_charge{kk,1} = t_(minlocs(kk):length(S_));
I_charge{kk,1} = I_(minlocs(kk):length(S_));
V_charge{kk,1} = V_(minlocs(kk):length(S_));
T_charge{kk,1} = T_(minlocs(kk):length(S_));
S_charge{kk,1} = S_(minlocs(kk):length(S_));
else
t_charge{kk,1} = t_(minlocs(kk):maxlocs(kk));
I_charge{kk,1} = I_(minlocs(kk):maxlocs(kk));
V_charge{kk,1} = V_(minlocs(kk):maxlocs(kk));
T_charge{kk,1} = T_(minlocs(kk):maxlocs(kk));
S_charge{kk,1} = S_(minlocs(kk):maxlocs(kk));
end
end
end
end
end
end