%clf;
%figure;
t=-5:.1:5;
Y=[ones(length(t),1) t' t'.^2 t'.^3];
 A=[2;-10;-4;-3];
%A=[3;1;-4;1];
%A=[2;-2;-4;-2];
%A=[2;-2;-4;-2];
Model=Y*A;
MeanCubic=mean(Model)
VarianceCubic=var(Model)
plot(t,Model);
title('Original cubic expression')
ylabel('f(t)')
xlabel('t')
pause;
% Adding Error just for fun
Xt=Model+normrnd(0,100,length(t),1);
%
MeanSeries=mean(Xt)
VarianceSeries=var(Xt)
plot(t,Xt,'+',t,Xt);
title('Time series-Original Model + Error')
xlabel('t')
ylabel('Xt')
pause;
%Spencer's 15-term
s=[-3 -6 -5 3 21 46 67 74 67 46 21 3 -5 -6 -3]*(1/320);
%Spencer's 21-term
%s=[-1 -3 -5 -5 -2 6 18 33 47 57 60 57 47 33 18 6 -2 -5 -5 -3 -1]*(1/350);
for j=1:length(t)-length(s)+ 1
   yt(j)=s*Xt(j:length(s)+(j-1));
end
MeanFilter=mean(yt)
VarianceFilter=var(yt)
start=floor((length(s)/2)+1)
finish=length(yt)+floor((length(s)/2))
%plot(t(8:length(y)+7),y),'+',t(8:length(y)+7),y);
plot(t(start:finish),yt,'+',t(start:finish),yt)
pause;
%Not needed,just for fun
acf(Xt,40,'Autocorrelation of Xt')
pause;
acf(yt,40,'Autocorrelation of yt')
pause;

