Finding peaks and troughs of sinusoidal from a Matrix and elements bounded within
3 次查看(过去 30 天)
显示 更早的评论
Hello i have a matrix that consists of zeros and ones. It has 5 sinusodial shapes linked together as seen in the image attached. The yellow represents where the value of the matrix is one and the blue for zero. How do i find the peaks and troughs of each of this sinusodial shapes and the indices/elements(rows and columuns) bounded by each of these sinusodial shapes. Basically i should have something that gives the peak and trough for sinusodial one and then the elements within it
0 个评论
采纳的回答
jonas
2018-7-3
编辑:jonas
2018-7-3
Since you did not attach the data, I had to start from your attached image. Therefore my x- and y-values are not scaled correctly. Basically you get the coordinates with find() and then findpeaks() to locate peaks and troughs. See attachment for results.
%%Fix binary image
RGB=imread('pic.png');
GRAY = rgb2gray(RGB);
threshold = graythresh(GRAY);
BW = im2bw(GRAY, threshold);
%Crop edges
BW=BW(5:end-10,60:end-30);
imshow(BW)
%%Find coordinates of ones
[y,x]=find(BW==1)
%%Find peaks and troughs
[~,locs1]=findpeaks(y.*-1,'minpeakprominence',20,...
'minpeakdistance',50)
[~,locs2]=findpeaks(y,'minpeakprominence',20,...
'minpeakdistance',50)
%%Plot data
figure;
plot(x,y,'-',...
x(locs1),y(locs1),'-x',...
x(locs2),y(locs2),'-x')
7 个评论
jonas
2018-7-4
编辑:jonas
2018-7-4
Simple enough. The peak indices are stored in locs2 (troughs) and locs1 (peaks). So, to find the indices between the first two troughs, you can type:
wave1=x(locs2(1):locs2(2))
then for the next
wave2=x(locs2(2):locs2(3))
and so on. If you want the corresponding y-values, just change x to y.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!