Removing jumps from data when plotting a graph
Ältere Kommentare anzeigen
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 Kommentare
Matt Gaidica
am 19 Jan. 2021
Bearbeitet: Matt Gaidica
am 19 Jan. 2021
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
am 19 Jan. 2021
Bearbeitet: Austin Ukpebor
am 21 Jan. 2021
Star Strider
am 19 Jan. 2021
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
am 19 Jan. 2021
Akzeptierte Antwort
Weitere Antworten (2)
Fangjun Jiang
am 19 Jan. 2021
0 Stimmen
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,'.')
1 Kommentar
Austin Ukpebor
am 20 Jan. 2021
Matt Gaidica
am 19 Jan. 2021
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 Kommentare
Austin Ukpebor
am 20 Jan. 2021
Matt Gaidica
am 20 Jan. 2021
Bearbeitet: Matt Gaidica
am 20 Jan. 2021
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
am 20 Jan. 2021
Austin Ukpebor
am 20 Jan. 2021
Matt Gaidica
am 20 Jan. 2021
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
am 20 Jan. 2021
Matt Gaidica
am 20 Jan. 2021
That's just zoomed in. Sorry for the confusion.
Austin Ukpebor
am 21 Jan. 2021
Matt Gaidica
am 21 Jan. 2021
Sure thing, sounds like a cool project. Feel free to reach out directly if you need anything!
Kategorien
Mehr zu Descriptive Statistics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







