📄 code_block_generation.m
字号:
function [code_block,f_comp] = code_block_generation(ofdm_block)
global H
% get AMP
s = get(H.edit18,'String');
AMP = st2de(s);
AMP = round(AMP);
% get B
s = get(H.edit21,'String');
B = st2de(s);
B = round(B);
s = get(H.edit12,'String');
M = st2de(s);
M = round(M);
% convert ofdm_block into frequency domain
% this information will be used to produce binary code
f = fft(ofdm_block);
f_real = real(f);
f_imag = imag(f);
% create dc(direct current) and fc(carrier frequency) information
dc = 1;
fc = length(f) + 1;
% fix phase shift by comparing phase shift of adjacent frequencies to
% our frequencies
if get(H.checkbox1,'Value') == 1
for k = 1:4,
[mag1,phase_change] = r2p(f(dc + (k * M) + B));
mag_factor = mag1 / (AMP / 3);
[mag2,phase] = r2p(f(dc + (k * M)));
new_mag = mag2 / mag_factor;
new_phase = phase - phase_change;
f(dc + (k * M)) = p2r(new_mag,new_phase);
f(fc - (k * M)) = conj(f(dc + (k * M)));
f(dc + (k * M) + B) = 0;
f(fc - (k * M) - B) = 0;
end
end
f_comp = f;
% initialize code_block and index
code_block = [0 0 0 0 0 0 0 0];
index = 1;
% loop to produce code from ofdm_block
for n = 1:4;
% find real and imaginary parts of frequency components (left is sideband of dc, right is sideband of fc)
real_f = real(f(dc + (n * M)));
%right_real = real(f(fc - (n * M)));
imag_f = imag(f(dc + (n * M)));
%right_imag = imag(f(fc - (n * M)));
% locate frequency spikes representing sine wave
if real_f > (AMP - 100) & real_f < (AMP + 100) & imag_f > (-AMP - 100) & imag_f < (-AMP + 100)
% sine wave represents [0 0]
code_block(index:index + 1) = [0 0];
end
% locate frequency spikes representing -sine wave
if real_f > (-AMP - 100) & real_f < (-AMP + 100) & imag_f > (-AMP - 100) & imag_f < (-AMP + 100)
% -sine wave represents [0 1]
code_block(index:index + 1) = [0 1];
end
% locate frequency spikes representing cosine wave
if real_f > (-AMP - 100) & real_f < (-AMP + 100) & imag_f > (AMP - 100) & imag_f < (AMP + 100)
% cosine wave represents [1 0]
code_block(index:index + 1) = [1 0];
end
% locate frequency spikes representing -cosine wave
if real_f > (AMP - 100) & real_f < (AMP + 100) & imag_f > (AMP - 100) & imag_f < (AMP + 100)
% -cosine wave represents [1 1]
code_block(index:index + 1) = [1 1];
end
% update code index
index = index + 2;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -