5

我有一个信号,我想在 MATLAB 中使用 picewise 三次样条算法消除基线漂移。

 d=load(file, '-mat');



 t=1:length(a);

 xq1=1:0.01:length(a);
  p = pchip(t,a,xq1);
  s = spline(t,a,xq1);
    % 
 figure, hold on, plot(a, 'g'), plot(t,a,'o',xq1,p,'-',xq1,s,'-.')
 legend('Sample Points','pchip','spline','Location','SouthEast')

但我看不到任何基线删除..原始数据正好在插值上。显示的情节

或者在另一个信号中,我们可以看到没有删除基线。 情节2

问题是我如何在 MATLAB 中“使用 peicewise 三次样条插值来消除基线漂移”。

谢谢

4

2 回答 2

5

您似乎希望将多项式拟合到您的数据中,以估计由于热变化引起的基线漂移。问题spline在于它总是完全适合您的数据(类似于pchip),因为它是一种插值技术。您可能想要一个可以使用的 courser fit polyfit。以下代码示例显示了如何使用它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

在此处输入图像描述

于 2017-08-30T21:25:54.070 回答
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')

结果

于 2017-09-01T01:44:44.020 回答