Remove base line drift with peicewise cubic spline algorithm using MATLAB

时间:2017-08-30 20:40:53

标签: matlab interpolation spline cubic-spline

I have a signal which I want to remove the basline drift using the picewise cubic spline algorithm in MATLAB.

{{csrf_field()}}
@for($x = 0; $x++ < 50;)
    <input type="text" name="type[name]">
@endfor

But I cant see any basline removal..The orginal data is exactly on the interpolated one.Displayed plot

or in the other signal as we can see no base line is removed. plot2

The question is how I can "use peicewise cubic spline interpolation to remove basline drift" in MATLAB.

Thank you

2 个答案:

答案 0 :(得分:5)

您可能希望将多项式拟合到数据中,以估算由于热变化引起的基线漂移。 spline的问题在于它总是完全适合您的数据(类似于pchip),因为它是一种插值技术。您可能希望使用polyfit获得适合您的courser。以下代码示例显示了如何使用polyfit来估算漂移。在这种情况下,我拟合了一个三阶多项式。

% generate some fake data
t = 0:60;
trend = 0.003*t.^2;
x = trend + sin(0.1*2*pi*t) + randn(1,numel(t))*0.5;

% estimate trend using polyfit
p_est = polyfit(t,x,3);
trend_est = polyval(p_est,t);

% plot results
plot(t,x,t,trend,t,trend_est,t,x-trend_est);
legend('data','trend','estimated trend','trend removed','Location','NorthWest');

<强>更新

如果您有曲线拟合工具箱,则可以使用额外的平滑约束拟合三次样条曲线。在上面的示例中,您可以使用

trend_est = fnval(csaps(t,x,0.01),t);

而不是polyfitpolyval。您必须使用平滑参数,0表示完全线性,1表示与spline相同的结果。

enter image description here

答案 1 :(得分:3)

我认为你应该减少计算样条拟合的点数(避免过度拟合)并连续插入原始x数据上的拟合。

t = 0:60;
trend = 0.003*t.^2;
x = trend + sin(0.1*2*pi*t) + randn(1,numel(t))*0.5;

figure;hold on
plot(t,x,'.-')

%coarser x-data
t2=[1:10:max(t) t(end)]; %%quick and dirty. I probably wanna do better than this
%spline fit here
p = pchip(t,x,t2);
s = spline(t,x,t2);
plot(t2,s,'-.','color' ,'g')

%interpolate back
trend=interp1(t2,s,t);

%remove the trend
plot(t,x-trend,'-.','color' ,'c')

result