How to compare signals' shape?
9 views (last 30 days)
Show older comments
HI! My question is concerning sets of signals acquired by motion system - already normalized to same length. (This is knee flexion and extention during the gait cycle)

I would like to make a program to simply clasiffy signals by its shape. Let'say I have 50 signals and I want the program to find only 5 that behave the same - are alike - represent the gait cycle of patient. I know that this is quite complex since there is more to be considered (time shift, amplitude, etc.). I was thinking some method like kNN, mean square? Any ideas or experiences are welcomed.
0 Comments
Accepted Answer
Star Strider
on 3 Mar 2016
If they are all sampled at the same times (so you would have to interpolate them to the same sampling times and not just normalise them for length), the k-th nearest neighbour would be my choice as the simplest classifier.
A simple k-th nearest neighbour classifier is:
ClassVectors = randi(10, 3, 5); % Class Vectors (3x5)
DataVectors = randi(10, 15, 5);
for k1 = 1:size(ClassVectors,1)
for k2 = 1:size(DataVectors,1)
d(k2,k1) = sqrt(sum((ClassVectors(k1,:)-DataVectors(k2,:)).^2));
end
end
[~,ClassMember] = min(d, [], 2);
Then use the sort function to return the five with the lowest distances to your class vector.
3 Comments
Star Strider
on 3 Mar 2016
My pleasure!
In that instance, duplicate your vectors in both my ‘ClassVectors’ and ‘DataVectors’ arrays. You are then comparing all of them with each other.
For example:
KneeFlex = randi(50, 5, 10);
ClassVectors = KneeFlex; % Class Vectors (3x5)
DataVectors = KneeFlex;
for k1 = 1:size(ClassVectors,1)
for k2 = 1:size(DataVectors,1)
d(k2,k1) = sqrt(sum((ClassVectors(k1,:)-DataVectors(k2,:)).^2));
end
end
[Dist,ClassMember] = sort(d); % Choose The Appropriate Function Here
I’m not sure how you want to sort them, so I’ll leave that to you. The sort function returns the indices as well, so two functions that may help you are ind2sub and sub2ind.
If you want to sort ‘d’ as a vector instead of a matrix, use
[Dist,Idx] = sort(d(:));
then the ind2sub function to convert the ‘Idx’ back to subscripts to index into the original ‘d’ matrix. That will tell you the relationships of the closest vectors.
milad farasati
on 6 Jul 2021
it gives a weird shape when you go from k1 to k2... i dont think thats how you supposed to write the code!
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!