% eda09_07
% smooth neuse.txt

% load data
D=load('neuse.txt');
t=D(:,1);
d=D(:,2);
Dt=t(2)-t(1);
[N, i]=size(d);

% construct 3-point smoothing filter
s1 = [1, 2, 1]';
s1 = s1/sum(s1);
L1 = length(s1);
L1h = floor(L1/2);

% filter and time shift
d1 = conv(s1, d);
d1 = d1(1+L1h:N+L1h);

% construct 19-point smoothing filter
s2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]';
s2 = s2/sum(s2);
L2 = length(s2);
L2h = floor(L2/2);

% filter and time shift
d2 = conv(s2, d);
d2 = d2(1+L2h:N+L2h);

% plot only this time range (for clarity)
L1=1;
L2=500;

% plot
figure(1);
clf;

subplot(3,1,1);
set(gca,'LineWidth',2);
axis( [t(L1), t(L2), 0, max(d) ] );
hold on;
plot(t(L1:L2),d(L1:L2),'k-', 'Linewidth', 2);
xlabel('time, days');
ylabel('d-obs');

subplot(3,1,2);
set(gca,'LineWidth',2);
axis( [t(L1), t(L2), 0, max(d) ] );
hold on;
plot(t(L1:L2),d1(L1:L2),'k-', 'Linewidth', 2);
xlabel('time, days');
ylabel('3-point');

subplot(3,1,3);
set(gca,'LineWidth',2);
axis( [t(L1), t(L2), 0, max(d) ] );
hold on;
plot(t(L1:L2),d2(L1:L2),'k-', 'Linewidth', 2);
xlabel('time, days');
ylabel('21-point');