second largest peak value
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I'm getting the amp of second largest peak as correct but the time is wrong ?
How to obtain the second highest value X,Y from this and plot as already Y is correct ,X seems to be in wrong region?
s=load ('30827.mat');
signal(1,1:length(s.ans))=s.ans;
load t.mat;
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(1,:))),t);
[highestPeak, indexOfHighestPeak] = max(PkAmp);
[a(1),b2]=max(abs(hilbert(signal(1,:))));
[a2(1),b6]=max(PkAmp(PkAmp<max(PkAmp))); % to get second largest peak value
% error is the time value calcluate and plotted wrong??
Highesttime(1,:) = t(b2);
Highest2time(1,:) = t(b6);
figure;
plot(t,(signal(1,:)),t,abs(hilbert(signal(1,:))),t(b2),a(1),'ro')
hold on
plot(PkTime, PkAmp, '^r', 'MarkerFaceColor','r')
xlim([0 0.0006]);ylim([-inf inf])
grid on
hold on,plot(t(b6),a2(1),'ko')
hold off
채택된 답변
Alex Mcaulley
2019년 6월 12일
To obtain the coordinates of the second peak you just need:
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(1,:))),t);
[~,idx] = sort(PkAmp,'descend');
PkAmp(idx(2)) %Amplitude of the second peak
PkTime(idx(2)) %Time of the second peak
댓글 수: 13
Ramesh Bala
2019년 6월 12일
Danke Schon Alex,
Lemme have a check
Ramesh Bala
2019년 6월 12일
Alright Alex ! I tried to use the method but it shows not compatible error ??
close all
s=load ('30827.mat');
signal(1,1:length(s.ans))=s.ans;
s= load ('30802.mat');
signal(2,1:length(s.ans))=s.ans;
load t.mat;
for k = 1:size(signal,1)
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(k,:))),t);
[a(k),b2]=max(abs(hilbert(signal(k,:))));
[a2(k),b6] = sort (PkAmp, 'descend' );
M(k) =PkAmp (b6(2)); % Amplitude of the second peak
Z(k) =PkTime (b6(2)); % Time of the second peak
figure;
plot(t,(signal(k,:)),t,abs(hilbert(signal(1,:))),t(b2),a(k),'ro')
hold on
plot(PkTime, PkAmp, '^r', 'MarkerFaceColor','r')
xlim([0 0.0006]);ylim([-inf inf])
grid on
hold on,plot(Z(k),M(k),'ko')
hold off
end
Ramesh Bala
2019년 6월 12일
편집: Ramesh Bala
2019년 6월 12일
Now it works well with some changes !!!But one question is how do i get the changing index values of b2 and b6 ,as it gives only the end values ( reason the X*Y matrix are not equal )
now it gives a single scalar value ,but I want all the index values b2 = [ xyx xyz] and b6 as such ??
close all
s = load ('30827.mat');
signal (1.1: length (s.ans)) = s.ans;
s = load ('30802.mat');
signal (2.1: length (s.ans)) = s.ans;
load t.mat;
for k = 1: size (signal, 1)
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(k,:))),t);
[a(k),b2]=max(abs(hilbert(signal(k,:))));
[a2, b6] = sort (PkAmp, 'descend' );
M(k)=PkAmp (b6(2)); % Amplitude of the second peak
Z(k)=PkTime (b6 (2)); % Time of the second peak
figure;
plot(t,(signal(k,:)),t,abs(hilbert(signal(k,:))),t(b2),a(k),'ro')
hold on
plot(PkTime, PkAmp, '^r', 'MarkerFaceColor','r')
xlim([0 0.0006]);ylim([-inf inf])
grid on;hold on
plot(Z(k),M(k),'ko')
hold off
end
I don't understand what do you want exactly, but to extract the peaks you want you don't need to use the max function:
for k = 1: size (signal, 1)
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(k,:))),t);
[~,idx] = sort (PkAmp, 'descend' );
b(k) = idx(1); % Index of the largest peak
a(k) = PkAmp (b(k)); % Amplitude of the largest peak
time(k) = PkTime (b(k)); % Time of the largest peak
b2(k) = idx(2); % Index of the second largest peak
a2(k) = PkAmp(b2(k)); % Amplitude of the second largest peak
time2(k) = PkTime (b2(k)); % Time of the second largest peak
%Some plots
end
Jan
2019년 6월 12일
Use maxk(Signal, 2) instead of sorting the complete vector.
Ramesh Bala
2019년 6월 13일
Thank you it works well.
I would like to know if there is a way to collect all the peak values in a matrix ?
for k = 1: size (signal, 1)
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(k,:))),t);
b2(k) = idx(2); % Index of the second largest peak
a2(k) = PkAmp(b2(k)); % Amplitude of the second largest peak
time2(k) = PkTime (b2(k)); % Time of the second largest peak
%this helps me to idenitfy largest peaks ,but how can I collect all the %peak values of a figure into a matrix??
end
Alex Mcaulley
2019년 6월 13일
In fact, you have all the peaks in PkAmp variable and the time they occur in Pktime.
Ramesh Bala
2019년 6월 13일
Yeah you're right .But I can't group as it says " 1-by-85 and the size of the right side is 1-by-87."
for the obtained values
Ramesh Bala
2019년 6월 13일
[PkAmp(k,:), PkTime(k,:)] = findpeaks(abs(hilbert(signal(k,:))),t);
Ramesh Bala
2019년 6월 13일
The above one doesn't work as the matrix is changing its size.so,how to group such changing matrix
Using cell array:
[PkAmp{k}, PkTime{k}] = findpeaks(abs(hilbert(signal(k,:))),t);
Ramesh Bala
2019년 8월 6일
Dear Alex
I have one more silly doubt in removing the index,I'm trying to find now the the largest time instead of Amp.So,I have used 'ascend' function which helps me to plot the the required time.
clc
clear all
close all
format long;
filenames={"30827"}
S(:,1) = [25 25 21.4 17.92 28.5 32.07 30 35 20 15];
S(:,2)= [10 15 8.5 12.07 8.5 12.07 5 5 5 5 ];
for i=1:numel(filenames)
s(i)=load (filenames{i});
signal(i,1:length(s(i).ans))=s(i).ans; % loading the signals from the scanning pts
end
load t.mat; %loading the time values
for k=1:1:length(S)
[a(k),b2]=max(abs(hilbert(signal(k,:)))); % first peak amp & index
%finding the peaks
set(0,'DefaultFigureWindowStyle','docked')
[PkAmp, PkTime] = findpeaks(abs(hilbert(signal(k,:))),t);
[~,idx] = sort (PkTime, 'ascend' );
b6(k) = idx(4); % Index of the fourth largest peak
a6(k) = PkAmp(b6(k)); % Amplitude of the fourth largest peak
time4(k)= PkTime (b6(k)); % Time of the fourth largest peak
figure;
plot(t,(signal(k,:)),t,abs(hilbert(signal(k,:))),t(b2),a(k),'ro')
hold on;grid on
plot(PkTime, PkAmp, '^r', 'MarkerFaceColor','r')
%plotting 4th largest
hold on,plot(time4(k), a6(k),'ko')
hold off
end
As per the script it plots the 4th largest PKTime peak .But how to remove other PkTime based on highest "a" highest PKAmp and then recontinue to plot the graph by taking highest(PKAMP) as PKTIME 1?
Ramesh Bala
2019년 8월 6일

추가 답변 (1개)
Steven Lord
2019년 6월 13일
1 개 추천
Use the islocalmax function with the 'MaxNumExtrema' option.
카테고리
도움말 센터 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
