Remove steps of adjacent points

7 views (last 30 days)
Konvictus177
Konvictus177 on 10 Sep 2021
Edited: Matt J on 10 Sep 2021
Hi,
I have a signal which shows repeating lower peaks due to end point and new starting point being on a different level. What is the fastest and easiest way to remove the step/peak and lift all points to the right in such a way that the two connecting points are on the same level and the rest of the signal is lifted with the same amount.
Thanks.

Accepted Answer

Matt J
Matt J on 10 Sep 2021
Edited: Matt J on 10 Sep 2021
Perhaps as follows:
threshold=0.5;
t=0:0.01:3;
signal=log(mod(t,1)+1);
D=diff(signal(:).');
D(abs(D)>threshold)=0;
signal2=cumsum([signal(1),D]);
plot(t,signal, '-x',t,signal2); legend('Original','Modified')
  1 Comment
Matt J
Matt J on 10 Sep 2021
Edited: Matt J on 10 Sep 2021
If the jumps are occuring at known intervals N, you could also do,
D=diff(signal(:).');
D(N:N:end)=0;
signal2=cumsum([signal(1),D]);

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 10 Sep 2021
You said you have "lower peaks due to end point". So it's always the last point that drops. So the last point is bogus and should basically be ignored? Are you obtaining a sequence of signals, And then you just stitch on the next signal onto the master, growing signal? So you could do
allSignals = [];
for k = 1 : numberOfSignalsToStitch
thisSignal = HoweverYouGetIt();
% Crop off/ignore last element.
thisSignal(end) = [];
if k == 1
allSignals = thisSignal;
else
% Put first point where last point is
thisSignal = thisSignal - thisSignal(1) + allSignals(end);
% This will "lift" the current signal to the end of the last signal.
allSignals = [allSignals, thisSignal]
end
end
If you need more help, attach your signal(s) in a .mat file.
  1 Comment
Konvictus177
Konvictus177 on 10 Sep 2021
Edited: Konvictus177 on 10 Sep 2021
It is the new starting point that is on a lower level than the last point. So the new starting point would we bogus. This new starting point should not be removed but be on the same level as the last point like a straight line connection. All points after the first point should be lifted with the same amount the first point is lifted to make the straight connection.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!