Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Berkin Birol
Berkin Birol il 16 Nov 2018
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 il 21 Nov 2018
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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su General Applications in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by