why is output of my MATLAB function in Simulink raises with slope?
2 views (last 30 days)
Show older comments
Hello everyone,
I tried to implement my own pulse generator with variable inputs. When I simulate it and compare results with the build in Pulse Generator I see that my output becomes high with a slope, but Simulink's Pulse Generator becomes high immediately. How can I have this kind of output?
Simulation performed for 100 seconds, with Fixed-step, discrete solver and Fixed-step size has been taken "1".
function [y, countTime] = fcn(Amplitude, period, width, phaseDelay, timeIncremental, Clock, pre_y, preCountTime)
%Setting previous values.
y=pre_y;
countTime=preCountTime;
%y is high for 'width' time, so it can be low again
if countTime==width
y=0;
end
%Counting the time between two high values
if y>0 || countTime>0
countTime=countTime+timeIncremental;
end
%Output is high first time after 'phase delay' passes.
if Clock==phaseDelay
y=Amplitude;
end
%Period has been reached, y is high again.
if countTime==period
countTime=0;
y=Amplitude;
end
3 Comments
Answers (0)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!