Search code examples
ccurve-fittinggsl

Finding the center of 1D data


Say I have data: 0 (or near 0), 0, 0, ..., 1, 10, 52, 80, 100, 100, 100, 100 (for a while), 90, 45, 5, 0, 0, 0... I want to find the index (not necessarily an int, I want more precision) of the 'center' of my plateau of data.

My first thought was to do a gaussian fit, but the data is rather flat for a while in the center. So maybe some kind of square (?) fit. I've been looking at minimization with gsl also, but I don't know what the simplest way to do this would be.

A simple way would be to find the index corresponding to the median value, but that gives me only a precision of 1. With a curve fitting I can do better.

Note: I'm in C and can use GSL, but a general math solution would work too!


Solution

  • Suggested algorithm:

    1. Optionally filter data: median of 3, low pass, etc.

    2. Find average value: Avg

    3. Find average index of values above Avg: Center_index.

    4. Average a few of the "values above" near Center_index.