How to generate stair function ?

1 回表示 (過去 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 Center および File ExchangeSources についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by