MATLAB Answers

RMSD between two signals

9 views (last 30 days)
Khawla Ouadie
Khawla Ouadie on 17 Sep 2020
Edited: Jon on 17 Sep 2020
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 Comment

jessupj
jessupj on 17 Sep 2020
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));

Sign in to comment.

Answers (1)

Jon
Jon on 17 Sep 2020
Edited: Jon on 17 Sep 2020
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 Comments

Show 1 older comment
Jon
Jon on 17 Sep 2020
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
Jon on 17 Sep 2020
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
Jon on 17 Sep 2020
@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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!