lines are not continuous
조회 수: 2 (최근 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
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
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
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);
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!