function[ys,yps]=ref_delayed_mcp(a,b,stat,ref);
% Reference delayed by b, scaled by a,
%
[tstep,trise,tfall,gain,NPE,Ishot,G,nadc,bw,tau,taus,T,R,fs,ts,apjit]=params();
%
% t0max=floor(4*tau);
% new
t0max=floor(1*tau);
a; b=-b;
% clear x y; 
clear figure;
if 5*tau+b-2<=0 
    disp('-b>=5*tau-2'); disp(-b); disp(5*tau-2); return
   if n<5*tau-b
       disp('n<5*tau+t0'); disp(n); disp(-b); disp(5*tau+b); return
   end
end
% Reference delayed by scaled to i0.
% t0<0,  right shift
% Get scaled and delayed reference from fy
%
       stat=size(ref,1)-2
       py=ref(stat+1,:); 
       npy=size(py,2);
       dpy=ref(stat+2,:);
       % Delay by b
       py(t0max+b:npy)=py(1:npy-b-t0max+1); 
       py(1:b+t0max-1)=0;
       dpy(t0max+b:npy)=dpy(1:npy-b-t0max+1); dpy(1:b+t0max-1)=0;
       % Scale
       py=a*py/abs(max(py)); dpy=a*dpy/abs(max(py));
       % Sample
       ys=py(tau:ts:size(py,2)); yps=dpy(tau:ts:size(py,2));
       size(ys)
       size(yps)
       return
       % ys and yps are sampled at ts, but b is in tstep, and should !
       %
% figure(555); subplot(2,1,1); plot(ys,'r'); subplot(2,1,2); plot(yps,'b');
% title('Sampled shaper response'); 
% pause;

