function [newshocklowalt,newshockhighalt] = newsperc(impulses_unanticipated,IRFmean,VVVmean,M,maxh,nhor)

pp=16;
IRFFc = permute(impulses_unanticipated,[2 3 1]);
%     IRFmean = squeeze(median(impulses_unanticipated(:,:,irep,:),4));  
[SEDalt, low, high] = impln(IRFFc,M,maxh,pp);

IRFlow = IRFmean - SEDalt;   
IRFhigh = IRFmean + SEDalt;
    
%     [DECOMPlow,TOTlow] = vardecomp_eric(IRFlow(:,:,irep),nhor,p,M);
%     [DECOMPhigh,TOThigh] = vardecomp_eric(IRFhigh(:,:,irep),nhor,p,M);

V9low = low((M+1:M:(M-1)*M+1),1:maxh)' ;  
V9high = high((M+1:M:(M-1)*M+1),1:maxh)';

WWWlow = zeros(M-1);
WWWhigh = zeros(M-1);

for j = 1:maxh
    JJlow = (maxh+1-j)*V9low(j,:)'*V9low(j,:);   
    JJhigh = (maxh+1-j)*V9high(j,:)'*V9high(j,:);
            
    WWWlow = WWWlow+JJlow;   
    WWWhigh = WWWhigh+JJhigh;
end

[Qlow,QQlow] = eig(WWWlow);
[Qhigh,QQhigh] = eig(WWWhigh);
    
RQlow = diag(QQlow);
RQhigh = diag(QQhigh);

[maxvlow,maxilow] = max(RQlow);
[maxvhigh,maxihigh] = max(RQhigh);

xlow = [0 Qlow(:,maxilow)'];
xhigh = [0 Qhigh(:,maxihigh)'];
  
for i = 1:M
    newshocklowalt(i,:) = IRFlow((0:M:(M-1)*M)+i,1:nhor)'*VVVmean';    
    newshockhighalt(i,:) = IRFhigh((0:M:(M-1)*M)+i,1:nhor)'*VVVmean';
end
