How to generate stair function ?
显示 更早的评论
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
2016-8-8
0 个投票
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.




类别
在 帮助中心 和 File Exchange 中查找有关 Signal Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!