1
我在Scilab中使用以下代码来生成使用矢量化方法的脉冲宽度调制。但是,在改变周期数,TimePeriod百分比时,我得到了不希望的图。请问任何人都可以帮助我?使用Scilab生成PWM
percent=input("Enter the percentage:");
TimePeriod=input("Enter the time period:");
Cycles=input("Enter the number of cycles:");
x=0:Cycles*TimePeriod;
t=(percent/100)*TimePeriod;
for n=0:0.01:Cycles
y(((n*TimePeriod)< x) & (x<(n*TimePeriod+t))) = 1;
y(((n*TimePeriod+t)< x)& (x<((n+1)*TimePeriod))) = 0;
plot(y,'b','LineWidth',2)
end