How to generate stair function ?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Robert
am 8 Aug. 2016
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.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!