Skip to content

fitpeaks initial guesses can be outside of user restrictions #108

@mwalsh161

Description

@mwalsh161

HelperFunctions/PeakFitting/fitpeaks.m

The Width, Amplitude, and Location input parameters allow the user to override default settings. The way the initial guesses are generated does not take these limits into account at all. The limits are only imposed on the fit itself. This creates a rather obnoxious scenario where peaks that satisfy your AmplitudeSensitivity, for example, don't fall in your allowed Location bound and they are forced onto random peaks within Location bounds.

The solution could be:

  • Filter the initial guess set on all the restrictions above before fitting.
  • Issue warning at runtime if the initial guesses are outside the limits.
  • Make sure it is obvious in documentation that this might happen - on the bright side there is enough returned by the function to detect this:
plot(x,y); hold('on');
dx = max(x)-min(x);
[locs,~,ft,~,init] = fitpeaks(x,y,'AmplitudeSensitivity',2,'Location',min(x)+dx*[1/3, 2/3]);
    
plot(ft{end});
for i = 1:length(locs.amplitudes)
    plot([0 0]+init.locations(i),get(gca,'ylim'),'--','DisplayName',sprintf('Guess: peak %i',i));
end
 hold('off');

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or requestgood first issueGood for newcomersno hardwareCan be run locally without worrying about being connected to hardware

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions