simulink matlab function block

1 回表示 (過去 30 日間)
mohamed samhy
mohamed samhy 2016 年 4 月 11 日
編集済み: Saurabh 2024 年 7 月 31 日
what function should I write in Simulink matlab function block so it generates square pulses as pulse generator , please help

回答 (1 件)

Saurabh
Saurabh 2024 年 7 月 31 日
編集済み: Saurabh 2024 年 7 月 31 日
Hi Samhy,
So you want to generate square pulses using 'Simulink MATLAB function' block and in order to do so, we need to configure the Inputs and Outputs of the model.
  • Define the inputs and outputs of the function, let say 't', 'period', 'amplitude' are inputs and 'y' is the output.
  • Use 'Constant' block for period and amplitude and 'clock' block to provide the current simulation time t.
  • To visualize the output, use the 'scope' block.
Attaching the link to demo model, make necessary changes according to the requirement.
MATLAB code that generates square pulses (Needs to be defined inside the ‘MATLAB function’ block) :
function y = fcn(u, data, data1)
time_in_period = mod(u, data);
if time_in_period < (data / 2)
y = data1;
else
y = 0;
end
The below screenshot is the output of the model:
I hope this was helpful.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by