필터 지우기
필터 지우기

Finding peaks and troughs of sinusoidal from a Matrix and elements bounded within

조회 수: 2 (최근 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

채택된 답변

jonas
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
Nkenna Amadi
Nkenna Amadi 2018년 7월 4일
thank you very much ! how do i find the elements within each of these 5 sinusoids?
jonas
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개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by