How to find first index before main peak in a signal ?

6 次查看(过去 30 天)
Hi all,
I have a signal ( see figure an attached).
I want to identify loactions and values of indices circled bold black (first through before main through indicated by blue star)
I have values and locations of all the remaining indices (attached a b c and d).
I am able to identify indices circled red using the code below. I would assume I can modify it to get the indices in bold black but I fail to do this. Can you help please?
load 'signal'
load 'a' % load all through value
load 'b' % load all through location
load 'c' % load main through value
load 'd' % load main through location
counter = 0;
for i = 1:length(main_trough_location)
%finds end of movement cycle
index = all_trough_location > main_trough_location(i);
if sum(index)>0
counter = counter + 1;
end_location(counter) = all_trough_location(find(index,1));
end_value(counter) = all_trough_value(find(index, 1));
end
end
plot(thigh_orient_y,'k')
hold on
plot(all_trough_location,all_trough_value,'ko')
plot(main_trough_location,main_trough_value,'b*')
plot(end_location,end_value,'r*')
h = legend('signal',' all troughs','main troughs','end');

采纳的回答

Simon Chan
Simon Chan 2022-1-27
Suppose it is the minimum point before rising, you may try to find the first minumum point counting backwards from each peak.
load('signal.mat');
peak_location = find(islocalmax(thigh_orient_y,'MinProminence',40));
backward = arrayfun(@(x) diff(thigh_orient_y(x:-1:1)),peak_location,'UniformOutput',false);
num_back = cellfun(@(x) find(x>0,1,'first'),backward);
min_location = peak_location-num_back+1;
plot(thigh_orient_y);
hold on;
grid on;
plot(min_location,thigh_orient_y(min_location),'g*')
  4 个评论
Tomaszzz
Tomaszzz 2022-1-28
Many thanks and sorry to bother again
I have a signal like this.
I get the error:
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Error in findpeaks_XsensDot (line 74)
num_back = cellfun(@(x) find(x>0,1,'first'),backward);
I suppose this is because there is no minimum just before the first main peak. Not sure how to modyfy the code to make this work. Ignoring the first minimum if not exists would work for me as well.
Can you help please?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Signal Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by