MATLAB: How to generate a sawtooth wave

homeworksawtooth wave

I get the graph i want.But the amplitude is from -10 to 10. Can i know how can i change it to 0 to 10 and keep the same graph?
Here is what i tried so far: T=2*4; Fs=1000; dt = 1/Fs; t = 0:dt:T-dt; x =-10*sawtooth(2*pi*t);
plot(t,x) grid on

Best Answer

You only need to make 2 changes:
T=2*4;
Fs=1000;
dt = 1/Fs;
t = 0:dt:T-dt;
x = sawtooth(2*pi*t); % <— REMOVE THE ‘-10’ HERE
x = (x + 1)*5; % <— ADD THIS LINE
plot(t,x)
grid on