Generating PWM using Scilab -


i using following codes in scilab generate pulse width modulation using vectorization method.but getting undesirable plot while varying number of cycles,timeperiod,percent.could 1 me in this?

percent=input("enter percentage:"); timeperiod=input("enter time period:"); cycles=input("enter number of cycles:");  x=0:cycles*timeperiod; t=(percent/100)*timeperiod;  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 

i modified code , works. code slow due loop many many calls. (scilab , matlab optimated matrix operations. weaken in loops. reduced number of calls number of cycles.

percent=input("enter percentage:"); timeperiod=input("enter time period:"); cycles=input("enter number of cycles:"); ts = 0.01; // sample time  x=ts:ts:cycles*timeperiod; on  = ones(1, percent/100*timeperiod/ts); off = zeros(1, (1 - percent/100)*timeperiod/ts); signal = []; cycle = 1:cycles  signal = [signal, on, off]; end  figure(1) plot2d(x, signal); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -