在MATLAB中以周期时间序列填充数据空白

时间:2014-10-23 12:22:54

标签: matlab time-series trend gaps-in-data

我正在寻找一种方法来填充包含周期性数据的时间序列中的数据间隙(在这种情况下,频率等于潮汐频率,因此包括半昼夜和弹簧/小频率)使用MATLAB。数据系列还包含噪声,我想在填补时间间隔的人工数据之上叠加。数据有一定的趋势,我想保留。理想情况下,我会研究一种在时间间隔的任何一侧使用记录数据的方法。

有没有在Matlab中这样做?

谢谢。

唐纳德约翰

1 个答案:

答案 0 :(得分:1)

所以可以做的是“猜测”一个模式函数,并使用一些优化例程使该模型拟合数据。然后仔细查看残差并获得表征残差的噪声的统计数据。然后应用模型并添加噪声。在Matlab代码中,Ansatz看起来像:

t_full = linspace(0,4*pi,500);
t = t_full([1:200, 400:end]);
f = 2;
A = 3;
D = 5;
periodic_signal = A*sin(t*f) + D;
trend = 0.2*t;
noise = randn(size(t));
y = periodic_signal + trend + noise;

% a model for the data -- haha i know the exact model here!
model = @(par, t) par(1)*sin(t*par(2)) + par(3) + par(4)*t;
par0 = [2, 2, 2, 2]; % and i can make a good guess for the parameters
par_opt = nlinfit(t,y, model, par0); % and optimize them

% now from the residuals (data minus model) one can guess noise
% characteristics
residual = y - model(par_opt, t);

% compare residual with "real noise" (should coincide if optimisation
% doesnt fail)
[mean(noise), mean(residual)] % about [0, 0]
[std(noise), std(residual)] % about [1, 1]
missing_data = 201:399;
new_noise = mean(residual) + std(residual)*randn(size(missing_data));

% show what is going on
figure
plot(t,y,'k.')
hold on
plot(t_full, model(par_opt, t_full), 'r-', 'linewidth', 2);
plot(t_full(missing_data), model(par_opt, t_full(missing_data)) + new_noise, 'r.')

legend('data', sprintf('y(t) = %.2f*sin(%.2f*t) + %.2f + %.2f*t + e(t)', par_opt), 'reconstructed data')

结果如下图: