function plotFT(x,fs,tmax,fmax)
%  plotFT(x,fs,tmax,fmax)
% plot the Fourier transform of a finite duration pulse
% which is essentially bandlimited.
% x is either 1xL (causal), or 2xL (two-sided). 
    clf
	ts=1/fs;
	mn=min(min(x));mx=max(max(x));d=(mx-mn+1e-3)*.2;
    X=FTform(x,fs); 
    L=length(X);                %one half the fft size
	[M,N]=size(x);
	xx=IFTform(X,fs);
	subplot(2,2,1)
	Lzoom=min(L,fix(tmax/ts));  %zoom plot
	t=ts*[-Lzoom+1:Lzoom-1];
	plot(t,[flipud(xx(2,2:Lzoom)')',xx(1,1:Lzoom)],'g')
	axis([t(1),max(t),mn-d,mx+d]);
	title('signal vs. time (secs)')
	ylabel('zoom in')	
	subplot(2,2,3)
	t=ts*[-N+1:N-1];
	plot(t,[flipud(xx(2,2:N)')',xx(1,1:N)],'k')
	axis([t(1),max(t),mn-d,mx+d]);
	ylabel('entire signal')
    % Frequency plots	
	subplot(2,2,2)
	f0=fs/(2*L);
	fm=min(fmax,(L-1)*f0);
	M=fix(fm/f0);
	f=f0*[0:M];
	XX=X(1:M+1);
	mag=abs(XX);
	plot(f,mag,'r')
	axis([0,M*f0,0,1.1*max(mag)]);
	title('Fourier transform vs. frequency (Hz)')
	ylabel('magnitude')
	subplot(2,2,4)
	mu=angle(XX)/pi;
	%give preference to pi over -pi
	plot(f,mu-sign(mu+.999)+1,'b')
	ylabel('phase/pi')
	axis([0,M*f0,-1,1]);
	
	
	