MATLAB: How to make a signal have a slower sample rate

sample rate

Hi, I'm sure this has an easy answer but I'll ask anyway.
I have a signal (in this case vehicle speed) on a sample test with a sample rate of 2ms (the system sample rate). The real system being simulated has a can signal which updates every 40ms, or 20 samples in this case.
How can I alter the signal I have, which changes every sample, to only change every 20 samples?
Thank you!

Best Answer

so this would be the code :
samples = 1000;
input_signal = 1 + sin(2*pi*(1:samples)/samples)+ 0.025*rand(1,samples);
decim_factor = 20; % nb of samples / decimation
output_signal = zeros(1,samples); % pre allocation
% zero overlap mean averaging
for ci=1:floor(samples/ decim_factor)
start_index = 1+(ci-1)*decim_factor;
stop_index = min(start_index+ decim_factor,length(input_signal));
output_signal(start_index:stop_index) = input_signal(start_index);
end
figure(1),
plot((1:samples),input_signal,'b',(1:samples),output_signal,'-r');