function x=data_tx(rate,levels,pulseID)
%	x=data_tx(rate,levels,pulseID)
% synthesize a TX signal (with clock period in first element)
% The number of data levels is an integer > 1,
% symbols/sec = rate*fc/fs, where
% 0<rate<3 ( max for zero ISI is 2)
% pulse type is governed by pulseID:
% 	1, for square pulse
% 	2, for impulse
% 	3, for halfwave sinusoid
% 	4, for fullwave raised sinusoid
% Single pulse mode is forced if pulseID is negative.

	L=2048;fs=24000;ts=1/fs;fc=1500;
	clk=round(fs/(rate*fc)); % samples per bit period
	nbits=floor(L/clk); % number of data bits

	pulse=ones(1,clk); % square pulse is the default
	if abs(pulseID)==2
		pulse=sqrt(clk); % impulse
	end
	if abs(pulseID)==3
		pulse=sin([1:clk]*pi/(clk+1));
		pulse = pulse/sqrt(pulse*pulse');
	end
	if abs(pulseID)==4
		pulse=sin([1:clk]*pi/(clk+1));
		pulse=pulse.*pulse;
		pulse = pulse/sqrt(pulse*pulse');
	end
	if abs(pulseID)<5
% construct a message sequence d and Tx PAM signal x(t)
		if pulseID>0
			d=(2/(levels-1))*(floor(levels*rand(1,nbits)))-1;
		else
			d=zeros(1,nbits);d(floor(nbits/2))=1;
		end		
		x=zeros(1,L);
		x([1:clk:1+clk*(nbits-1)])=d;
		x=[clk,conv(x,pulse)];x=x(1:L+1);
		%sound(x,fs);
	end	
	
	