Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Berkin Birol
Berkin Birol el 16 de Nov. de 2018
Comentada: Berkin Birol el 21 de Nov. de 2018
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 comentarios
Berkin Birol
Berkin Birol el 16 de Nov. de 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 el 21 de Nov. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre General Applications en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by