> Well, unless one looks it's unlikely will find anything, indeed. :)
>
> Why not post the area of code in that region w/ the specific message?
> More eyes may well spot something.
True enough! The code around line 85 in findpeaks is as follows (line 85 is the line on which the error function is called):
% validate value of Pd and set default values for Pd and Np
[Pd,Np] = setvalues(Pd,Np,L);
if(Pd >=Indx(L))
pdmsgid = generatemsgid('largeMinPeakDistance');
error(pdmsgid,strcat('Invalid MinPeakDistance. Set MinPeakDistance in the range (',num2str(0), ',', num2str(Indx(L)), ').'));
else
% Call a nested function that finds the peaks
end
Pd is the peak distance; if not specified by the user (as in my case) it is set to 1 by setvalues. Indx is a list of the indices of all the input data values greater than MinPeakHeight. L is the length of this vector.
For the given data set, Pd should be 1 (the default) and Indx(L) should also be 1 (since the first element is the only one that exceeds MinPeakHeight, Indx should be [1] and L, being effectively the length of Indx, will also be 1). Thus Pd >= Indx(L) will be true, triggering the error. The mechanics of what's causing the error are simple enough, but I'm curious about the logic behind them.
> I'd suggest since findpeaks is a toolbox function to submit the sample
> dataset to official support as a bug report. Having a repeatable
> dataset should enable TMW to uncover the problem. (From your
> description of behavior w/ changing threshold, etc., it still sounds to
> me like an end-effect that may be related to the actual values as well.
> The mixture of positive and negative values is another area I wonder
> if there's a logic error concerning in the implementation. What happens
> if you take the same dataset but add abs(min(x))+C) where C is a
> constant >=0? IOW, same shape but all positive values.)
Adding an offset to all values removes the error.
Another dataset that triggers the error is:
a = [100 1 1 1];
p = findpeaks(a,'minpeakheight',2*std(a));
Interestingly, the command sets
b = [100 1 1 1 100];
p = findpeaks(b,'minpeakheight',2*std(a)); % Using same MinPH as above
and
c= [100 1 1 1];
p = findpeaks(c);
don't trigger the error (the result for each is that no peaks are found). This appears to indicate that the error occurs only with a single peak above MinPeakHeight at the start of the input dataset. Based on datasets b and c above, consistent behaviour in the error case would be for findpeaks to simply report that no peaks were found.
I think I'll take your suggestion and file this as a bug report, but if you (or anyone else) have any additional thoughts on this I'd still welcome them.
W Frane