x-coordinate of peaks in 1D plot
이전 댓글 표시
Hello,
I have the following 1D plot:
I want to find all the x-coordinate values of the peaks in a above plot. I have used the following lines of code and end up having only the y-coordinates(maginutude) values sorted in descending order:
out; %row vector containing the magnitude values(dependent variable)
omega %row vector containing the frequency axis of FFT (independent variable)
peaks=imregionalmax(out);
[label n]=bwlabel(peaks);
peak = imdilate(peaks,strel('disk',1));
G=regionprops(label,'PixelIdxList');
maxForThisBlob=zeros(1,n);
for blob = 1 : n
% Get pixel intensities of this particular blob.
thisBlob = out(G(blob).PixelIdxList);
% Find the max intensity out of those pixel intensities.
maxForThisBlob(blob) = max(thisBlob(:));
end
% Sort them in descending order.
sortedMaxes = sort(maxForThisBlob, 'descend');
%----plotting----%
N=size(omega,2);
figure;
plot(omega(1:N/2),out,'r') %plot one-sided spectrum
The above variable sortedMaxes contains the Magnitude (y-coordinate) values of the peaks(that is 0.02542,0.0191,......so on). How can I extract the corresponding x-coordinates at each of the peaks(that is 3.6,7.2,......so on) ?
please help
답변 (2개)
Walter Roberson
2012년 6월 21일
[sortedMaxes, maxidx] = sort(maxForThisBlob, 'descend');
maxx = omega(maxidx);
댓글 수: 3
zozo
2012년 6월 21일
Walter Roberson
2012년 6월 21일
Hmmmm....
Looking again I see that maxidx would be a blob number. I do not have any feel for how blobs correspond to peak positions in your graph.
Change your G=regionprops(label,'PixelIdxList'); to
G=regionprops(label,'PixelIdxList', 'Centroid');
Then
for blob = 1 : n
thiscentroid = G(maxidx(blob)).Centroid;
blobx(blob) = thiscentroid(1);
end
Then blobx will be a vector of x coordinates of the centroids (for lack of anything better to use). The x coordinates would be pixel coordinates.
Then you have the problem of converting pixel coordinates to graph x coordinates. Doing that automatically (without user input) is a challenge. Programs can help, such as http://www.mathworks.co.uk/matlabcentral/fileexchange/7173-grabit
or http://www.mathworks.com/matlabcentral/fileexchange/4316-reverseplot
Though, you could probably automatically detect the pixel coordinates corresponding to the beginning and ending of the x axis without so much difficulty. I guess you could use interp1() to interpolate those to omega values.
XLen = Xaxisend - Xaxisstart + 1; %might need to tweaked as right end of plot does not touch axis
blobomega = interp1( Xaxisstart : Xaxisend, linspace( omega(1), omega(end), XLen ), blobx );
Or more simply,
XLen = Xaxisend - Xaxisstart + 1; %might need to tweaked as right end of plot does not touch axis
blobomega = omega(1) + (blobx - Xstart) / XLen * (omega(end) - omega(1));
zozo
2012년 6월 22일
Honglei Chen
2012년 6월 21일
0 개 추천
You can use findpeaks
댓글 수: 10
zozo
2012년 6월 21일
Matt Kindig
2012년 6월 21일
Use findpeaks to get the frequencies corresponding to the peak amplitudes, and then identify which of these frequencies are harmonics (integer multiples of maxx). You should use a threshold to determine whether each of the peak frequencies is within a suitably small tolerance of the desired harmonic frequency.
zozo
2012년 6월 22일
zozo
2012년 6월 22일
Honglei Chen
2012년 6월 22일
The findpeaks() has an option to sort the peaks. You probably want to set a minimum peak height and then get the 3 maximum peaks.
Walter Roberson
2012년 6월 22일
findpeaks() applies to datasets, not to images of plots. imdilate() and so on apply to images, not to datasets.
Which is it that you have: the data for the plot, or the image of the plot?
zozo
2012년 6월 22일
zozo
2012년 6월 22일
Honglei Chen
2012년 6월 22일
It seems that you can just use 'SORTSTR' to 'descend' and then pick the first 3 peaks.
However, this only works if you are reasonably confident for your data set because as long as you have noise, there will be a lot of small peaks. Hence, if there are no big peaks, the small peaks will be chosen. To solve this issue, you will need some sort of adaptive minimum peak height. You will need to estimate the noise floor of your data and then use that to come up with a reasonable minimum height
zozo
2012년 6월 23일
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!