%%
% For simple, we use [1,2,3,4] to represent the four QPSK bit pairs.
% Every bit pairs corresponde to a basic 4 bits heating sequency, for example 1 corresponde to [1 1 0 0].

clc;clear;
fd = 100;% communication rates and it can be changed further;
Duration_t=1/fd/2;% The basic heating duration;
len=977;% The data length;
% barker = [-1 -1 -1 -1 -1 1 1 -1 -1 1 -1 1 -1];%13 bit barker code
barker = [3 3 3 3 3 0 0 3 3 0 3 0 3].';%header;
symbol = [1 1 0 0;0 1 1 0;1 0 0 1;0 0 1 1];
symbol = symbol.';%corresponde to 00 01 10 11
s = RandStream('mt19937ar','Seed',0); % To generate a constant sequence
x = randi(s,[0,3],len,1);
preamble = zeros(10,1);%Consecutive 0 to establish a phase reference
trans = [barker;preamble;x];%The virtual data packet
trans = trans + 1;
modsymbol = symbol(:,trans);
modsymbol = modsymbol(:);%The heating sequency, 1 reprsent heating on, 0 represent heating OFF
num_0=0;
num_1=0;
T_all=[];
modulation_f=2000;
fid=fopen('CN_sequence2.tlan','wt');

for i=1:length(modsymbol)
    if mod(i,10)==0
        display(['处理至：',num2str(i/1200*100)]);
    end;
    if modsymbol(i)==0
        num_0=num_0+1;
        n=num_1*20+num_0;
        status(n,:)='RFOFF';
        
        T=(i-1)*Duration_t;
        T_all=[T_all T];
        T=T*1e6;
        fprintf(fid,'%s %10.1f %s\n','AT',T,'   RFOFF*');
        
    else  
        num_1=num_1+1;
        T=(i-1)*Duration_t;
        for j=1:20
           n=(num_1-1)*20+num_0+j;
           T_1=T+(j-1)*1/modulation_f/2;
           T_all=[T_all T_1];
           T_1=T_1*1e6;
            if mod(j,2)==0;
                status(n,:)='RFOFF';
                fprintf(fid,'%s %10.1f %s\n','AT',T_1,'   RFOFF*');

            else
               status(n,:)='RFONN';
               fprintf(fid,'%s %10.1f %s\n','AT',T_1,'   RFON*');
            end
        end
    end
     
end
fclose(fid)
