RMSD between two signals
이전 댓글 표시
Hello saviors,
I am struggling with a structural health monitoring project. I'm expected to code the RMSD between two signals (one reference signal and another signal calculated by a sensor).
I did a first attempt but it didn't work. I'm a beginner at matlab so maybe my mistake is dumb but I would appreciate any help or clue. This is my code :
clc
clear
close all
load ('probewithwithout.mat')
RMSd = []
time = 1:1:1;
positions = 1:1:2;
for i = time
for j = positions
RMSd(i,j) = sqrt(sum((time(i).probewith(:,j)-time(i).probewithout(:,j)).^2)/sum(time(i).probewithout(:,j).^2));
end
end
With the file "probewithwithout" (means probe with crack and without crack), I have this in which I stored my data in the form of vectors :

I'm so confused I don't even know what I don't know anymore.
Thanks in advance!
댓글 수: 1
jessupj
2020년 9월 17일
do you mean to multiply time(i) by probewith(:,j) in the loop? change those '.' to '.*' it should be yelling at you that dot indexing ins't supported for your scalar object 't'
sqrt(sum((time(i).*probewith(:,j)-time(i).*probewithout(:,j)).^2)/sum(time(i).*probewithout(:,j).^2));
답변 (1개)
Looking at your variables in the workspace I see the signals probeWith and probeWithout. Each arrays with two columns. I assume each column is for a position of the sensors. Think of each array as two column vectors side by side.
You could compute rmsd as:
% compute deviations
deviation = probeWith - probeWithout % column vector of deviation values
% compute covariance
cov = deviation'*deviation % note ' on first term makes it a row vector
% compute rmsd (don't need the cross terms)
rmsd = diag(sqrt(cov))
Note the inner product (row vector time column vector) above computes the sum of the squared deviation
댓글 수: 4
jessupj
2020년 9월 17일
they look like 2501x2 (i.e. not vectors) to me. this won't work
Jon
2020년 9월 17일
I'm not sure if you saw my post before I edited. I initially missed that you had two columns of data and needed to modify my response
Jon
2020년 9월 17일
Since I assume you are only interested in the deviations between the signals at the same location (column in your probe matrices) you could also loop over the locations. This would perhaps make it more obvious what you were calculating, but usually in MATLAB it is nice to take advantage of its ability to handle matrix vector operations without loops. Just to illustrate this would look like:
rmsd = zeros(2,1); % preallocate array to hold result
for k = 1:2 % loop over positions
deviation = probeWith(:,k) - probeWithout(:,k);
rmsd(k) = sqrt(deviation'*deviation);
end
Jon
2020년 9월 17일
@jessup Sorry we got out of synch, I saw that there were two columns and started editing my initial reply accordingly and then came back and later saw your comment. I think the answer is OK now with the two columns
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!