MATLAB: Is there a way to have a variable pulse signal in Simulink 6.4 (R2006a)

communications blocksetcycledutyModulationpulsesimulinkvariablewidth

I have a duty cycle coming out of a part of my model. I want to create a pulse signal based on that duty cycle. The duty cycle will be changing with time.

Best Answer

Below is an example of how to implement a variable pulse in Simulink. It involves using the Pulse Generator block and a MATLAB file S-function. The S-function takes the desired pulse width (this could be coming from a controller) and uses SET_PARAM to change the PulseWidth property of the Pulse Generator block.
The example is feeding the desired pulse width into the S-function as a percentage of the Period property in the Pulse Generator block (i.e. duty cycle). You can alter the S-function if you want to feed in the exact width. This would involve adding commands to calculate the pulse width percentage as a function of the period and the desired pulse width.
The set_param command is done on line 272 of the S-function in the Outputs() function. Note there are no actual outputs from the S-function, it is just used to change parameters. Also note another set_param command is done in the InitializeConditions() function. This is to ensure a valid value of PulseWidth is in the Pulse Generator block at the start of simulation.
Here are a few helpful documentation links (You can copy and paste the commands below into the MATLAB command window to display the documentation):
set_param
web([docroot,'/toolbox/simulink/slref/set_param.html'])
Writing Level-2 MATLAB file S-Functions
web([docroot '/simulink/sfg/writing-level-2-matlab-s-functions.html'])
Pulse Generator
web([docroot,'/toolbox/simulink/slref/pulsegenerator.html'])
Pulse Width Modulator Generator
web([docroot,'/toolbox/physmod/powersys/ref/pwmgenerator.html'])