How to synchronize three measurment data?
7 次查看(过去 30 天)
显示 更早的评论
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
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
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
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 个评论
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
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 Exchange 中查找有关 Measurements and Spatial Audio 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!