Data smoothing and getting maximum

J

jabidof

Hello All,

I have a set of (x,y) data coming from measurements. When plotting the
points, i get a kind of staircases curve. I thus like to:
1st: smooth the data and
2nd: get the maximum of the smoothed curve.

Any idea to help me?

jpc
 
P

Peter J. Holzer

jabidof said:
I have a set of (x,y) data coming from measurements. When plotting the
points, i get a kind of staircases curve. I thus like to:
1st: smooth the data and

That depends on *how* you want to smooth the curve. If your data points
have to be on the smoothed curve, you may want to google for "cubic
interpolation" (or you may even get away with linear or quadratic
interpolation). If the problem is only that the plots don't "look nice",
you may want to check the manual of your plotting software - maybe it
can do this already.

Measurements often have an error. If you want to filter out these
errors, you may want to compute the average or median of a few adjacent
points or program some more sophisticated filter based on the known
properties of your measurements.
2nd: get the maximum of the smoothed curve.

Just sample the smoothed curve in sufficiently small intervals and take
the maximum of the samples. (There is probably a more accurate way for
each method of interpolation, but this is the simplest and most
general).

hp
 
X

xhoster

jabidof said:
Hello All,

I have a set of (x,y) data coming from measurements. When plotting the
points, i get a kind of staircases curve. I thus like to:
1st: smooth the data and

If you think your data fits a parabola well, (and if you don't [or even
if you do], then you should probably treat your question as primarily a
statistics matter, not a Perl matter) you could fit the data using
Statistics::Regression:

my $reg = Statistics::Regression->new(
3, "sample regression",
[ "const", "X", "X**2" ]
);

foreach (@x_y_pair) {
my ($x,$y)=@$_
$reg->include( $y, [ 1, $x, $x**2 ] );
};



2nd: get the maximum of the smoothed curve.


my @theta=$reg->theta();
die "Data seem to have min, not max" unless $theta[2]<0;
my $extreme_occurs_at = -$theta[1]/$theta[2]/2;

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top