help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Gaussian fit of a peak


From: Marc Normandin
Subject: Re: Gaussian fit of a peak
Date: Tue, 23 Sep 2008 19:33:48 -0400
User-agent: Thunderbird 2.0.0.16 (X11/20080724)

Julius Smith wrote:
> On Wed, Sep 17, 2008 at 8:20 AM, Andrea Cimatoribus <address@hidden> wrote:
>> Hi everybody,
>> I am an absolute novice of octave, even though I have some experience
>> with matlab.
>> Just to get the feeling of octave, I am presently translating a simple
>> (but very useful to me) script, that basically sums data with a peak
>> structure. In order to do this properly, I need to centre each new
>> spectrum on the zero, that is the peak maximum. My strategy, in
>> matlab, was to make a preliminary gaussian fit, whose result was to be
>> confirmed through a graphical input, to get the "zero" of the
>> spectrum. As of now, I am trying to understand how can I make a
>> gaussian fit of the data in octave. Data is simply organised as a
>> matrix [x,y]. Is there a built function? Sorry but I can't find
>> anything with online help.
>> Andrea
>>
>>
> For the single-Gaussian case, you can take a log and fit a parabola:
>
> x = -1:0.1:1;
> sigma = 0.01;
> y = exp(-x.*x) + sigma*randn(size(x));
> [p,s] = polyfit(x,log(y),2);
> yh = exp(polyval(p,x));
> norm(y-yh)    % ans =  1.9230e-16 when sigma=0
> plot([y',yh']);
>
> - Julius
>

Just a few cautionary notes on this approach:

1. If your data contain negative values, taking the logarithm will have
you fitting imaginary data.  The fit should still work, but the parabola
will be complex-valued.

2. Similarly, the transformed data will contain -Inf points if any data
are identically zero.  Not sure how polyfit would react to this, but I
wouldn't be surprised if the answer were "not well".

3. If you're fitting transformed data (e.g., logarithm of original data,
as suggested), you ought to transform the residual weights accordingly.
 Otherwise you'll be overemphasizing certain measurements (in this case,
the tails of the distribution may unduly influence your fit).

Regards,
Marc

-- 
------------------------------------------------------------------
Marc D. Normandin              http://web.ics.purdue.edu/~mdnorman
Graduate Research Assistant                     address@hidden
Indiana University School of Medicine           317-278-9841 (tel)
Department of Radiology, Division of Research   317-274-1067 (fax)
------------------------------------------------------------------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]