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

3 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

jonas
jonas am 3 Jul. 2018
Bearbeitet: jonas am 3 Jul. 2018
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 Kommentare
Nkenna Amadi
Nkenna Amadi am 4 Jul. 2018
thank you very much ! how do i find the elements within each of these 5 sinusoids?
jonas
jonas am 4 Jul. 2018
Bearbeitet: jonas am 4 Jul. 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by