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!