How to match the rising starting point of the graph
1 view (last 30 days)
Show older comments
I want the graphs to have the same rising starting point.
Moving the graph by a certain value has a similar starting point.
However, it is very difficult and takes a long time to find the values one by one.
There is so much noise in the signal that I don't know how to code it.
I subtracted y(:,1) from the code to start from the origin.
4 Comments
dpb
on 21 May 2022
Alternately, one might consider a piecewise regression of the section from beginning to the peak. I've posted this several times, the one I found first is at <Piecewise Regression>
Accepted Answer
Star Strider
on 21 May 2022
This is my best effort. I could not get the other functions I tried (ischange, findchangepts, islocalmin, etc.) to work, so I went with a somewhat less-sophisticated approach that finds the approximate indices of the threshold, then uses those values to correct for the x-offsets —
LD = load('ld.mat');
x = LD.signal.x;
y = LD.signal.y;
L = numel(x);
yf = sgolayfilt(y, 3, 1501); % Filter Signal
Threshold = 0.000075;
for k = 1:size(y,2)
zci(k) = find(diff(sign(yf(:,k)-Threshold)),1,"first") % Index Of First Threshold-Crossing
end
Lmax = L-max(zci)-1000; % Maximum Vector Length
Offset = 2500; % Set To 0 To Begin At Origin
for k = 1:size(y,2)
idxrng = (zci(k) : zci(k)+Lmax)-Offset; % Index Range With Initial Offset
yfc(:,k) = yf(idxrng,k); % Filtered, Corrected
yc(:,k) = y(idxrng,k); % Original, Corrected
end
figure
plot(x(1:Lmax+1),yfc)
grid
title('Filtered, Shift-Corrected')
legend(compose('y_%d',1:size(y,2)), 'Location','best')
figure
plot(x, yf)
grid
title('Filtered, Uncorrected')
legend(compose('y_%d',1:size(y,2)), 'Location','best')
figure
plot(x(1:Lmax+1), yc)
grid
title('Original, Shift-Corrected')
legend(compose('y_%d',1:size(y,2)), 'Location','best')
The code produces three plots, the third being the most relevant —
.
4 Comments
Star Strider
on 22 May 2022
My pleasure!
I use sgoiayfilt to filter the data in order to remove most of the noise. Without the filtering, with the noise left in, the problem is essentially impossible to solve.
If my Answer helped you solve your problem, please Accept it!
.
More Answers (0)
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!