how to time shift a set of data?

18 ビュー (過去 30 日間)
Govind Sankar Madhavan Pillai Ramachandran Nair
回答済み: Mathieu NOE 2025 年 9 月 30 日 15:30
I have a plot of 12 cell voltages like this. There is also current here as yyaxis right, but ignore that. I forgot to remove the current, its not needed.
As you can see its unbalanced, 11 values are similar and 12th is off. The idea to solve this to time shift the 11 values to a common starting point. So make all values start from 3.6.
you can see the black lines i drew. I am trying to plot just those values. But the issue is when reduce the 11 cells starting from 3.6 then the size of those 11 values is different from the 12th value. The 12th cell size would be larger and i cant have that, because this is a 2d array and all the columns should be of same size. So i extrapolate using time of the 12th cell and time of other 11 cells, then i get value of 11 cells to have many 3.6V. The plot will be like this.
The extrapolate function i wrote is this:
11CellVoltExtrapolated = interp1(11CellsTime,11CellVolt,Timeof12thCell,'linear', 'extrap');
So this is the problem. Also I cannot have nan values, because i need this array for other functions which cannot have nan values. How can i do this. Thank you.
  2 件のコメント
Mathieu NOE
Mathieu NOE 2025 年 9 月 30 日 13:50
can you share your data ?
Govind Sankar Madhavan Pillai Ramachandran Nair
This are the two data, i hope with the name, it is self explanatory what each data is.

サインインしてコメントする。

回答 (1 件)

Mathieu NOE
Mathieu NOE 2025 年 9 月 30 日 15:30
so this is what I tried in order to time shift the 12th voltage vs the others
  • find the indexes for the last sample above 3.6 V
  • compute the difference between this index for the 12 th curve vs the others (here you can opt either min, mean or max of the 11 first indexes. To have the final curve starting right underneath the others , use "min")
  • the final array has the first 11 data truncated (beginning) and the 12 th voltagetruncated (beginning & end)
  • be carefull with extrapolation because this leads quite often to bad results - it's up to you if your really need to go that route. I have not implemented any extrapolation here because I have some relunctance doing so
  • the time shifted version of the 12 th voltage appears in thick green in the second plot below
hope it helps !
load("CellData without bringing down to 3.6V.mat")
data = table2array(CellData);
t = data(:,1);
Voltages = data(:,3:end);
figure
plot(t,Voltages)
start = 3.6
start = 3.6000
for k = 1:size(Voltages,2)
ind(k) = find(Voltages(:,k)>=start,1,'last');
end
% time shift the 12th voltage
% start_ind_11 = round(mean(ind(1:11)));
start_ind_11 = round(min(ind(1:11)));
% start_ind_11 = round(max(ind(1:11)));
shift = start_ind_11 - ind(12);
% now remove the initial samples for the first 11 voltages
newVolt1to11 = Voltages(start_ind_11:end,1:11);
newt = t(start_ind_11:end);
% now remove the initial and endind samples for the last voltage
newVolt12 = Voltages(ind(12):end-shift,12);
figure
plot(newt,newVolt1to11)
hold on
plot(newt,newVolt12,'g--','linewidth',2)
% combine data into single array
newVolt = [newVolt1to11 newVolt12];

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by