MATLAB: Unexpected shift after downsampling using decimate

decimatedownsampleresample

n = 1000;
t = 1:n;
x = rand(1,n) - 0.5;
x = sin(2*pi/100*t);
y = decimate(x,4);
figure('color','w');
ha = axes('nextplot','add','box','on');
plot(ha,t,x,'k','marker','.');
plot(ha,t(1:4:end),y,'r','marker','o'); addkeycb;
There is a shift of 3 points.

Best Answer

Add the default filter to produce the correct decimation:
y = decimate(x,4,'fir');