#scilab
#scilab
Вопрос:
Хотя я знаю, как генерировать пилообразную волну в Matlab с помощью sawtooth(x)
, но я не знаю, как сгенерировать ее в Scilab. Нужно ли мне использовать xcos
для этого? Или это какие-то другие способы? Не удалось найти в Интернете ничего, кроме SAWTOOTH_F
in xcos
.
Ответ №1:
Пожалуйста, найдите ниже функцию, которая генерирует пилообразный сигнал
function y = sawtooth(t,percent)
//SAWTOOTH Sawtooth and triangle wave generation.
// sawtooth(t) generates a sawtooth wave between -1 and 1 with period
// 2*%pi for the time discretization in t such that for t=0 y=-1.
// The percent argument gives the raise time in percentage of the
// period. The signal raises linearly from the beginning of each period
// up to that point and then decreases linearly up to end of the period.
// If percent is omitted it assumed to be equal to 1.
if typeof(t)<>"constant"|~isreal(t)|and(size(t)>1) then
error(msprintf(_("%s: Wrong type for argument #%d: Real vector expected.n"),"sawtooth",1))
end
if argn(2)==1 then
percent=1;
else
if typeof(percent)<>"constant"|~isreal(percent)|or(size(percent)<>1) then
error(msprintf(_("%s: Wrong type for argument #%d: Real scalar expected.n"),"sawtooth",2))
end
if percent > 1|percent < 0 then
error(msprintf(_("%s: Wrong value for input argument #%d: Must be in [%d %d].n"),"sawtooth",2,0,1))
end
end
//shift t to make it positive and have y=-1 for t=0
mnt=min(t)
if mnt<0 then
t=t ceil(abs(mnt)/(2*%pi))*(2*%pi)
end
//periods indicator
pind=modulo(t,2*%pi)/(2*%pi);
//set the increasing parts
//the indices of the increasing signal parts
iinc=find(pind<=percent);
if iinc<>[] then
//set the increasing parts
y(iinc)=2*pind(iinc)-percent;
if percent<>0 then y(iinc)=y(iinc)/percent;end
end
//set the decreasing parts
//the indices of the decreasing signal parts
idec=1:size(t,"*");
idec(iinc)=[];
if idec<>[] then
y(idec)=-2*pind(idec) 1 percent;
if percent<>1 then y(idec)=y(idec)/(1-percent);end
end
//special case
if percent==0 then
y(pind==0)=1;
end
endfunction