[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Gaussian fit of a peak
From: |
Julius Smith |
Subject: |
Re: Gaussian fit of a peak |
Date: |
Tue, 23 Sep 2008 17:45:07 -0600 |
Yes, it is good to stay away from zero. I normally work only with the
center-most samples of each peak - that is, I fit only to the middle
third or so, where the peak really "looks Gaussian" and is clearly
positive. - jos
On Tue, Sep 23, 2008 at 5:33 PM, Marc Normandin <address@hidden> wrote:
> 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)
> ------------------------------------------------------------------
>
>
--
"Anybody who knows all about nothing knows everything" -- Leonard Susskind
- Re: Gaussian fit of a peak, (continued)
- Re: Gaussian fit of a peak, Thomas Weber, 2008/09/23
- Re: Gaussian fit of a peak, Andrea Cimatoribus, 2008/09/23
- Message not available
- Message not available
- Fwd: Gaussian fit of a peak, Andrea Cimatoribus, 2008/09/24
- Re: Gaussian fit of a peak, Carlo de Falco, 2008/09/24
- Re: Gaussian fit of a peak, Andrea Cimatoribus, 2008/09/24
- Re: Fwd: Gaussian fit of a peak, Francesco Potorti`, 2008/09/24
- Re: Fwd: Gaussian fit of a peak, LUK ShunTim, 2008/09/24
Re: Gaussian fit of a peak, Rob Mahurin, 2008/09/23
Re: Gaussian fit of a peak, Julius Smith, 2008/09/23