lines are not continuous

4 ビュー (過去 30 日間)
Ahmed Alalawi
Ahmed Alalawi 2019 年 11 月 11 日
コメント済み: Ahmed Alalawi 2019 年 11 月 11 日
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 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by