八度-锯齿功能

时间:2019-02-23 14:28:22

标签: octave

我想在Octave中绘制锯齿函数。我知道我可以使用命令“ sawtooth(t)”,但是我没有软件包,所以我创建了以下函数。

function x = pieceWise2bis(t)
x = zeros (size (t));

ind1 = t >= 10 & t < 13;
x(ind1) = +20;

ind2=t >= 13 & t < 16;
x(ind2) = -20;

ind3=t >= 16 & t < 19;
x(ind3) = +20;

ind4=t >= 19 & t < 22;
x(ind4) = -20;
endfunction

当我绘制此函数时,我没有得到想要的结果,因为我想要一个真正的锯齿函数,而不是像这样的子的周期函数。 有人可以告诉我如何修改我的代码吗? 谢谢

1 个答案:

答案 0 :(得分:2)

It appears that the usual way to load sawtooth, by installing signal which requires control.... is not working, in any case you are way better off writing this yourself. Here's one of many ways to do it:

clear; %% this line tells octave the remainder is more than just a func.
## usage: ST = sawtooth (time)
function ST = sawtooth (time)
  ST=rem(time,2*pi)/2/pi;
endfunction

time=linspace(0,20,101); % second line of main program (clear is 1st)
PriSawtooth=sawtooth(time);
plot(time,PriSawtooth,'linewidth',1)