Remove steps of adjacent points
6 views (last 30 days)
Show older comments
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/734679/image.png)
0 Comments
Accepted Answer
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')
More Answers (1)
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!