How to delete some signal parts ?

11 views (last 30 days)
JPTheCoach
JPTheCoach on 26 Mar 2019
Answered: JPTheCoach on 19 Jun 2019
Hi thank you all for the help.
In attached figure an accelerometric signal is shown (Y axis report acceleration magnitude, X axis report timestamps from start time to sample, [0 value]).
I want to use first part of signal as a model (The piece of signal with magnitude lower than 2 g), the rest part of signal is abnormal: How can i use first part as a model and replace piece of signal significatly different from that model ? is it possibile compair every subpart of abnormal signal with right signal model ? :-D
Thank you to all, i appreciate every suggestion :-)
  4 Comments
JPTheCoach
JPTheCoach on 8 Apr 2019
Thank you men,
Walter : in your strategy sample points will be good samples before the high peaks ? (In picture all samples with offset timestamp < 50 sec)
Adam : threshold could be medium of samples, the high peaks made it very high (Usually is between 3 and 2 g on y axis), but i don't know if this criteria works in another cases ...
Walter Roberson
Walter Roberson on 8 Apr 2019
For 'Samplepoints' you would pass in the x coordinates corresponding to the samples you wish to consider as "normal".

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 8 Apr 2019
Edited: Adam Danz on 15 Apr 2019
Walter 's suggestion would look something like this (below) but for my fake data, few to no outliers were detected. That might be due to how I'm generating the fake data or implenting the outlier detection.
% Make fake data & visualize it
data = [rand(1,500), rand(1,1000)*3];
t = seconds(linspace(0,100, length(data)));
figure
plot(t, data)
% detect outliers that are > 3 std from moving mean (window size = 5sec)
isout = isoutlier(data, 'movmean', seconds(5), 'Samplepoints', t);
% Plot results (if any)
find(isout) % <-- are there any outliers detected?
hold on
plot(t(isout), data(isout), 'r')
Here is another suggestion below using kmeans-clustering. First I take the moving maximum over a window of 10 samples (you can play around with that window size). That smooths out the data a bit. Then I use kmean() to cluster the moving maxima into two clusters. We don't know whether the first part of your signal will be assigned to cluster 1 or cluster 2 so we just look for the first time that cluster index changes. I draw a red line where the cluster first changes so you can see how the signal is separated from the following noise.
% USING THE SAME FAKE DATA FROM THE BLOCK OF CODE ABOVE
% Assign clusters
cluster = kmeans(movmax(data, 10)',2); %input 1 must be column vector
% Find first index where cluster changes
changeIdx = find(cluster ~= cluster(1), 1);
% Plot results
figure
plot(t, data)
% Show x value where pattern changes
hold on
plot(t(changeIdx*[1,1]), [min(ylim),max(ylim)], 'r-', 'LineWidth', 3)
% create index of signal so you can separate it as needed....
isSignal = true(size(data));
isSignal(changeIdx:end) = false;

More Answers (1)

JPTheCoach
JPTheCoach on 19 Jun 2019
Thanks to everyone!! have a good day

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!