close all; clear all;

proxies=70;
years=1400:1980;
samples=length(years);

calib=years>=1902 & years<=1980;

AR1=0.2;
proxy=exp(filter(1,[1 -AR1],0.15*randn(samples,proxies)));

mann_mu=mean(proxy(calib,:));
mann_sigma=std(detrend(proxy(calib,:)));
mann_stand=(proxy-repmat(mann_mu,samples,1))./...
              repmat(mann_sigma,samples,1);
[mannPC1 D V]=svds(mann_stand,1);

% calib zero mean+possible flip
calib_mean=mean(mannPC1(calib));
mannPC1=(2*(mean(mannPC1)<calib_mean)-1)*(mannPC1-calib_mean);

smooth=22;
mannPC1_filt=filter(ones(smooth,1)/smooth,1,mannPC1);
figure;
plot(years,mannPC1,'c')
hold on;
plot(years(smooth:end),mannPC1_filt(smooth:end),'r');
axis tight; grid on;