Issue with finding the peaks of a graph.
4 views (last 30 days)
Show older comments
I would like to plot peaks on the autocorrelation graph. however, the findpeaks function does not give me the peaks of the autocorrelation graph. Is there something wrong with my code?
I have a histogram that looks like this:
I use this histogram to plot the autocorrelation:
and when I use the findpeaks function to find and plot the peaks, I get this:
my code is:
MINval = min(CODCT);
MAXval = max(CODCT);
width = 1;
h=hist(CODCT,floor(MINval):width:ceil(MAXval)); %histogram
x = h;
Rxx=autom(x); %autocorrelation
figure()
grid;
[pks,locs] = findpeaks(Rxx);
plot(Rxx);
hold on
plot(Rxx(locs),pks,'k^','markerfacecolor',[1 0 0]), hold off
0 Comments
Accepted Answer
Star Strider
on 7 Jan 2018
I cannot figure out what you are doing, and specifically what ‘autom’ returns.
Try this instead:
plot(locs,pks,'k^','markerfacecolor',[1 0 0])
6 Comments
Star Strider
on 9 Jan 2018
As always, my pleasure.
There may be some peak-finding routines on the File Exchange. I have not used them, so have no experience with them.
More Answers (1)
Steven Lord
on 7 Jan 2018
If the issue to which the title of your question refers is the X ticks of the last plot, that's because you called plot with one data input.
Calling plot(q) plots points (1, q(1)), (2, q(2)), (3, q(3)), ....
Calling plot(q, w) plots points (q(1), w(1)), (q(2), w(2)), (q(3), w(3)), ....
If that's not the issue about which you're asking with which you'd like us to help you, please state that issue clearly.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!