📄 code_generation.m
字号:
function [code] = code_generation(ofdm_signal)
global H
% get N
s = get(H.edit8,'String');
N = st2de(s);
N = round(N);
% get null number
s = get(H.edit9,'String');
NULL = st2de(s);
NULL = round(NULL);
% create real part of ofdm_signal
ofdm_signal_real = real(ofdm_signal);
% the ofdm_signal will be scanned scan_size points at a time
% when a block is found between the null, it will be used to create the output code
scan_size = NULL / 20;
scan_size = round(scan_size);
% buffer the ofdm_signal to be divisible by scan_size
ofdm_signal_real = buffer(ofdm_signal_real,scan_size);
% find number of scans to perform
scan_num = length(ofdm_signal_real) / scan_size;
% a and b will be used to indicate the start and end of an ofdm_block
% a = start
% b = end
a = 0;
b = 0;
% array containing a and b
locations = 0;
location_index = 1;
% possible_b will be assigned when a possible end to the block is found
% only when this is confirmed will it be assigned to b
possible_b = 0;
% initialize code
code = 0;
% index of code
index = 1;
% scan loop, scans the ofdm_signal scan_size points at a time
for k = 1:scan_num,
% begin_block is the beginning index of the scan block
begin_block = (k * scan_size) - (scan_size - 1);
% end_block is the ending index of the scan block
end_block = (k * scan_size);
% create scan block from ofdm_signal
scan_block = ofdm_signal_real(begin_block:end_block);
% if a non null is found we must be scanning an ofdm block
% the first non null index is assigned to a
if any(scan_block) == 1
% x = non null indexes
x = find(scan_block);
% last equals last non null index
last = x(length(x));
% the last non null index may be an end to the ofdm block
% so possible_b is assigned to it
possible_b = begin_block + (last - 1);
% if a beginning to a block has not been found, a is assigned to the first
% null index
if a == 0
a = begin_block + (x(1) - 1);
end
% if all elements in the scan_block is null, we must be in null space within
% the ofdm_signal
else
% if a possible b has been found and the current scan is within the null space
% this means the ofdm_block ended last scan, so the possible_b found in the last scan
% was the actual end of the ofdm_block
if possible_b ~= 0;
b = possible_b;
end
end
% if a and b have both been found, an entire ofdm_block has been indexed
% this block can now be converted into a block of binary code
if a ~= 0 & b ~= 0
% the ofdm_block is converted into a block of code
[code_block,f_comp] = code_block_generation(ofdm_signal_real(a:a + N - 1));
% code array is updated with code_block
code(index:index + 7) = code_block;
% increase code array index
index = index + 8;
% update locations array with a and b
locations(location_index:location_index + 1) = [a b];
location_index = location_index + 2;
% reset a and b
a = 0;
b = 0;
possible_b = 0;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -