clear
close all

%% Parameter
beta=1e-6;

%% Read data
[x,f]=textread('filter1d.csv','%f,%f');

%% Extract data
h=x(2)-x(1);
N=length(x);

%% Assemble matrices
e=ones(N,1);
% Laplace
A=spdiags([e -2*e e],[-1 0 1],N,N);
A(1,:)=zeros(1,N);
A(N,:)=zeros(1,N);
% Identity
B=spdiags(e,0,N,N);
% Operator
OP=-beta/(h*h)*A + B;

%% Solve
sol=OP\f;

%% Plot
plot(x,f,'r',x,sol,'k')
legend('noisy signal','filtered signal')

%% Write as eps
print -depsc2 -r600 filter1d.eps
