Python - finding peaks in noisy data

278 views
Skip to first unread message

Dave Typinski

unread,
Dec 9, 2020, 10:46:10 PM12/9/20
to sara...@googlegroups.com
Hi all,

I have some noisy spectral data within which exist many peaks.

I would like to find the locations of the stronger peaks using Python.

What I have tried:

scipy.signal.find_peaks --> only reports peak locations to the nearest sample.
Would like the location to be more accurate than that.

scipy.signal.find_peaks_cwt --> the thing is still running after a couple hours
(or hung). There is a lot of data, so maybe it's just quite slow.

peakutils.interpolate --> looks like it can interpolate the locations of
Gaussian fitted peaks, but unfortunately it's a black box and doesn't actually
provide the Gaussian function parameters, only the peak locations (which is not
enough info to plot the Gaussian curves).

Does anyone have any suggestions for other peak-finding methods or utilities for
Python that will provide interpolated peak locations?

Thanks!
--
Dave

Michiel Klaassen

unread,
Dec 10, 2020, 1:50:48 PM12/10/20
to sara-list
Hi Dave,
There seems to be no answers to your question, and I myself think it is also difficult to answer.
Can you give an example graph with (paint) indication what you want.
regards,
Michiel

Op do 10 dec. 2020 om 04:46 schreef Dave Typinski <dav...@typnet.net>:
--
--
You received this message because you are subscribed to the Google
Groups "Society of Amateur Radio Astronomers" group.
To post to this group, send email to sara...@googlegroups.com
To unsubscribe from this group, send email to
sara-list-...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sara-list?hl=en
---
You received this message because you are subscribed to the Google Groups "Society of Amateur Radio Astronomers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sara-list+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sara-list/5FD19A00.6010100%40typnet.net.

Coto

unread,
Dec 10, 2020, 7:03:01 PM12/10/20
to Society of Amateur Radio Astronomers
Hi Dave,

Are you looking for global maximum or local maxima localization? For the global maximum, see my code (around line 23 of period_plot.py) here: https://github.com/0xCoto/simpleReader

It uses numpy, so it's scipy-independent.

Hope that helps,
Apostolos

Dave Typinski

unread,
Dec 10, 2020, 8:43:15 PM12/10/20
to sara...@googlegroups.com
Hi Michiel,

Here's a plot of the data showing one peak with some prominent side lobes.  The idea is to fit a Gaussian / Lorentzian / whatever curve to the main peak to determine its location along the horizontal axis with sub-sample precision (i.e., interpolation between two samples).

I expect the true peak is somewhere between bin numbers 897 and 898.


What I'm looking for is a Python package that does this sort of peak curve fitting.  No sense reinventing the wheel if it already exists.
--
Dave

Dave Typinski

unread,
Dec 10, 2020, 8:51:18 PM12/10/20
to sara...@googlegroups.com
Hi Apostolos,

Looks like yours puts a vertical line on the plot at the global max. That's a
good way to do it to the nearest sample, but I'm looking for interpolated
sub-sample precision.
--
Dave


On 12/10/20 19:03, Coto wrote:
> Hi Dave,
>
> Are you looking for global maximum or local maxima localization? For the global
> maximum, see my code (around line 23 of period_plot.py) here:
> https://github.com/0xCoto/simpleReader
>
> It uses numpy, so it's scipy-independent.
>
> Hope that helps,
> Apostolos
>
> On Thursday, December 10, 2020 at 8:50:48 PM UTC+2 vmin...@gmail.com wrote:
>
> Hi Dave,
> There seems to be no answers to your question, and I myself think it is also
> difficult to answer.
> Can you give an example graph with (paint) indication what you want.
> regards,
> Michiel
> parac.eu <http://parac.eu>
> <mailto:sara-list+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/9601a209-62c3-4be8-b71b-3ac10c03ad64n%40googlegroups.com
> <https://groups.google.com/d/msgid/sara-list/9601a209-62c3-4be8-b71b-3ac10c03ad64n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Paul Oxley

unread,
Dec 10, 2020, 9:15:22 PM12/10/20
to sara...@googlegroups.com
Dave

If you want to know where the peak occurs, you need more sample points.

Paul

Dave Typinski

unread,
Dec 10, 2020, 9:25:06 PM12/10/20
to sara...@googlegroups.com
Hi Paul,

In a perfect world, yes. We can, however, work with imperfect data and obtain a
reasonable sub-bin-width approximation of the peak's location using curve fitting.
--
Dave


On 12/10/20 21:15, Paul Oxley wrote:
> Dave
>
> If you want to know where the peak occurs, you need more sample points.
>
> Paul
>
> On Thursday, December 10, 2020, 08:43:17 PM EST, Dave Typinski
> <dav...@typnet.net> wrote:
>
>
> Hi Michiel,
>
> Here's a plot of the data showing one peak with some prominent side lobes. The
> idea is to fit a Gaussian / Lorentzian / whatever curve to the main peak to
> determine its location along the horizontal axis with sub-sample precision
> (i.e., interpolation between two samples).
>
> I expect the true peak is somewhere between bin numbers 897 and 898.
>
>
> What I'm looking for is a Python package that does this sort of peak curve
> fitting. No sense reinventing the wheel if it already exists.
> --
> Dave
>
>
> On 12/10/20 13:50, Michiel Klaassen wrote:
>> Hi Dave,
>> There seems to be no answers to your question, and I myself think it is also
>> difficult to answer.
>> Can you give an example graph with (paint) indication what you want.
>> regards,
>> Michiel
>> parac.eu <http://parac.eu>
>>
>> Op do 10 dec. 2020 om 04:46 schreef Dave Typinski <dav...@typnet.net
>> <mailto:dav...@typnet.net>>:
>> <mailto:sara...@googlegroups.com>
>> To unsubscribe from this group, send email to
>> sara-list-...@googlegroups.com
>> <mailto:sara-list-...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/group/sara-list?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Society of Amateur Radio Astronomers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sara-list+...@googlegroups.com
>> <mailto:sara-list%2Bunsu...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sara-list/5FD19A00.6010100%40typnet.net.
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Society of Amateur Radio Astronomers" group.
>> To post to this group, send email to sara...@googlegroups.com
>> <mailto:sara...@googlegroups.com>
>> To unsubscribe from this group, send email to
>> sara-list-...@googlegroups.com
>> <mailto:sara-list-...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/group/sara-list?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Society of Amateur Radio Astronomers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sara-list+...@googlegroups.com
>> <mailto:sara-list+...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sara-list/CAABBjRCh8F52k2XPgbx4rdwiq-%2BTh-dSk7TDk1xJQLPhoN2C8A%40mail.gmail.com
>> <https://groups.google.com/d/msgid/sara-list/CAABBjRCh8F52k2XPgbx4rdwiq-%2BTh-dSk7TDk1xJQLPhoN2C8A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to sara-list+...@googlegroups.com
> <mailto:sara-list+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/5FD2CEAF.6000104%40typnet.net
> <https://groups.google.com/d/msgid/sara-list/5FD2CEAF.6000104%40typnet.net?utm_medium=email&utm_source=footer>.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to sara-list+...@googlegroups.com
> <mailto:sara-list+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/1532929515.6859786.1607652917467%40mail.yahoo.com
> <https://groups.google.com/d/msgid/sara-list/1532929515.6859786.1607652917467%40mail.yahoo.com?utm_medium=email&utm_source=footer>.

Paul Oxley

unread,
Dec 10, 2020, 9:34:58 PM12/10/20
to sara...@googlegroups.com
Dave

Unfortunately, curve fitting will not help resolve points between bins. You need more points to develop a curve. The data has a peak with a large slope on both sides. Data outside the peak and two bins on either side is not material to the position of the peak.

A guess might be obtained by averaging the three points. 

Paul

Paul

>>    email to sara-list+unsub...@googlegroups.com

>>    <mailto:sara-list%2Bunsu...@googlegroups.com>.
>>    To view this discussion on the web visit
>>    https://groups.google.com/d/msgid/sara-list/5FD19A00.6010100%40typnet.net.
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Society of Amateur Radio Astronomers" group.
>> To post to this group, send email to sara...@googlegroups.com
>> <mailto:sara...@googlegroups.com>
>> To unsubscribe from this group, send email to
>> sara-list-...@googlegroups.com
>> <mailto:sara-list-...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/group/sara-list?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Society of Amateur Radio Astronomers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sara-list/CAABBjRCh8F52k2XPgbx4rdwiq-%2BTh-dSk7TDk1xJQLPhoN2C8A%40mail.gmail.com
>> <https://groups.google.com/d/msgid/sara-list/CAABBjRCh8F52k2XPgbx4rdwiq-%2BTh-dSk7TDk1xJQLPhoN2C8A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email

> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/5FD2CEAF.6000104%40typnet.net
> <https://groups.google.com/d/msgid/sara-list/5FD2CEAF.6000104%40typnet.net?utm_medium=email&utm_source=footer>.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email

--
--
You received this message because you are subscribed to the Google
Groups "Society of Amateur Radio Astronomers" group.
To post to this group, send email to sara...@googlegroups.com
To unsubscribe from this group, send email to
sara-list-...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sara-list?hl=en
---
You received this message because you are subscribed to the Google Groups "Society of Amateur Radio Astronomers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sara-list+unsub...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/sara-list/5FD2D87F.5%40typnet.net.

Dave Typinski

unread,
Dec 10, 2020, 11:10:13 PM12/10/20
to sara...@googlegroups.com
Hi Paul,

The data here represents the output of a Fourier transformed time series. Since
the data isn't infinitely long, there is FFT leakage from the peak bin into
adjacent bins. Window functions can in some cases reduce FFT leakage, but
leakage is impossible to remove completely. With that in mind, if bins adjacent
to the peak bin receive unsymmetrical amounts of leaked spectral power, then the
actual peak is not perfectly centered in one bin. Curve fitting isn't perfect,
but it will allow the calculation of a reasonable approximation of the true
location of the peak to a resolution less than the bin width.

I agree that in this dataset there is a dearth of bins adjacent to the bin
containing the local maximum. Nevertheless, a curve can be fitted to even this
small group of bins.
--
Dave


On 12/10/20 21:34, Paul Oxley wrote:
> Dave
>
> Unfortunately, curve fitting will not help resolve points between bins. You need
> more points to develop a curve. The data has a peak with a large slope on both
> sides. Data outside the peak and two bins on either side is not material to the
> position of the peak.
>
> A guess might be obtained by averaging the three points.
>
> Paul
>
> Paul
>
> On Thursday, December 10, 2020, 09:25:08 PM EST, Dave Typinski
> <dav...@typnet.net> wrote:
>
>
> Hi Paul,
>
> In a perfect world, yes. We can, however, work with imperfect data and obtain a
> reasonable sub-bin-width approximation of the peak's location using curve fitting.
> --
> Dave
>
>
> On 12/10/20 21:15, Paul Oxley wrote:
> > Dave
> >
> > If you want to know where the peak occurs, you need more sample points.
> >
> > Paul
> >
> > On Thursday, December 10, 2020, 08:43:17 PM EST, Dave Typinski
> > <dav...@typnet.net <mailto:dav...@typnet.net>> wrote:
> >
> >
> > Hi Michiel,
> >
> > Here's a plot of the data showing one peak with some prominent side lobes. The
> > idea is to fit a Gaussian / Lorentzian / whatever curve to the main peak to
> > determine its location along the horizontal axis with sub-sample precision
> > (i.e., interpolation between two samples).
> >
> > I expect the true peak is somewhere between bin numbers 897 and 898.
> >
> >
> > What I'm looking for is a Python package that does this sort of peak curve
> > fitting. No sense reinventing the wheel if it already exists.
> > --
> > Dave
> >
> >
> > On 12/10/20 13:50, Michiel Klaassen wrote:
> >> Hi Dave,
> >> There seems to be no answers to your question, and I myself think it is also
> >> difficult to answer.
> >> Can you give an example graph with (paint) indication what you want.
> >> regards,
> >> Michiel
> >> parac.eu <http://parac.eu>
> >>
> >> Op do 10 dec. 2020 om 04:46 schreef Dave Typinski <dav...@typnet.net
> <mailto:dav...@typnet.net>
> >> <mailto:dav...@typnet.net <mailto:dav...@typnet.net>>>:
> >> <mailto:sara...@googlegroups.com <mailto:sara...@googlegroups.com>>
> >> To unsubscribe from this group, send email to
> >> sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>
> >> <mailto:sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>>
> >> For more options, visit this group at
> >> http://groups.google.com/group/sara-list?hl=en
> >> ---
> >> You received this message because you are subscribed to the Google Groups
> >> "Society of Amateur Radio Astronomers" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to sara-list+...@googlegroups.com
> <mailto:unsub...@googlegroups.com>
> >> <mailto:sara-list%2Bunsu...@googlegroups.com
> <mailto:2Bunsu...@googlegroups.com>>.
> >> To view this discussion on the web visit
> >> https://groups.google.com/d/msgid/sara-list/5FD19A00.6010100%40typnet.net.
> >>
> >> --
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "Society of Amateur Radio Astronomers" group.
> >> To post to this group, send email to sara...@googlegroups.com
> <mailto:sara...@googlegroups.com>
> >> <mailto:sara...@googlegroups.com <mailto:sara...@googlegroups.com>>
> >> To unsubscribe from this group, send email to
> >> sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>
> >> <mailto:sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>>
> >> For more options, visit this group at
> >> http://groups.google.com/group/sara-list?hl=en
> >> ---
> >> You received this message because you are subscribed to the Google Groups
> >> "Society of Amateur Radio Astronomers" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to sara-list+...@googlegroups.com
> <mailto:unsub...@googlegroups.com>
> >> <mailto:sara-list+...@googlegroups.com
> <mailto:unsub...@googlegroups.com>>.
> >> To view this discussion on the web visit
> >>
> https://groups.google.com/d/msgid/sara-list/CAABBjRCh8F52k2XPgbx4rdwiq-%2BTh-dSk7TDk1xJQLPhoN2C8A%40mail.gmail.com
> >>
> <https://groups.google.com/d/msgid/sara-list/CAABBjRCh8F52k2XPgbx4rdwiq-%2BTh-dSk7TDk1xJQLPhoN2C8A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> >
> > --
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Society of Amateur Radio Astronomers" group.
> > To post to this group, send email to sara...@googlegroups.com
> <mailto:sara...@googlegroups.com>
> > To unsubscribe from this group, send email to
> > sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>
> > For more options, visit this group at
> > http://groups.google.com/group/sara-list?hl=en
> > ---
> > You received this message because you are subscribed to the Google Groups
> > "Society of Amateur Radio Astronomers" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email
> > to sara-list+...@googlegroups.com <mailto:unsub...@googlegroups.com>
> > <mailto:sara-list+...@googlegroups.com
> <mailto:unsub...@googlegroups.com>>.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/sara-list/5FD2CEAF.6000104%40typnet.net
> >
> <https://groups.google.com/d/msgid/sara-list/5FD2CEAF.6000104%40typnet.net?utm_medium=email&utm_source=footer>.
> >
> > --
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Society of Amateur Radio Astronomers" group.
> > To post to this group, send email to sara...@googlegroups.com
> <mailto:sara...@googlegroups.com>
> > To unsubscribe from this group, send email to
> > sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>
> > For more options, visit this group at
> > http://groups.google.com/group/sara-list?hl=en
> > ---
> > You received this message because you are subscribed to the Google Groups
> > "Society of Amateur Radio Astronomers" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email
> > to sara-list+...@googlegroups.com <mailto:unsub...@googlegroups.com>
> > <mailto:sara-list+...@googlegroups.com
> <mailto:unsub...@googlegroups.com>>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/sara-list/1532929515.6859786.1607652917467%40mail.yahoo.com
> >
> <https://groups.google.com/d/msgid/sara-list/1532929515.6859786.1607652917467%40mail.yahoo.com?utm_medium=email&utm_source=footer>.
>
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> <mailto:sara...@googlegroups.com>
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to sara-list+...@googlegroups.com. <mailto:unsub...@googlegroups.com.>
>
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/5FD2D87F.5%40typnet.net.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to sara-list+...@googlegroups.com
> <mailto:sara-list+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/1750963326.6867069.1607654087876%40mail.yahoo.com
> <https://groups.google.com/d/msgid/sara-list/1750963326.6867069.1607654087876%40mail.yahoo.com?utm_medium=email&utm_source=footer>.

Nathan Towne

unread,
Dec 11, 2020, 12:33:51 AM12/11/20
to sara...@googlegroups.com
Hi Dave,

The ideal solution is to understand how the five peaks result from the
same source, i.e., the response function that maps the source at an
unknown frequency to the spectrum.  Then fit the entire spectrum to the
model of the five peaks with the source frequency and signal intensity
(and a vertical background offset) to be determined by the fit.

What is it about the signal that is determining the width of the lines
and the number and intensity of the sidelobes?

As an alternative to detailed modeling, you can construct a
phenomenological model of the response making assumptions, e.g., about
the number and symmetry of the peaks, guessing at the width and spacing,
etc., and fit with that response.

More points can be had if the time series is longer, even if the signal
of interest is of shorter duration (a sort of interpolation).  But that
may not provide more information that would enable a more precise
estimate of the peak position.

Nathan

Alexandros Filothodoros

unread,
Dec 11, 2020, 5:34:08 AM12/11/20
to sara...@googlegroups.com
Hello,

It has some extra parameters that you can use. They are explained in the script.

Cheers everyone
Alex

--
--
You received this message because you are subscribed to the Google
Groups "Society of Amateur Radio Astronomers" group.
To post to this group, send email to sara...@googlegroups.com
To unsubscribe from this group, send email to
sara-list-...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sara-list?hl=en
---
You received this message because you are subscribed to the Google Groups "Society of Amateur Radio Astronomers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sara-list+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sara-list/62a6d07f-a0ef-5288-da5f-3200858af5aa%40ownmail.net.


--
''Υπερέβαλε εαυτόν και κατέκτησε τον κόσμο ''-Αρχιμήδης

Michiel Klaassen

unread,
Dec 11, 2020, 7:10:51 AM12/11/20
to sara-list
Hi Dave,
Well; that generated a lot of response.
If you google  "gaussian fit python" , you get a lot of solutions; I am often inspired by the solutions from " stackoverflow" 
Regards
Michiel

Op vr 11 dec. 2020 om 11:34 schreef Alexandros Filothodoros <alexfilo...@gmail.com>:

Jim Abshier

unread,
Dec 11, 2020, 4:08:34 PM12/11/20
to sara...@googlegroups.com
It looks like a reasonable approach would be to fit a quadratic
polynomial to the central peak point and the points on either side of
the peak. Then find the peak of the quadratic polynomial.  If a
quadratic of the form y = ax^2 + bx + c is fit to the 3 central points,
the peak of the quadratic would be x0 = -b/(2a). This would be the
fractional sample distance from the central peak sample. If the y values
are y1, y2 and y3, where y2 is the central sample, y1 is the one on the
left and y2 is the one on the right, the fractional sample distance from
the peak would be:

x0 = (y3 - y1) / ( 4*y2 - 2*y1 - 2*y3)

For example: if y1 = 1, y2 = 3 and y3 = 2, the peak position would be x0
= 0.1666... samples to the right of the central peak.

You don't need Python, or a computer. A hand calculator would suffice.

Keep in mind that since there is noise on the spectral samples, the peak
solution will not be exact.

Jim Abshier


On 12/10/20 8:43 PM, Dave Typinski wrote:
> Hi Michiel,
>
> Here's a plot of the data showing one peak with some prominent side
> lobes.  The idea is to fit a Gaussian / Lorentzian / whatever curve to
> the main peak to determine its location along the horizontal axis with
> sub-sample precision (i.e., interpolation between two samples).
>
> I expect the true peak is somewhere between bin numbers 897 and 898.
>
>
> What I'm looking for is a Python package that does this sort of peak
> curve fitting.  No sense reinventing the wheel if it already exists.
> --
> Dave
>
>
> On 12/10/20 13:50, Michiel Klaassen wrote:
>> Hi Dave,
>> There seems to be no answers to your question, and I myself think it
>> is also difficult to answer.
>> Can you give an example graph with (paint) indication what you want.
>> regards,
>> Michiel
>> parac.eu <http://parac.eu>
>>
>> Op do 10 dec. 2020 om 04:46 schreef Dave Typinski <dav...@typnet.net
>> <mailto:dav...@typnet.net>>:
>> <mailto:sara...@googlegroups.com>
>> To unsubscribe from this group, send email to
>> sara-list-...@googlegroups.com
>> <mailto:sara-list-...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/group/sara-list?hl=en
>> ---
>> You received this message because you are subscribed to the
>> Google Groups "Society of Amateur Radio Astronomers" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to sara-list+...@googlegroups.com
>> <mailto:sara-list%2Bunsu...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sara-list/5FD19A00.6010100%40typnet.net.
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Society of Amateur Radio Astronomers" group.
>> To post to this group, send email to sara...@googlegroups.com
>> To unsubscribe from this group, send email to
>> sara-list-...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/sara-list?hl=en
>> ---
>> You received this message because you are subscribed to the Google
>> Groups "Society of Amateur Radio Astronomers" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to sara-list+...@googlegroups.com
>> <mailto:sara-list+...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sara-list/CAABBjRCh8F52k2XPgbx4rdwiq-%2BTh-dSk7TDk1xJQLPhoN2C8A%40mail.gmail.com
>> <https://groups.google.com/d/msgid/sara-list/CAABBjRCh8F52k2XPgbx4rdwiq-%2BTh-dSk7TDk1xJQLPhoN2C8A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sara-list+...@googlegroups.com
> <mailto:sara-list+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/5FD2CEAF.6000104%40typnet.net
> <https://groups.google.com/d/msgid/sara-list/5FD2CEAF.6000104%40typnet.net?utm_medium=email&utm_source=footer>.

Dave Typinski

unread,
Dec 11, 2020, 5:44:28 PM12/11/20
to sara...@googlegroups.com
Thanks Alex, that looks very useful.
--
Dave
> >> <dav...@typnet.net <mailto:dav...@typnet.net>> wrote:
> >>
> >>
> >> Hi Paul,
> >>
> >> In a perfect world, yes. We can, however, work with imperfect data
> >> and obtain a
> >> reasonable sub-bin-width approximation of the peak's location using
> >> curve fitting.
> >> --
> >> Dave
> >>
> >>
> >> On 12/10/20 21:15, Paul Oxley wrote:
> >> > Dave
> >> >
> >> > If you want to know where the peak occurs, you need more sample
> >> points.
> >> >
> >> > Paul
> >> >
> >> > On Thursday, December 10, 2020, 08:43:17 PM EST, Dave Typinski
> >> > <dav...@typnet.net <mailto:dav...@typnet.net>
> <mailto:dav...@typnet.net <mailto:dav...@typnet.net>>> wrote:
> >> >
> >> >
> >> > Hi Michiel,
> >> >
> >> > Here's a plot of the data showing one peak with some prominent
> >> side lobes. The
> >> > idea is to fit a Gaussian / Lorentzian / whatever curve to the
> >> main peak to
> >> > determine its location along the horizontal axis with sub-sample
> >> precision
> >> > (i.e., interpolation between two samples).
> >> >
> >> > I expect the true peak is somewhere between bin numbers 897 and 898.
> >> >
> >> >
> >> > What I'm looking for is a Python package that does this sort of
> >> peak curve
> >> > fitting. No sense reinventing the wheel if it already exists.
> >> > --
> >> > Dave
> >> >
> >> >
> >> > On 12/10/20 13:50, Michiel Klaassen wrote:
> >> >> Hi Dave,
> >> >> There seems to be no answers to your question, and I myself think
> >> it is also
> >> >> difficult to answer.
> >> >> Can you give an example graph with (paint) indication what you want.
> >> >> regards,
> >> >> Michiel
> >> >> parac.eu <http://parac.eu> <http://parac.eu>
> <mailto:sara...@googlegroups.com>
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sara-list+...@googlegroups.com
> <mailto:sara-list%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/62a6d07f-a0ef-5288-da5f-3200858af5aa%40ownmail.net.
>
>
>
> --
> ''Υπερέβαλε εαυτόν και κατέκτησε τον κόσμο ''-Αρχιμήδης
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to sara-list+...@googlegroups.com
> <mailto:sara-list+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/CAFi7tau4RSqtVEXZaZhHFu5wYX-L%3DH8z%3Dw0_fq-Yo94VG4hFFg%40mail.gmail.com
> <https://groups.google.com/d/msgid/sara-list/CAFi7tau4RSqtVEXZaZhHFu5wYX-L%3DH8z%3Dw0_fq-Yo94VG4hFFg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Dave Typinski

unread,
Dec 11, 2020, 5:46:27 PM12/11/20
to sara...@googlegroups.com
Hi Michiel,

Indeed, stack overflow is a gold mine, often more useful than the package docs.
--
Dave


On 12/11/20 07:10, Michiel Klaassen wrote:
> Hi Dave,
> Well; that generated a lot of response.
> If you google "gaussian fit python" , you get a lot of solutions; I am often
> inspired by the solutions from " stackoverflow"
> Regards
> Michiel
> parac.eu <http://parac.eu>
>
> Op vr 11 dec. 2020 om 11:34 schreef Alexandros Filothodoros
> <alexfilo...@gmail.com <mailto:alexfilo...@gmail.com>>:
> >> <dav...@typnet.net <mailto:dav...@typnet.net>> wrote:
> >>
> >>
> >> Hi Paul,
> >>
> >> In a perfect world, yes. We can, however, work with imperfect data
> >> and obtain a
> >> reasonable sub-bin-width approximation of the peak's location using
> >> curve fitting.
> >> --
> >> Dave
> >>
> >>
> >> On 12/10/20 21:15, Paul Oxley wrote:
> >> > Dave
> >> >
> >> > If you want to know where the peak occurs, you need more sample
> >> points.
> >> >
> >> > Paul
> >> >
> >> > On Thursday, December 10, 2020, 08:43:17 PM EST, Dave Typinski
> >> > <dav...@typnet.net <mailto:dav...@typnet.net>
> <mailto:dav...@typnet.net <mailto:dav...@typnet.net>>> wrote:
> >> >
> >> >
> >> > Hi Michiel,
> >> >
> >> > Here's a plot of the data showing one peak with some prominent
> >> side lobes. The
> >> > idea is to fit a Gaussian / Lorentzian / whatever curve to the
> >> main peak to
> >> > determine its location along the horizontal axis with sub-sample
> >> precision
> >> > (i.e., interpolation between two samples).
> >> >
> >> > I expect the true peak is somewhere between bin numbers 897 and 898.
> >> >
> >> >
> >> > What I'm looking for is a Python package that does this sort of
> >> peak curve
> >> > fitting. No sense reinventing the wheel if it already exists.
> >> > --
> >> > Dave
> >> >
> >> >
> >> > On 12/10/20 13:50, Michiel Klaassen wrote:
> >> >> Hi Dave,
> >> >> There seems to be no answers to your question, and I myself think
> >> it is also
> >> >> difficult to answer.
> >> >> Can you give an example graph with (paint) indication what you want.
> >> >> regards,
> >> >> Michiel
> >> >> parac.eu <http://parac.eu> <http://parac.eu>
> <mailto:sara...@googlegroups.com>
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sara-list+...@googlegroups.com
> <mailto:sara-list%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/62a6d07f-a0ef-5288-da5f-3200858af5aa%40ownmail.net.
>
>
>
> --
> ''Υπερέβαλε εαυτόν και κατέκτησε τον κόσμο ''-Αρχιμήδης
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> <mailto:sara...@googlegroups.com>
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> <mailto:sara-list-...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sara-list+...@googlegroups.com
> <mailto:sara-list+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/CAFi7tau4RSqtVEXZaZhHFu5wYX-L%3DH8z%3Dw0_fq-Yo94VG4hFFg%40mail.gmail.com
> <https://groups.google.com/d/msgid/sara-list/CAFi7tau4RSqtVEXZaZhHFu5wYX-L%3DH8z%3Dw0_fq-Yo94VG4hFFg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Society of Amateur Radio Astronomers" group.
> To post to this group, send email to sara...@googlegroups.com
> To unsubscribe from this group, send email to
> sara-list-...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sara-list?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Society of Amateur Radio Astronomers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to sara-list+...@googlegroups.com
> <mailto:sara-list+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sara-list/CAABBjRCVfM%3DBnAyFCFHokUX62eaW9C09m0vJzyZGk4V%3DMDN1eg%40mail.gmail.com
> <https://groups.google.com/d/msgid/sara-list/CAABBjRCVfM%3DBnAyFCFHokUX62eaW9C09m0vJzyZGk4V%3DMDN1eg%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Dave Typinski

unread,
Dec 11, 2020, 5:56:54 PM12/11/20
to sara...@googlegroups.com
Hi Jim,

Yes, absolutely. A couple participants on the HamSCI list schooled me on this
method only yesterday.

In case anyone else wonders where this wonderfully easy-to-use formula comes
from, here you go:

https://ccrma.stanford.edu/~jos/sasp/Quadratic_Interpolation_Spectral_Peaks.html

But it gets even better: turns out that a Gaussian peak in linear space is a
parabola in dB space. This makes fitting Gaussian peaks as easy as falling off
a log.

Thanks a bunch, Jim!
--
Dave

Dave Typinski

unread,
Dec 11, 2020, 6:07:59 PM12/11/20
to sara...@googlegroups.com
Hi Nathan,

I'm not sure why those sidelobes are spaced the way they are. Could be a result
of how the time series was generated, but I don't know how to tell.

This project involves frequency measurement, but not as most envision it. The
source data is a 7-year continuous time series with one-minute resolution
indicating when Jovian DAM was visible in the AJ4CO spectral data. Just a 1 or
a 0 at each 1-minute data point. That series is the input to the DFT.

There are several peaks (and harmonics of those peaks) in the DFT output.

The largest peak is from the sidereal day, as one would imagine.

Another peak comes from the rotation rate of the Jovian magnetic field.

It is the locations of such peaks that I wish to pin down as closely as possible.
--
Dave
Reply all
Reply to author
Forward
0 new messages