[scilab-Users] lsqrsolve

Gary Nelson gnelson at quantasonics.com
Wed May 19 00:31:44 CEST 2010


A non-text attachment was scrubbed...
Name: env1.wav
Type: audio/wav
Size: 562 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20100518/b94e6928/attachment.bin>
-------------- next part --------------

On May 18, 2010, at 1:44 PM, ray joseph wrote:

> Gary,
> 
> Please let me know if this describes your experiment.
> 
> You have N sets of data.  
I did not communicate clearly. See attached wav file. I have many sets of data that look similar to this. 
I have processed this data using first central difference to find maxima and second central difference to find inflection points where
the gaussian formulation I am using defines sigma.

Some data sets have more maxima than this, but here we could find two maxima to the left, fit gaussians and subtract them out, then apply the algorithm again on the remaining maxima.

I have done this manually, and can make it work. But that is not feasible except to test the idea. I find that (Ai, mi, Si) can be expressed to fractions of a sample time and squared error is sensitive to these parameters to that precision.

I imagine a process that finds (as in this case) two larger maxima, fit a guassian to each and subtract. That will reveal a couple more, so recursively apply maxima finder, measure sigmas, fit gaussians again.


> You want to fit each one with its own Gaussian
> curve.  You are not trying to determine the statistical distribution of the
> magnitude of the numbers in each of the sets, but are addressing the
> magnitudes of the sequence of numbers as if they were the range of (produced
> from) a function on a sequentially ordered set of integers.  Such as:
exactly the form I use. S is measured at the inflection points

> yi = A*exp(-((xi-m)^2)/(2*s^2))

My notion is that 
estimate(Ai,mi,Si) = sum(yi)     //sum_over_i

In this example, we can add two gaussians to fit the largest two maxima and tinker the parameters to minimize the squared error.

> 
> To do a least squared fit of (xi,yi) wrt (A,m,s):
> 
> Take the ln of both sides:
> ln(yi) = ln(A) + -((xi-m)^2)/(2*s^2)
> 
> by letting -2*s^2 = 1/q, the above can be written:
> ln(yi) = ln(A) + q*((xi-m)^2)
> ln(yi) = ln(A) + q*(xi^2 - xi*m + m^2)
> ln(yi) = ln(A) + q*xi^2 - q*xi*m + q*m^2)
> 
> If you do this for each of the j sets, each will have an independently fit
> set (Aj,mj,sj).

Thanks for taking the time to help.
> 
> 
> Ray
> 
> 
> 
> ----- Original Message ----- 
> From: "Gary Nelson" <gnelson at quantasonics.com>
> To: <users at lists.scilab.org>
> Sent: Monday, May 17, 2010 5:57 PM
> Subject: Re: [scilab-Users] lsqrsolve
> 
> 
> 
> Suppose I have a dataset that has N maxima and I want to fit a gaussian to
> each one, and minimize the least square error between the sum of N gaussians
> and the dataset.
> I have tried this manually by tinkering the parameters and it clearly can be
> done to good effect.
> The datasets have 250 to 500 samples -- a smooth sequence of  positive
> numbers with maxima that are plausibly gaussian shaped
> Initial guess could be a set of amplitudes whose time locations are taken
> from central difference positive to negative transits. I found that manual
> tweaking by moving centers a fraction of a sample left or right would change
> lsqerror, then tweaking amplitudes, then tweaking sigmas -- a couple
> interations and the visible fit would be very good.
> 
> Now, how do I do this more rigorously?
> 
> Thanks
> 
> On May 4, 2010, at 7:57 PM, ray joseph wrote:
> 
>> Gary,
>> 
>> I am sorry that I am bypassing your original request; but if you calculate
>> the mean and standard deviation of your data set, you will get the two
>> parameters.  Using the solver will be a fun exercise.
>> 
>> Ray
>> 
>> ----- Original Message ----- 
>> From: "Gary Nelson" <gnelson at quantasonics.com>
>> To: <users at lists.scilab.org>
>> Sent: Tuesday, May 04, 2010 2:12 PM
>> Subject: Re: [scilab-Users] lsqrsolve
>> 
>> 
>> I would like to fit a gaussian to some data samples using least squares.
>> The gaussian has two parameters -- amplitude and width (sigma).
>> 
>> I would like to use 6 to 12 samples that span a maximum and provide a
> first
>> guess of the amplitude and width.
>> 
>> After reading the manual on lsqsolve, it seems like it will do the job,
> but
>> I would appreciate some guidance to make it work.
>> 
>> Thanks
>> 
>> Gary Nelson
>> 
>> 
>> On Apr 7, 2010, at 2:12 AM, Samuel Gougeon wrote:
>> 
>>> ----- Message d'origine -----
>>> De : Maso Ricci
>>> Date : 31/03/2010 12:18:
>>>> Hi,
>>>> 
>>>> I am using the lsqrsolve function to fit some data.
>>>> I wonder whether lsqrsolve accepts contrains in order to force the
>> solution to be positive.
>>>> 
>>>> thanks in advance for any comments and suggestions
>>> Did you check the leastsq() function based on the optim() one ? Its 'b',
>> binf, bsup
>>> sequence of 3 input arguments allow to specify some boundaries.
>>> So, for instance, if the solution you are searching for is a scalar that
>> must be positive,
>>> just set 'b',0,%inf. see help leastsq()
>>> 
>>> HTH
>>> Samuel
>>> 
>>> 
>> 
>> Gary Nelson
>> gnelson at quantasonics.com
>> 
>> 
>> 
>> 
>> 
> 
> Gary Nelson
> gnelson at quantasonics.com
> 
> 
> 
> 
> 

Gary Nelson
gnelson at quantasonics.com





More information about the users mailing list