필터 지우기
필터 지우기

How to make a signal have a slower sample rate

조회 수: 5 (최근 30일)
João Araújo
João Araújo 2020년 11월 16일
댓글: Mathieu NOE 2020년 11월 17일
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!

채택된 답변

Mathieu NOE
Mathieu NOE 2020년 11월 17일
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');
  댓글 수: 2
João Araújo
João Araújo 2020년 11월 17일
I also thought I would have to do a cycle for this. Thank you for taking the time to write the code, you've been very helpful!
Mathieu NOE
Mathieu NOE 2020년 11월 17일
you're welcome !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2020년 11월 16일
hello
for integer factor downsampling use : decimate
for non integer factor resampling use resample (not needed in your case)
EXAMPLE: Decimate a signal by a factor of four
t = 0:.00025:1; % Time vector
x = sin(2*pi*30*t) + sin(2*pi*60*t);
y = decimate(x,4);
subplot(1,2,1);
stem(x(1:120)), axis([0 120 -2 2]) % Original signal
title('Original Signal')
subplot(1,2,2);
stem(y(1:30)) % Decimated signal
title('Decimated Signal')
  댓글 수: 3
Mathieu NOE
Mathieu NOE 2020년 11월 16일
so you mean you would like to pick 1 sample every 20 and hold the value on the 19 next iterations ?
it's like applying a zero hold sampler
João Araújo
João Araújo 2020년 11월 17일
Exactly this yes.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by