Pulse train with duty cycle variable.

2 ビュー (過去 30 日間)
Carlos Martínez
Carlos Martínez 2017 年 4 月 3 日
回答済み: Joseph Cheng 2017 年 4 月 4 日
Hello, I want to make a Pulse train(for a simulation of the switching a dc-dc boost elevator). Here is my code.
dur=input('Please set the time the wave will last: ');
per=input('Please set the Period: ');
duty=input('Please set the Duty Cycle: ');
t=0:dur/1000:dur-dur/1000;
ton=ones(1,floor(1000/(length(dur)/(per*(duty/100)))));
toff=zeros(1,ceil(1000/(length(dur)/(per*((100-duty)/100)))));
normal=[ton,toff];
y=repmat(normal,1,(length(dur)/per));
plot(t,y);
But I am having a lot of problems for floating numbers of periods, duty cycles and so on...
Any idea of how to improve or make it really efficient?

回答 (1 件)

Joseph Cheng
Joseph Cheng 2017 年 4 月 4 日
why not try something like this:
t=0:per/1000:per-per/1000; %define period
normal = zeros(1,numel(t));
normal(t<per*duty/100))=1;
then just remap this to either equal the total duration or just above and then cut to length.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by