Trying to use findpeaks to isolate the portion of the signal that has a positive slope

9 次查看(过去 30 天)
Hi
I have a voltage vs time signal and I'd like to isolate the parts with positive slope (minima to maxima) of this signal. I'm fairly inexperinced with matlab so I've been struggling with finding a way to cut out the parts I want.
I've used findpeaks to mark the peaks and valleys:
Fs=100;
[peaks_y,peaks_x]=findpeaks(PotentialV,Fs);
figure(1);
findpeaks(PotentialV,Fs);
title('maxima');
figure(2);
InvertedY= max(PotentialV)- PotentialV;
[valleys_y,valleys_x]=findpeaks(InvertedY,Fs);
findpeaks(InvertedY,Fs);
title('minima');
One problem that I have is that I can't define the x axis for the findpeaks operation, meaning that it just starts from zero, I'd rather have it begin from the original point of time in my document, Another problem is that I don't know how to get the y values from the minima points as when you invert the graph, the y values are useles so I only have the x values but I don't know how to make matlab automatically find the x values from the original table!

采纳的回答

Star Strider
Star Strider 2020-9-26
This will identify and plot the positive slopes:
T1 = readtable('73(4)_interval.xlsx');
Slope = gradient(T1{:,1}) ./ gradient(T1{:,2});
Pos = T1{:,1};
Pos(Slope<=0) = NaN;
figure
plot(T1{:,2}, T1{:,1})
hold on
plot(T1{:,2}, Pos, 'LineWidth',1.5)
hold off
grid
xlabel('Elapsed Time (s)')
ylabel('Potential (v)')
legend('Original Signal','Positive Slopes','Location','NW')
producing this figure:
The positive slope regions are those that are not NaN in the ’Pos’ Vector. The second plot in the figure (orange lines) demonstrates how to identify them and access them.
  2 个评论
Mahyar Farahani
Mahyar Farahani 2020-9-26
Thank a lot for the help! I've been banging my head against the wall trying to figure this out, It's both impressive and demoralizing to see how simple the solution was!
Star Strider
Star Strider 2020-9-27
As always, my pleasure!
It's both impressive and demoralizing to see how simple the solution was!’
I appreciate that you found it to be impressive, however I hope you did not actually find it to be demoralising. I have the advantage of taking another look at it, as well as having several years experience with MATLAB, so my approach was an alternative. If it had not worked, I would have suggested using the ischange function (introduced in R2017b).

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by