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
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
2018년 7월 24일
Hi Anna, How did you get this kinda plot. I want to get a similar plot to this
채택된 답변
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
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!