Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octave - sawtooth function

Tags:

octave

I would like to plot a sawtooth function in Octave. I know that I can use the command "sawtooth(t)" but I don't have the package so I created the following function.

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

When I plot this function I don't get the result I'm looking for because I want a real sawtooth function and not a periodic function with crenels like that. COuld someone tell me how I could adapt my code ? Thank you

like image 819
S.Pri Avatar asked May 24 '26 20:05

S.Pri


1 Answers

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)
like image 135
Clinton Winant Avatar answered Jun 03 '26 08:06

Clinton Winant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!