How can I find a minimum only before a peak has been detected?

6 次查看(过去 30 天)
I have the following graph in which I used function findpeaks and MinPeakHeight to find the peaks that I'm interested in.
[pks,locs]=findpeaks(filter_sgo,'MinPeakHeight',limiar,'MinPeakDistance',minpkdist);
Now I want to find the local minimums but only before the peaks that I have already detected (red points of the picture). I know I have to invert the signal and use findpeaks again, but I can't figure out how to only detect before a peak.
Thanks a lot.
  7 个评论
jonas
jonas 2018-5-23
If you post the data (or part of the data) and your code, then it would be easier to help you. It would also be easier to post a good answer. Anyway, I'm guessing this line is incorrect
if loc_min(1,:)< locs(1,j) && loc_min(1,:)>locs(1,j)-2000
you are never using i in your loop, perhaps : should be replaced by i?
Folakemi Omotoye
Folakemi Omotoye 2018-7-24
Hi Anna, How did you get this kinda plot. I want to get a similar plot to this

请先登录,再进行评论。

采纳的回答

jonas
jonas 2018-5-23
编辑:jonas 2018-5-23
What you are looking for seems to be the beginning of the peak, which is not necessarily a valley. A simple method to approximate those values would be to count backwards from each peak, and find the location when the signal intercepts a predefined threshold. Here's a simple example. You may recognize the peaks from the documentation on findpeaks.
x = linspace(0,1,1000);
Pos = [1 2 3 5 7 8]/10;
Hgt = [3 4 4 2 2 3];
Wdt = [2 6 3 3 4 6]/100;
for n = 1:length(Pos)
Gauss(n,:) = Hgt(n)*exp(-((x - Pos(n))/Wdt(n)).^2);
end
PeakSig = sum(Gauss);
%%example starts here
[pks,locs] = findpeaks(PeakSig);
locs=[1 locs];
thres=0.5; %set threshold
win=diff(locs)
mins=nan(size(win))
for i=1:numel(win);
ind=find(PeakSig(locs(i):locs(i+1))<thres);
if ~isempty(ind)
mins(i)=max(ind)+locs(i);
end
end
mins(isnan(mins))=[];
figure;hold on
findpeaks(PeakSig)
plot(mins,PeakSig(mins),'rx')
  3 个评论
Image Analyst
Image Analyst 2018-5-24
Or (what I think might be better) is to descend from the peak until you're less than the threshold, and keep going until the values start to turn around and increase again.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by