function rcos_pulse_ua

% Generate amplitude and (partial) tlan files for raised-cosine pulse
% For Swedish ELF/VLF around 1 kHz, 2013:
%  Note that the first UPDt command should be replaced by a STMCt command.
%

dt=1.1; % DDS amplitude time step (microseconds)
plen=100; % pulse length (microseconds)
pstart=1.0; % pulse start time in tlan file (microseconds)
elf_freq=1000;  % Hz
txn='UPDt*';  % for all transmitters
%txn='UPDt3&4';  % for t3,4

rep=10^6/(elf_freq); % microseconds

npoints=ceil(plen/dt);
pkpoint=ceil(npoints/2);
t=dt*(0:npoints-1);

a=0.5 - 0.5*cos(2*pi*t/plen);

figure
plot(t,a,'o-');
xlabel('Time \mu s');
ylabel('Amplitude');

% Write out the amplitude file for 

fid=fopen('rcos_pulse.paf','w');
if fid==-1
  error('cannot open paf file');
end

% header and first (tx off) amplitude
% fprintf(fid,'AMPPAR_VS 2.0\n1 0\n');
fprintf(fid,'PAFPAR_VS 2.0\nBLOCKLEN 3 BYTES\n');

% amplitude for our pulse
for k=1:npoints
%  x=uint16(round(16383*a(k))); % 0x3FFF is maximum amplitude
  x=(a(k)); % 0x3FFF is maximum amplitude
%   fprintf(fid,'%d A 0x%04X\n',k,x);
   fprintf(fid,'%d A %0.4f\n',k,x);
end

% final tx off amplitude
fprintf(fid,'%d A 0\n',npoints+1);

fclose(fid);


% Write out the pulse part of the tlan file

fid=fopen('rcos_pulse_part.tlan','w');
if fid==-1
  error('cannot open tlan file');
end

fprintf(fid,'AT      %.1f  RFON*,NOFLP*        %% Open SOUSY switch\n',pstart - 1);
for k=1:pkpoint
  fprintf(fid,'AT      %.1f    %s\n',pstart+(k-1)*dt,txn);          %% Kick in AMP(%d)\n', ...
end
fprintf(fid,'SETTCR    %.1f\n',rep/2);       %% Kick in final amplitude\n', ...
for k=pkpoint+1:npoints
  fprintf(fid,'AT      %.1f    %s\n',pstart+(k-1)*dt,txn);          %% Kick in AMP(%d)\n', ...
end


fprintf(fid,'AT      %.1f    %s\n',pstart+npoints*dt,txn);       %% Kick in final amplitude\n', ...
fprintf(fid,'AT      %.1f  RFOFF*              %% Close SOUSY switch\n', pstart+npoints*dt+1);
fprintf(fid,'AT      %.1f  REP              %% ', rep);

fclose(fid);
