function data = HDB3_code(source_data,V_first,NZ_first)

len=length(source_data); %% Determine V code, use 6 to represent V code index=1; v=V_first; % Initial polarity of V code while index<=len-3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% student code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % task : For every consecutive four bits in the source data, check if the value is [0,0,0,0]. If yes, set the fourth bit as the V code, and alternate the polarity of adjacent V codes (use 6 to represent V code).

if source_data(1,index:index+3)==[0,0,0,0];
    v=-v;% Alternate the polarity of V code
    source_data(1,index:index+3)=[6,v]; % Use 6 to represent V code and positive/negative values to represent polarity

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
index=index+4; else index=index+1; end end data1 = source_data;% Data after determining V code

%% Determine B code, use 7 to represent B code nr=NZ_first;% Initial polarity of non-zero code index=1; while index<=len if index<=len-3 if abs(source_data(1,index:index+3)) == [0,0,0,6]% If it is 000V if nr ~= (source_data(1,index+3))/6% Alternate polarity of non-zero code if V code and the previous non-zero code have opposite polarity source_data(1,index)=nr*-17; % Use 7 to represent B code and opposite polarity to the initial non-zero code nr=nr-1; end index=index+4; else

% Learn from V code program and complete the missing part of the following B code program if source_data(index)~= 0 ;% If it does not satisfy 000V, it is AMI code source_data(index)= nr*-1 ;% Alternate polarity nr=nr*-1;% Alternate polarity of non-zero code for the next group end index=index+1; end else if source_data(index)~=0% Encode the last three bits of the source data using AMI code source_data(index)=nr*-1; nr=nr*-1; end index=index+1; end end data2=source_data;

%% HDB3 mark restoration for i=1:len if abs(source_data(1,i)) == 6 % If it is V code source_data(1,i)=source_data(1,i)/6; elseif abs(source_data(1,i)) == 7 % If it is B code source_data(1,i)=source_data(1,i)/7; else end end

data3=source_data; data=[data1;data2;data3];%[Determine V code:Determine B code:Encoded data]

en

function data = HDB3_codesource_dataV_firstNZ_firstlen=lengthsource_data; 确定V码V码用6表示index=1; v=V_first; V码初始极性while index=len-3 student code task 对信号源source_data每连续四位判断其值是否为0000若是则令其第四位为V码并且相邻V码极性

原文地址: https://www.cveoy.top/t/topic/fRGL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录