Issue with finding the peaks of a graph.

4 views (last 30 days)
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

Accepted Answer

Star Strider
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
Amy Wong
Amy Wong on 9 Jan 2018
I understand. Thank you for your detailed explaination!
Do you know any other method to find the values and locations of the peaks instead of using the findpeaks function?
Star Strider
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.

Sign in to comment.

More Answers (1)

Steven Lord
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.
  1 Comment
Amy Wong
Amy Wong on 7 Jan 2018
I have edited my question.
My issue is i do not understand why the peaks does not match my graph

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!