フィルターのクリア

How to synchronize three measurment data?

6 ビュー (過去 30 日間)
Mathias Braun
Mathias Braun 2024 年 1 月 12 日
編集済み: Star Strider 2024 年 1 月 13 日
I've done three measurments with the from one experiement. Now I have the .csv data and want to synchronize those three data sets for example with their maximum. How do I plot them and how can i get a median from all data?
In the csv data, the first variable is the time, the second one is a force. The third one is not necessary for ploting.
Thank you for your help guys.
  1 件のコメント
George Abrahams
George Abrahams 2024 年 1 月 12 日
Virus scans for the attached files: Messung1.csv, Messung2.csv, Messung3.csv. Nothing malicious found.
The three matrices have sizes Nx3, Mx3, Px3. As time can't be 3D, I think that @Mathias Braun means that the first column is time and the second column is force. Presumably each matrix is from a repeat of the experiment and you want to average them to remove noise. The data looks like this:

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

採用された回答

Star Strider
Star Strider 2024 年 1 月 12 日
編集済み: Star Strider 2024 年 1 月 13 日
This turned out to be a bit more involved than I thought it would be. The data matrices do not have the same lengths and the sampling times are close, however not standardised or constant. The first task was to use the findsignal function to locate the signal delay and then standardise for it. This then required resampling (using the resample function) the time vectors to a common sampling frequency, and then truncating the table arrays so that they all had the same starting and ending times, and the same row sizes. After that, calculating the statistics was straightforward.
Try this —
files = dir('*.csv');
for k = 1:numel(files)
T{k,:} = readtable(files(k).name);
T{k}.Properties.VariableNames([1 2]) = {'Time','Force'}; % Create Individual 'table' Arrays From Files
end
for k = 1:numel(T)
fprintf('\n--------------------\n\t\tFile: %s —\n',files(k).name)
Data = T{k} % Display 'table' Arrays
end
-------------------- File: Messung1.csv —
Data = 216222×3 table
Time Force Var3 ______ ________ _______ 4.3372 0.14522 0.15575 4.3374 0.14522 0.15575 4.3376 0.14522 0.15575 4.3378 0.14522 0.15575 4.338 0.14522 0.15575 4.3382 0.14522 0.15575 4.3384 0.14522 0.15575 4.3386 0.14522 0.15575 4.3388 0.14522 0.15575 4.339 0.14522 0.15575 4.3392 0.20898 0.28217 4.3394 0.017689 0.21896 4.3396 0.017689 0.21896 4.3398 0.017689 0.21896 4.34 0.017689 0.21896 4.3402 0.017689 0.21896
-------------------- File: Messung2.csv —
Data = 166806×3 table
Time Force Var3 ______ _________ _________ 0.0158 0.017689 -0.16032 0.016 -0.046074 -0.033894 0.0162 -0.046074 -0.033894 0.0164 -0.046074 -0.033894 0.0166 -0.046074 -0.033894 0.0168 -0.046074 -0.033894 0.017 -0.046074 -0.033894 0.0172 -0.046074 -0.033894 0.0174 -0.046074 -0.033894 0.0176 -0.046074 -0.033894 0.0178 -0.046074 -0.033894 0.018 -0.046074 -0.033894 0.0182 -0.046074 -0.033894 0.0184 -0.046074 -0.033894 0.0186 0.017689 -0.097108 0.0188 0.017689 -0.033894
-------------------- File: Messung3.csv —
Data = 170370×3 table
Time Force Var3 ______ ________ _________ 0.0158 -0.10984 -0.033894 0.016 -0.10984 0.02932 0.0162 -0.10984 0.02932 0.0164 -0.10984 0.02932 0.0166 -0.10984 0.02932 0.0168 -0.10984 0.02932 0.017 -0.10984 0.02932 0.0172 -0.10984 0.02932 0.0174 -0.10984 0.02932 0.0176 -0.10984 0.02932 0.0178 -0.10984 0.02932 0.018 -0.10984 0.02932 0.0182 -0.10984 0.02932 0.0184 -0.10984 0.02932 0.0186 -0.10984 0.02932 0.0188 0.081453 0.02932
figure
hold on
for k = 1:numel(T)
plot(T{k}.Time, T{k}.Force, 'DisplayName',["Table "+k])
end
hold off
grid
xlabel('Time')
ylabel('Force')
title('Original Data')
legend('Location','best')
istart = zeros(size(T)); % Preallocate
istop = istart;
dist = istop;
for k = 1:numel(T)-1 % Use T{end} As Standard Reference
[i1,i2,d3] = findsignal(T{k}.Force, T{end}.Force);
if ~isempty(i1)
istart(k) = i1;
istop(k) = i2;
dist(k) = d3;
end
end
figure
hold on
for k = 1:numel(T)
[t1(k,:),t2(k,:)] = bounds(T{k}.Time);
if istart(k) ~= 0
T{k}.Time = T{k}.Time - T{k}.Time(istart(k));
T{k}.Force = T{k}.Force(1:numel(T{k}.Time));% + 100;
end
len(k,:) = numel(T{k}.Time);
ts(k,:) = [mean(diff(T{k}.Time)) std(diff(T{k}.Time)) 1/mean(diff(T{k}.Time))];
[Force,Time] = resample([T{k}.Force T{k}.Var3], T{k}.Time, 5E+3); % Resample To Common Time BAse
Tr{k} = table(Time,Force(:,1),Force(:,2));
Tr{k}.Properties.VariableNames = {'Time','Force','Var3'};
plot(T{k}.Time, T{k}.Force, 'DisplayName',["Table "+k])
end
hold off
grid
xlabel('Time')
ylabel('Force')
title('Shifted & Resampled Data')
legend('Location','best')
for k = 1:numel(Tr)
fprintf('\n--------------------\n\t\tFile: %s —\n',files(k).name)
Resampled_Shifted_Data = Tr{k} % Display 'table' Arrays
end
-------------------- File: Messung1.csv —
Resampled_Shifted_Data = 216220×3 table
Time Force Var3 _______ ________ _______ -5.14 0.14522 0.15575 -5.1398 0.14522 0.15575 -5.1396 0.14522 0.15575 -5.1394 0.14522 0.15575 -5.1392 0.14522 0.15575 -5.139 0.14522 0.15575 -5.1388 0.14522 0.15575 -5.1386 0.14522 0.15575 -5.1384 0.14522 0.15575 -5.1382 0.14522 0.15575 -5.138 0.20898 0.28217 -5.1378 0.017689 0.21896 -5.1376 0.017689 0.21896 -5.1374 0.017689 0.21896 -5.1372 0.017689 0.21896 -5.137 0.017689 0.21896
-------------------- File: Messung2.csv —
Resampled_Shifted_Data = 166807×3 table
Time Force Var3 ______ _________ _________ 0.0158 0.017689 -0.16032 0.016 -0.046074 -0.033894 0.0162 -0.046074 -0.033894 0.0164 -0.046074 -0.033894 0.0166 -0.046074 -0.033894 0.0168 -0.046074 -0.033894 0.017 -0.046074 -0.033894 0.0172 -0.046074 -0.033894 0.0174 -0.046074 -0.033894 0.0176 -0.046074 -0.033894 0.0178 -0.046074 -0.033894 0.018 -0.046074 -0.033894 0.0182 -0.046074 -0.033894 0.0184 -0.046074 -0.033894 0.0186 0.017689 -0.097108 0.0188 0.017689 -0.033894
-------------------- File: Messung3.csv —
Resampled_Shifted_Data = 170372×3 table
Time Force Var3 ______ ________ _________ 0.0158 -0.10984 -0.033894 0.016 -0.10984 0.02932 0.0162 -0.10984 0.02932 0.0164 -0.10984 0.02932 0.0166 -0.10984 0.02932 0.0168 -0.10984 0.02932 0.017 -0.10984 0.02932 0.0172 -0.10984 0.02932 0.0174 -0.10984 0.02932 0.0176 -0.10984 0.02932 0.0178 -0.10984 0.02932 0.018 -0.10984 0.02932 0.0182 -0.10984 0.02932 0.0184 -0.10984 0.02932 0.0186 -0.10984 0.02932 0.0188 0.081453 0.02932
figure
hold on
for k = 1:numel(Tr)
[t1(k,:),t2(k,:)] = bounds(T{k}.Time);
plot(Tr{k}.Time, Tr{k}.Force, 'DisplayName',["Resampled Table "+k])
end
hold off
grid
xlabel('Time')
ylabel('Force')
title('Shifted & Resampled Data')
legend('Location','best')
Tbounds = [t1 t2]
Tbounds = 3×2
-5.1400 38.1038 0.0158 33.3770 0.0158 34.0900
for k = 1:numel(Tr)
fprintf('\n--------------------\n\t\tFile: %s —\n',files(k).name)
Lv = Tr{k}.Time >= max(Tbounds(:,1)) & Tr{k}.Time <= min(Tbounds(:,2));
Tr{k} = Tr{k}(Lv,:);
Standardised_Resampled_Shifted_Data = Tr{k} % Display 'table' Arrays
end
-------------------- File: Messung1.csv —
Standardised_Resampled_Shifted_Data = 166807×3 table
Time Force Var3 ______ _______ _______ 0.0158 0.40027 0.97753 0.016 0.40027 0.97753 0.0162 0.40027 0.97753 0.0164 0.40027 0.97753 0.0166 0.40027 0.97753 0.0168 0.40027 0.97753 0.017 2.8233 0.59824 0.0172 3.4609 0.66146 0.0174 3.4609 0.66146 0.0176 3.4609 0.66146 0.0178 3.4609 0.66146 0.018 3.4609 0.66146 0.0182 3.4609 0.66146 0.0184 3.4609 0.66146 0.0186 3.4609 0.66146 0.0188 3.4609 0.66146
-------------------- File: Messung2.csv —
Standardised_Resampled_Shifted_Data = 166807×3 table
Time Force Var3 ______ _________ _________ 0.0158 0.017689 -0.16032 0.016 -0.046074 -0.033894 0.0162 -0.046074 -0.033894 0.0164 -0.046074 -0.033894 0.0166 -0.046074 -0.033894 0.0168 -0.046074 -0.033894 0.017 -0.046074 -0.033894 0.0172 -0.046074 -0.033894 0.0174 -0.046074 -0.033894 0.0176 -0.046074 -0.033894 0.0178 -0.046074 -0.033894 0.018 -0.046074 -0.033894 0.0182 -0.046074 -0.033894 0.0184 -0.046074 -0.033894 0.0186 0.017689 -0.097108 0.0188 0.017689 -0.033894
-------------------- File: Messung3.csv —
Standardised_Resampled_Shifted_Data = 166807×3 table
Time Force Var3 ______ ________ _________ 0.0158 -0.10984 -0.033894 0.016 -0.10984 0.02932 0.0162 -0.10984 0.02932 0.0164 -0.10984 0.02932 0.0166 -0.10984 0.02932 0.0168 -0.10984 0.02932 0.017 -0.10984 0.02932 0.0172 -0.10984 0.02932 0.0174 -0.10984 0.02932 0.0176 -0.10984 0.02932 0.0178 -0.10984 0.02932 0.018 -0.10984 0.02932 0.0182 -0.10984 0.02932 0.0184 -0.10984 0.02932 0.0186 -0.10984 0.02932 0.0188 0.081453 0.02932
ForceMtx = zeros(size(Tr{1},1), numel(Tr));
for k = 1:numel(Tr)
ForceMtx(:,k) = Tr{k}.Force;
end
Force_Median = median(ForceMtx,2);
Force_Mean = mean(ForceMtx, 2);
Force_Std = std(ForceMtx, [], 2);
Force_SEM = Force_Std/sqrt(size(ForceMtx,2));
tci95 = tinv([0.025 0.975], size(ForceMtx,2)-1);
Force_95CI = Force_Mean + Force_SEM*tci95;
figure
hold on
for k = 1:numel(Tr)
[t1(k,:),t2(k,:)] = bounds(T{k}.Time);
plot(Tr{k}.Time, Tr{k}.Force, 'DisplayName',["Resampled Table "+k])
end
plot(Tr{1}.Time, Force_Median, '-r', 'LineWidth',1, 'DisplayName','Force Median')
hold off
grid
xlabel('Time')
ylabel('Force')
title('Time Standardised Shifted & Resampled Data')
legend('Location','best')
EDIT — (12 Jan 2024 at 17:00)
Corrected typograpical error, added 95% confidence interval calculations.
EDIT — (13 Jan 2024 at 02:12)
Put the findsignal call in a loop and use the last table as the common reference for the others.
EDIT — (13 Jan 2024 at 11:20)
Improved efficiency using the findsignal loop and the findsignal outputs.
.
  2 件のコメント
Alexander
Alexander 2024 年 1 月 12 日
編集済み: Alexander 2024 年 1 月 13 日
@Star Strider I think also, that the data acquisition is strange. If I perform a diff of the time axis it looks like that:
Sample rate 0, 0.2, 1 (*10^-3). Hence, the data are also inconsistend. A snippet of the data:
I'm not sure where it's comming from, but I guess it's from a float-double problem of the acquisition system.
Star Strider
Star Strider 2024 年 1 月 12 日
The whole point is to equalise the samping frequencies and normalise the time vectors so that all the records start and stop at the same times. This creates an ensemble from which the necessary statistics can be calculated.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by