![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1589461/image.png)
How to synchronize three measurment data?
4 views (last 30 days)
Show older comments
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 Comment
George Abrahams
on 12 Jan 2024
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1589461/image.png)
Accepted Answer
Star Strider
on 12 Jan 2024
Edited: Star Strider
on 13 Jan 2024
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
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
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]
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
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 Comments
Alexander
on 12 Jan 2024
Edited: Alexander
on 13 Jan 2024
@Star Strider I think also, that the data acquisition is strange. If I perform a diff of the time axis it looks like that:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1589616/image.jpeg)
Sample rate 0, 0.2, 1 (*10^-3). Hence, the data are also inconsistend. A snippet of the data:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1589621/image.jpeg)
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
on 12 Jan 2024
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!