How to generate stair function ?

조회 수: 5 (최근 30일)
Alice
Alice 2016년 8월 8일
답변: Robert 2016년 8월 8일
I want to generate a stair function from sensor measures in Simulink with certain specifications :
  • My goal is to sample the measures I get from the sensor ; I am working on a Real Time Interface
  • If time equals 0, I want the function's result to be equal to the sensor's measures
  • If time ~= 0, I want to create a kind of discret signal : if time is not divisible by 1.72, I want the variable A to stock all the sensor's measures and the function's result should be equal to the previous definition. If time is divisible by 1.72, I want the function's result to be equal to the mean of the sensor's measures during the sampling period.
I have made this code, but it isn't working
function slopeSampling = SamplingFunction(slope, time)
if (time == 0)
definitionSlopeSampling = slope;
clear A;
else
if(mod(time, 1.71) ~= 0)
A = [A slope];
else
definitionSlopeSampling = mean(A);
end
end
slopeSampling = definitionSlopeSampling;
end

답변 (1개)

Robert
Robert 2016년 8월 8일
If you have the DSP System Toolbox, you can use the included block Mean to calculate a running mean of your signal, then reset it every 1.72 seconds according to your design.
If you do not, you could recreate the running mean with a pair of discrete time integrator blocks.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by