lines are not continuous
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ahmed Alalawi
el 11 de Nov. de 2019
Comentada: Ahmed Alalawi
el 11 de Nov. de 2019
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 comentario
Adam Danz
el 11 de Nov. de 2019
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.
Respuesta aceptada
Daniel M
el 11 de Nov. de 2019
Editada: Daniel M
el 11 de Nov. de 2019
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 comentarios
Daniel M
el 11 de Nov. de 2019
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);
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!