How to find the maximum value of C that corresponds to a set of X,Y coordinates?
1 view (last 30 days)
Show older comments
Brianna Miranda
on 29 Jul 2022
Commented: Star Strider
on 29 Jul 2022
I have a spectrogram plot that contains X,Y and C. I want to find the maximum values of C from that spectrogram and also the XY coordinates that they correspond to. I have this so far but I am not sure how to get the X,Y coordinates that each value of max C corresponds to.
imagesc(X,Y,10*log10(C))
maxC = max(C);
0 Comments
Accepted Answer
Star Strider
on 29 Jul 2022
The spectrogram plot is actually a surf plot with the view set to display it looking from the top, so the ‘Z’ values will give you all the information you want.
One way of getting that information from the spectrogram is to use the medfreq funciton. See Track Chirps in Audio Signal for an example.
2 Comments
Star Strider
on 29 Jul 2022
With a spectrogram, the ‘maximum’ can be defined as the maximum value of the ‘Z’ matrix (the eqay solution), or the maximum frequency with respect to time (the solution that the link I posted could be useful to find).
The maximum value of the ‘Z’ matrix is simply:
[r,c] = find(Z == max(Z(:))
so for example —
[X,Y] = ndgrid(1:0.1:5);
Z = randn(size(X))
[r,c] = find(Z == max(Z(:)))
maxZ = Z(r,c)
figure
surf(X,Y,Z)
hold on
stem3(X(r,c),Y(r,c),Z(r,c), '^r', 'MarkerFaceColor','r')
hold off
grid on
.
More Answers (1)
Voss
on 29 Jul 2022
X = 1:3:31;
Y = 1:2:13;
C = rand(numel(Y),numel(X));
imagesc(X,Y,10*log10(C))
[maxC,idx] = max(C(:))
[yidx,xidx] = ind2sub(size(C),idx)
maxX = X(xidx)
maxY = Y(yidx)
line(maxX,maxY,'Marker','x','MarkerEdgeColor','r')
0 Comments
See Also
Categories
Find more on Time-Frequency Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!