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!







