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