Matlab: Calculation range I have this Matlab/Octave code:
% needed for Octave ----------------------    
pkg load signal
% ------------------------------------------------

% Square -----------------------------------------
figure
N=50;                               % harmonics
fs = 1000;
r_start=0;
r_end=10;
r_step=1/fs;
r = r_start:r_step:r_end;           % range
w_sqr = square(r)/2;                % Square wave [-0.5:0.5]
%w_sqr = square(r);                  % [-1:1]


plot(r,w_sqr);
axis([r_start r_end -1.2 1.2]);
grid on;
hold on;

% Fourier -----------------------------------------
i=1;
sum=0;
for t=r
  for n=1:N
    sum = sum + (2*sin(n*t)+sin(pi*n-n*t)-sin(n*t+pi*n))/(2*pi*n);
  end
  F(i)=sum;
  i=i+1;
  sum = 0;
end;
F=F';
plot(r,F);
axis([r_start r_end -1.2 1.2]);

which results this:

By changing the value of variable w_sqr to (square(r)+1)/2 and calculation of F to F(i)=(1/2)+sum I get the result in range [0:1].
What changes are needed to do in Stage 2 to get the result in range [-1:1]?
I guess f(i) = 2*sum should do: