why is output of my MATLAB function in Simulink raises with slope?

2 ビュー (過去 30 日間)
Berkin Birol
Berkin Birol 2018 年 11 月 16 日
コメント済み: Berkin Birol 2018 年 11 月 21 日
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
pulseGeneratorOutput.png
  3 件のコメント
Berkin Birol
Berkin Birol 2018 年 11 月 16 日
Thank you for your reply. The solver was fixed step and in the same solver Simulink's own pulse generator works just fine. I think I miss something due to my lack of experience in Simulink.
Berkin Birol
Berkin Birol 2018 年 11 月 21 日
I solved the issue with zero order hold block and uploaded the block to: https://www.mathworks.com/matlabcentral/fileexchange/69483-customizable-pulse-generator.
But, I am still wondering if there is an another way(without ZOH) to do this.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by