function plotFS(x,T,M)
%   plotFS(x,T,M)
% Periodic signals. x represents one period, from
% t=0 to t=T-ts, where ts=T/length(x)is the sampling period.
% (1) plot two periods of x(t), from -T to T.
% (2) plot magnitude of FS coefficients from -M to M.
% (3) plot phase of FS coefficients from -M to M.
   figure
   X=Fseries(x);
   N=length(X);
   if N < M+1
       X=[X,zeros(1,M+1-N)];
   end
   Y=[conj(fliplr(X([2:M+1]))),X([1:M+1])];
   subplot(3,1,2)
   f0=1/T;              % fundamental frequency
   f=[-M*f0:f0:M*f0];   % frequency axis values
   stem(f,abs(Y),'b')
   title('Fourier Series magnitude vs. frequency in Hertz')
   subplot(3,1,3)
   stem(f,(1/pi)*angle(Y),'b')
   hold on
   title('Fourier Series phase/pi vs. frequency in Hertz')
   v=axis;axis([v(1:2),-1.2 1.2]);
   plot([v(1:2)],[0 0],'k')
   % do time domain panel
   subplot(3,1,1)
   L=512;N=length(X);
   if L<2*N
       L=2*L;
   end
   y=real(ifft(L*[X,zeros(1,L+1-2*N),conj(fliplr(X(2:N)))]));
   plot([-T:T/length(y):T],[y,y,y(1)],'g',[-T,T],[0,0],'k');
   mn=min(y);mx=max(y);d=(mx-mn+1e-3)*.2;
   axis([-T,T,mn-d,mx+d]);
   title('periodic signal vs. time, in seconds')

