Removing jumps from data when plotting a graph
이전 댓글 표시
I am trying to plot sensor readings. See attached the data and the graph. Please I need a help on how to remove those jumps in the graph (space between the 2 red markings). I would like to apply same to the remaing jumps in the graph. Any help is well appreciated.
댓글 수: 4
Matt Gaidica
2021년 1월 19일
편집: Matt Gaidica
2021년 1월 19일
Austin, need some more details (what kind of sensor is this?). For example, if I zoom in on one of the smaller discontinuities, it's not a very sharp jump, it kind of stumbles downwards.
- What information are you trying to maintain?
- What constitutes a "jump" (i.e. dy/dx)?

Have you tried plotting diff() of your signal, and does that highlight the trouble areas sufficiently?
Austin Ukpebor
2021년 1월 19일
편집: Austin Ukpebor
2021년 1월 21일
Star Strider
2021년 1월 19일
If you are calculating the numerical derivative, use the gradient function. It produces an output that has the same dimensions as the input.
Austin Ukpebor
2021년 1월 19일
채택된 답변
추가 답변 (2개)
Fangjun Jiang
2021년 1월 19일
0 개 추천
In your case, since you have enough data, I think you can use symbol in plot() to remove the "jump".
If your old way is plot(x,y), then you can use plot(x,y,'.')
Matt Gaidica
2021년 1월 19일
What do you want to do with the data that around the jumps (still referring to my previous figure)? Interpolate it? Maybe you want some type of dynamic detrending, but it still doesn't totally remove the artifact of the jumps. I just loaded your data in A.
y = smoothdata(A,'movmean',100);
close all
figure;
subplot(211);
plot(A);
hold on;
plot(y);
subplot(212);
plot(A-y);

댓글 수: 9
Austin Ukpebor
2021년 1월 20일
Matt Gaidica
2021년 1월 20일
편집: Matt Gaidica
2021년 1월 20일
Would it be possible to hand select some of those discontinuities as a semi-automatic approach? Given the first figure I showed, you're going to have some issues stitching these data back together.
I think you're going to have to (1) figure out how to detrend or re-align the data then (2) filter remaining discontinuities or smooth it. Here's one last idea, maybe you can get those numbers (e.g., 200, 50, 20) to play nice with your data, or get close enough to analyze it:
y = movmax(A,200);
B = abs(A - y);
TF = smoothdata(B,'movmed',50);
C = B;
C(TF > median(B) * 20) = 0;
close all
ax = [];
figure;
ax(1) = subplot(211);
plot(A);
ax(2) = subplot(212);
plot(B);
hold on;
plot(C);
linkaxes(ax,'x');


Austin Ukpebor
2021년 1월 20일
Austin Ukpebor
2021년 1월 20일
Matt Gaidica
2021년 1월 20일
I posted the code above. In https://www.mathworks.com/matlabcentral/answers/720594-removing-jumps-from-data-when-plotting-a-graph#comment_1273664
Austin Ukpebor
2021년 1월 20일
Matt Gaidica
2021년 1월 20일
That's just zoomed in. Sorry for the confusion.
Austin Ukpebor
2021년 1월 21일
Matt Gaidica
2021년 1월 21일
Sure thing, sounds like a cool project. Feel free to reach out directly if you need anything!
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







