lines are not continuous

3 次查看(过去 30 天)
Hello there
I have data which supposed to look like waves. But for some reasons, the lines are not continuous.
I have attached the data and also the figure. I marked the figure with red to show how the data supposed to look like.
Anyone has an idea of how to fix that?
Thank you
  1 个评论
Adam Danz
Adam Danz 2019-11-11
I wonder why the data came out like that in the first place. Where did the data come from? Is it the result of a sensor hitting a bound or something like that?
I'd start with findpeak() to locate the indices where the sharp peaks form and then use those indices to isolate flipped segments.

请先登录,再进行评论。

采纳的回答

Daniel M
Daniel M 2019-11-11
编辑:Daniel M 2019-11-11
It's not perfect, but it might be sufficient. That's up to you. Play with the different values for dipreset. You might want to smooth the several samples around the 'entry' and 'exit' points.
clearvars
clc
close all
data = load('task.mat');
task = data.task;
% get the location of the peaks
[pks,locs] = findpeaks(task,'MinPeakHeight',15);
% show the data with the identified peaks
figure
plot(task)
hold on
plot(locs,pks,'v')
% this will fail if there are not an even number of peaks
locpairs = reshape(locs,2,[]);
task2 = task; % temporary duplicate
for k = 1:size(locpairs,2)
% get the locations between the first dip
diplocs = locpairs(1,k):locpairs(2,k);
dipval = task(diplocs); % get the values
% get reset value
% dipreset = min(dipval([1 end]));
% dipreset = mean(dipval([1 end]));
dipreset = dipval(1);
% reset dipval
dipval = abs(dipval - dipreset) + dipreset;
task2(diplocs) = dipval; % store result
end
hold on
plot(task2)
% view the output
  2 个评论
Daniel M
Daniel M 2019-11-11
One smoothing attempt might be to add these lines in the loop at the bottom.
% smooth entry
dt = 4;
en = locpairs(1,k);
task2(en-dt:en+dt) = smooth(task2(en-dt:en+dt),2*dt+1,'sgolay',1);
% smooth exit
ex = locpairs(2,k);
task2(ex-dt:ex+dt) = smooth(task2(ex-dt:ex+dt),2*dt+1,'sgolay',1);
Ahmed Alalawi
Ahmed Alalawi 2019-11-11
Thank you Daniel
You saved my day!

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by