Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: maximum/minimum detektion in signal

Subject: maximum/minimum detektion in signal

From: Lothar Schmidt

Date: 7 Jun, 2008 15:58:00

Message: 1 of 5

i try to find maxima and minima in my data doing this:

% index to possible maxima and minima
index=2:numel(data)-1;
% maximum ist greater than its neighbours
max_index=1+find(data(index)>data(index-1) & data(index)>data(index+1))
% flip signal
data=-data;
% minima are "inverse maxima"
min_index=1+find(data(index)>data(index-1) & data(index)>data(index+1))
% flip signal again
data=-data;

this works fine (i thought so for years). I suppose that max_index and
min_index grow alternating (we have a max, then a min, then again a max
and so on).

suposing to get eg:
max_index: [4 50 103 124 156...]
min_index: [27 84 112 142 162...]

With some new data it happens that i find consecutive maxima with no
minimum between them. Any idea how this can happen? I already tried with
some kind of "tolerance" eg data(index)>data(index-1)+tol
but this did not help...
signal is sampled in 24-bit, saved as ascii and loaded from that file.

getting eg:
max_index: [4 50 103 124 156...]
min_index: [27 84 142 162...]

any hint how this can happen? Some kind of accuracy effect?
you can also help me, giving me a trick how to eliminate consecutive maxima.

tia
Lothar

Subject: maximum/minimum detektion in signal

From: Lothar Schmidt

Date: 7 Jun, 2008 16:29:09

Message: 2 of 5

Lothar Schmidt schrieb:
> i try to find maxima and minima in my data doing this:
>
> % index to possible maxima and minima
> index=2:numel(data)-1;
> % maximum ist greater than its neighbours
> max_index=1+find(data(index)>data(index-1) & data(index)>data(index+1))
> % flip signal
> data=-data;
> % minima are "inverse maxima"
> min_index=1+find(data(index)>data(index-1) & data(index)>data(index+1))
> % flip signal again
> data=-data;
>
> this works fine (i thought so for years). I suppose that max_index and
> min_index grow alternating (we have a max, then a min, then again a max
> and so on).
>
> suposing to get eg:
> max_index: [4 50 103 124 156...]
> min_index: [27 84 112 142 162...]
>
> With some new data it happens that i find consecutive maxima with no
> minimum between them. Any idea how this can happen? I already tried with
> some kind of "tolerance" eg data(index)>data(index-1)+tol
> but this did not help...
> signal is sampled in 24-bit, saved as ascii and loaded from that file.
>
> getting eg:
> max_index: [4 50 103 124 156...]
> min_index: [27 84 142 162...]
>
> any hint how this can happen? Some kind of accuracy effect?
> you can also help me, giving me a trick how to eliminate consecutive
> maxima.
>
> tia
> Lothar

just found how this can happen:

eg:
0 1 0 0 1 0 means that a max ist detected at index 2 an at index 5. No
minimum ist detected between the maxima. So far so bad...

How can i eliminate the index 124 in the example?
  max_index: [4 50 103 124 156...]
  min_index: [27 84 142 162...]

Subject: maximum/minimum detektion in signal

From: Lothar Schmidt

Date: 7 Jun, 2008 17:23:29

Message: 3 of 5

Lothar Schmidt schrieb:
> Lothar Schmidt schrieb:
>> i try to find maxima and minima in my data doing this:
>>
>> % index to possible maxima and minima
>> index=2:numel(data)-1;
>> % maximum ist greater than its neighbours
>> max_index=1+find(data(index)>data(index-1) & data(index)>data(index+1))
>> % flip signal
>> data=-data;
>> % minima are "inverse maxima"
>> min_index=1+find(data(index)>data(index-1) & data(index)>data(index+1))
>> % flip signal again
>> data=-data;
>>
>> this works fine (i thought so for years). I suppose that max_index and
>> min_index grow alternating (we have a max, then a min, then again a
>> max and so on).
>>
>> suposing to get eg:
>> max_index: [4 50 103 124 156...]
>> min_index: [27 84 112 142 162...]
>>
>> With some new data it happens that i find consecutive maxima with no
>> minimum between them. Any idea how this can happen? I already tried
>> with some kind of "tolerance" eg data(index)>data(index-1)+tol
>> but this did not help...
>> signal is sampled in 24-bit, saved as ascii and loaded from that file.
>>
>> getting eg:
>> max_index: [4 50 103 124 156...]
>> min_index: [27 84 142 162...]
>>
>> any hint how this can happen? Some kind of accuracy effect?
>> you can also help me, giving me a trick how to eliminate consecutive
>> maxima.
>>
>> tia
>> Lothar
>
> just found how this can happen:
>
> eg:
> 0 1 0 0 1 0 means that a max ist detected at index 2 an at index 5. No
> minimum ist detected between the maxima. So far so bad...
>
> How can i eliminate the index 124 in the example?
> max_index: [4 50 103 124 156...]
> min_index: [27 84 142 162...]

fixed but not yet vectorized...:
first i've made shure that the first and the last "event" is a minimum.
then:

     for i=1:numel(max_index)
         while i<numel(max_index) && max_index(i)<min_index(i)
             max_index(i)=[];
         end
         while i<numel(min_index) && min_in dex(i+1)<max_index(i)
             min_index(i+1)=[];
         end
     end

any idea how to vectorize?

Subject: maximum/minimum detektion in signal

From: us

Date: 7 Jun, 2008 18:32:02

Message: 4 of 5

Lothar Schmidt:
<SNIP min-max-only, please

one of the solutions

% the data
     a=[4,50,103,124,156];
     b=[27 84 142 162];
% the engine
     [as,ix]=sort([a,b]);
     ix=[true,diff(ix)~=1];
     as=as(ix);
     an=as(1:2:end);
     bn=as(2:2:end);
% the result
     disp(an);
     disp(bn);

us

Subject: maximum/minimum detektion in signal

From: Lothar Schmidt

Date: 8 Jun, 2008 11:31:14

Message: 5 of 5

us schrieb:
> Lothar Schmidt:
> <SNIP min-max-only, please
>
> one of the solutions
>
> % the data
> a=[4,50,103,124,156];
> b=[27 84 142 162];
> % the engine
> [as,ix]=sort([a,b]);
> ix=[true,diff(ix)~=1];
> as=as(ix);
> an=as(1:2:end);
> bn=as(2:2:end);
> % the result
> disp(an);
> disp(bn);
>
> us

your my hero! I tried something similar but got stuck in index
confusion... thanks a lot

Lo

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
logical indexing us 7 Jun, 2008 14:35:06
sort us 7 Jun, 2008 14:35:06
diff us 7 Jun, 2008 14:35:06
code us 7 Jun, 2008 14:35:05
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics