|
From: | Carlo de Falco |
Subject: | Re: Smooth line approximating minima of a data series |
Date: | Wed, 24 Feb 2010 17:29:39 +0100 |
On 24 Feb 2010, at 13:12, Matthias Brennwald wrote:
On Feb 24, 2010, at 10:38 AM, Carlo de Falco wrote:2010/2/24 Matthias Brennwald <address@hidden>:Dear allConsider a series of data values that reflect a smooth function (e.g.a low-degree polynomial), but there might be additional features inthe data (e.g. narrow peaks or noise). I'd like to fit a polynomial to this data, whereby this polynomial reflects a smooth approximation ofthe minima of the raw data (I call this the "base line"). The following might help to illustrate what I'm trying to accomplish: x = [-1:0.01:1]; % x-axis values p = [-3 2 1 0]; yp = polyval (p,x); % make up a polynomial reflecting the "base line" for illustration y = yp + rand(size(x)); % this would be the raw data plot (x,y,x,yp); legend ('raw data','base line') % plot the raw data and the polynomial for illustration Has anyone an idea of how to accomplish this? Are there standard methods? I'd appreciate any hints. Thanks Matthiasdoes this do what you want? x = [-1:0.01:1]; p = [-3 2 1 0]; yp = polyval (p,x) y = yp + randn(size(x)); plot (x,y,x,yp); yy = polyfit (x, y, 4) plot (x, polyval (yy, x), x, y, x, yp)No, this is not what I'm after. I am looking for a polynomial (or some other smooth function) that tracks the (local) minima of the data series (as in the plot of my original example). The polyfit function returns a polynomial wich minimizes the sum of the squares of the residuals relative to each of the the data points. In contrast to this, I would like to do the minimization such that each residuals is positive, i.e. polynomial values never exceed the the values in the data series.Matthias
what about the following: x = [-1:0.01:1]; p = [-3 2 1 0]; yp = polyval (p,x); y = yp + rand(size(x)); plot (x, y) vref = 1e-4; v1 = @(t) interp1 (x, y, t, "nearest"); fun = @(v2, v2dot, t) v2dot - max ((v1(t)-v2)/vref, -10); yf = daspk (fun, y(1), 0, x); plot (x, y, x, yf, x, polyval (polyfit (x(:), yf(:), 4), x))this actually traces (approximately) the maxima rather than minima but the modifications are trivial
c.
[Prev in Thread] | Current Thread | [Next in Thread] |