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.
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...]
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
% 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);
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.