%
%  Thsir routine implements a trigonometric Fourier Sine Series
%
% Inputs: N is the number of terms to be used in the series
%
function Fourier_Sine_series(N)
%
%  one period of the function goes from low to high
%
  low = -2;
  high = 2;
%
%  the difference between low and high is one period
%
  T = high-low;
  w0 = 2*pi/T;
%
%  the periodic function
%
  x  = @(t) 0.*(t<-1)+t.*((-1<=t)&(t<1))+0.*(t>=1);
%
%   find b(1) to b(N)
%
  for k = 1:N
      arg = @(t) x(t).*sin(k*w0*t);
      b(k) = (2/T)*quadl(arg,low,high);
  end;
%
%  determine a time vector over one period
%
  t = linspace(low,high,1000);
%
%  Find the Fourier series representation
%
  est = 0;
  for k = 1:N
      est = est + b(k)*sin(k*w0*t);
  end;
%
%  plot the results
%
  plot(t,x(t),'-',t,est,'--'); grid; xlabel('Time (sec)');
  legend('Original','Fourier Series','Location','NorthWest');
  title(['Number of Terms = ', num2str(N)]);
%