📄 generate_preamble.m
字号:
%
% Return the preamble (SYNC + SFD) according to the parameters
% code_id: index of the ternary code to use
% L: spreading factor
% N_sync: length of packet sync sequence in symbols
% N_sfd: length of start frame delimiter in symbols
%
% function pre = generate_preamble(L, code_id, N_sync, N_sfd)
%
function [pre sfd_code N_sync N_sfd] = generate_preamble(L, code_id, N_sync, N_sfd)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% check validity of input values %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%should have at least on argument L, max 4 arguments
error(nargchk(1,4,nargin));
% assign default values if less than 4
switch(nargin)
case 1
code_id = 1;
N_sync = 64; %default
N_sfd = 8; %data rates > 0.8Mbps
case 2
N_sync = 64; %default
N_sfd = 8; %data rates > 0.8Mbps
case 3
N_sfd = 8; %data rates > 0.8Mbps
end
% check whether values are standard compliant
if(L ~= 16 & L ~= 64 & L ~= 4)
error('value for L not standard compliant, must be 16, 64 or 4');
end
if(code_id < 1 | code_id > 24 | floor(code_id) ~= code_id)
error('value for code_id not standard compliant, must be 1:24');
end
if(N_sync ~= 16 & N_sync ~= 64 & N_sync ~= 1024 & N_sync ~= 4096)
error('value for N_sync not standard compliant, must be 16, 64, 1024 or 4096');
end
if(N_sfd ~= 8 & N_sfd ~= 64)
error('value for N_sfd not standard compliant, must be 8 or 64');
end
%also check for incompatible combinations
if( (code_id > 8 & L ~= 4) | (code_id <= 8 & L == 4) )
error('combination of code length and spreading factor L is not standard compliant')
end
if( L == 64 & N_sync == 4096 )
error('combination of spreading factor L and sync length N_sync is not standard compliant')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% construct symbols Si %%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
code = [];
% get the ternary code
if(code_id < 9)
code = len31_preamble_code(code_id);
else
error('ternary codes of length 127 not yet implemented')
end
len_code = length(code);
%construct symbol si
si = reshape([code; zeros(L-1,len_code)],1,L*len_code);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% construct Preamble %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%sync part
sync = repmat(si,1,N_sync);
%sfd part
sfd_code = [];
if(N_sfd == 8)
sfd_code = [0 1 0 -1 1 0 0 -1];
else
sfd_code = [ 0 +1 0 -1 +1 0 0 -1 0 +1 0 -1 +1 0 0 -1 -1 0 0 +1 0 -1 0 +1 0 +1 0 0 0 -1 0 -1 0 -1 0 0 +1 0 -1 -1 0 -1 +1 0 0 0 0 +1 +1 0 0 -1 -1 -1 +1 -1 +1 +1 0 0 0 0 +1 +1];
end
sfd = kron(sfd_code,si);
pre = [sync sfd];
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -