<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/147350</link>
    <title>MATLAB Central Newsreader - local maxima lines:MATLAB CODE</title>
    <description>Feed for thread: local maxima lines:MATLAB CODE</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 04 May 2007 04:11:19 -0400</pubDate>
      <title>local maxima lines:MATLAB CODE</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/147350#370677</link>
      <author>carlosmvmendes@gmail.com</author>
      <description>Hello!&lt;br&gt;
&lt;br&gt;
Is there any Matlab function to obtain the local maxima lines?&lt;br&gt;
&lt;br&gt;
Wavemenu in the wavelet toolbox does it but i can=B4t find the actual&lt;br&gt;
Matlab command line function.&lt;br&gt;
&lt;br&gt;
If that fucntion doesn=B4t exist in Matlab function, is there any free&lt;br&gt;
available Matlab code to perform it?&lt;br&gt;
&lt;br&gt;
Thanks in advance.&lt;br&gt;
&lt;br&gt;
Carlos&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 04 May 2007 19:10:46 -0400</pubDate>
      <title>Re: local maxima lines:MATLAB CODE</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/147350#370830</link>
      <author>Paul Mennen</author>
      <description>&amp;gt; Is there any Matlab function to obtain the local&lt;br&gt;
&amp;gt; maxima lines?&lt;br&gt;
&amp;gt; Carlos&lt;br&gt;
&lt;br&gt;
I assume you just want to find the local maxima in a vector?&lt;br&gt;
If so, a fairly simple minded expression to return the indexes of all&lt;br&gt;
the local maxima of a vector "a" follows:&lt;br&gt;
&lt;br&gt;
find(a&amp;gt;=[a(2:end) inf] &amp; a&amp;gt;[inf a(1:end-1)])&lt;br&gt;
&lt;br&gt;
If the maxima is a sequence of several equal values, this will return&lt;br&gt;
the index of the first of those. If you wanted it to return the index&lt;br&gt;
of the last one, just swap the &amp;gt;= and the &amp;gt;. If you wanted to&lt;br&gt;
include endpoints of the sequence as possible local maxima, just&lt;br&gt;
change the two instances of "inf" to "-inf".&lt;br&gt;
&lt;br&gt;
If you think about how this works, I think you will find it&lt;br&gt;
easy to extend it to look for local minima as well.&lt;br&gt;
&lt;br&gt;
This may be good enough for most applications, although the reason I&lt;br&gt;
called it "simple minded" is that it can be fooled by a plateau. For&lt;br&gt;
instance a sequence such as [1 2 3 3 3 4 4] has no local maximum, but&lt;br&gt;
one will be identified by my simple minded approach.&lt;br&gt;
&lt;br&gt;
Suppose we take this 15 element example:&lt;br&gt;
&lt;br&gt;
a = [1 2 2 3 2 1 1 5 1 17 17 17 15 20 1 ];&lt;br&gt;
% 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - index of a&lt;br&gt;
&lt;br&gt;
A better algorithm that handles plateaus should return the following&lt;br&gt;
indices as local maxima: 4, 8, 10, 14. And for local minima is should&lt;br&gt;
return indicies: 6, 9, 13&lt;br&gt;
&lt;br&gt;
This is tricky, but I think you will find that the following code&lt;br&gt;
produces this result exactly:&lt;br&gt;
&lt;br&gt;
--------------------------------------------------------------&lt;br&gt;
p = 1:length(a);&lt;br&gt;
b = diff([inf a])~=0;&lt;br&gt;
aa = a(b); pp = p(b);&lt;br&gt;
maxima = pp(find(aa&amp;gt;[aa(2:end) inf] &amp; aa&amp;gt;[inf aa(1:end-1)]))&lt;br&gt;
minima = pp(find(aa&amp;lt;[aa(2:end) -inf] &amp; aa&amp;lt;[-inf aa(1:end-1)]))&lt;br&gt;
---------------------------------------------------------------&lt;br&gt;
&lt;br&gt;
~Paul&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 11 May 2008 15:32:02 -0400</pubDate>
      <title>Re: local maxima lines:MATLAB CODE</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/147350#431449</link>
      <author>Pavle Boskoski</author>
      <description>carlosmvmendes@gmail.com wrote in message&lt;br&gt;
&amp;lt;1178277079.853382.320360@n59g2000hsh.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is there any Matlab function to obtain the local maxima lines?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Wavemenu in the wavelet toolbox does it but i can=B4t find&lt;br&gt;
the actual&lt;br&gt;
&amp;gt; Matlab command line function.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If that fucntion doesn=B4t exist in Matlab function, is&lt;br&gt;
there any free&lt;br&gt;
&amp;gt; available Matlab code to perform it?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks in advance.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Carlos&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Here is some script that recreates the plot that you can see&lt;br&gt;
from the wave menu:&lt;br&gt;
&lt;br&gt;
% First generate the wavelet coefficients&lt;br&gt;
% sig is your signal normal use of CWT command&lt;br&gt;
r=cwt(sig,'haar',15000);&lt;br&gt;
&lt;br&gt;
%clear some stuff if you run this over and over&lt;br&gt;
clear coefs coefs_max coefs_fin;&lt;br&gt;
&lt;br&gt;
indBeg = size(r,1);&lt;br&gt;
scales = a_coefs;&lt;br&gt;
coefs  = r;&lt;br&gt;
%--------------------&lt;br&gt;
[tmp,I1] = sort(scales);&lt;br&gt;
[tmp,I2] = sort(I1);&lt;br&gt;
coefs = coefs(I2,:);&lt;br&gt;
coefs_max = localmax(coefs,indBeg); %localmax is a built-in&lt;br&gt;
in wavelet toolbox&lt;br&gt;
coefs_fin = coefs_max(I1,:);&lt;br&gt;
&lt;br&gt;
clear coefs coefs_max;&lt;br&gt;
&lt;br&gt;
% Prepare the plot&lt;br&gt;
[nbRow,nbCol] = size(coefs_fin);&lt;br&gt;
markersize = 2;&lt;br&gt;
marker     = 'o';&lt;br&gt;
linestyle  = 'none';&lt;br&gt;
color      = wtbutils('colors','cw1d','spy');&lt;br&gt;
x = [1:nbCol];&lt;br&gt;
&lt;br&gt;
[iRow, iCol]= find(coefs_fin);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
%Plot the maxima&lt;br&gt;
plot(x(iCol),a_coefs(iRow), ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;'marker',marker, ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;'markersize',markersize, ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;'linestyle',linestyle,   ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;'color','r'); &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I hope this was the thing that you were looking for.&lt;br&gt;
&lt;br&gt;
Pavle&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 11 May 2008 15:39:03 -0400</pubDate>
      <title>Re: local maxima lines:MATLAB CODE</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/147350#431450</link>
      <author>Pavle Boskoski</author>
      <description>There was a small error in my previous script:&lt;br&gt;
&lt;br&gt;
r=cwt(sig,'haar',15000);&lt;br&gt;
&lt;br&gt;
should be:&lt;br&gt;
&lt;br&gt;
r=cwt(sig,a_coefs,'haar');&lt;br&gt;
&lt;br&gt;
where a_coefs are the scales on which you would like to&lt;br&gt;
perform the CWT&lt;br&gt;
&lt;br&gt;
Pavle&lt;br&gt;
&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
