⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encoder.m

📁 空时格码编码器
💻 M
字号:
%4-PSK Trellis codes for two transmit antennas
clear all
len_stream = 22;
% Input_stream = round(rand(1,len_stream));                  % the input stream
% Input_stream = [0 1 1 1 0 0 1 0 1 0 0 1 1 0 1 0 0 1 0 0 1 0];
Input_stream = [1	1	1	0	0	0	0	1	0	1	0	1	0	1	1	1	0	1	1	1	1	1];
Input_stream = [1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 1 1 1 1 1 1];
% Size = size(Input_stream);
len_codes = len_stream/2;                                                  % divide the stream into two parts
upper_codes(1) = 0;
lower_codes(1) = 0;
Upper_stream(1) = 0;
Lower_stream(1) = 0;
% Branch_coef = [0 2;2 0;0 1;1 0];  %4 states
Branch_coef = [0 2;2 0;0 1;1 0;2 2]; %8 states
% Branch_coef = [0 2;2 0;0 2;0 1;1 2;2 0]; %8 states
sizeBc = size(Branch_coef); 
mem_order = sizeBc(1)-2;                              % the memory order 
states = 2^mem_order;                                   % n states
                                               
upper_order = mem_order/2 - mod(mem_order/2,1);                                    % the memory order of the upper and lower branches
lower_order = (mem_order+1)/2 - mod((mem_order+1)/2,1);
k = 1;
for i = upper_order+1:upper_order+len_codes
    Upper_stream(i) = Input_stream(2*k-1);                                     % the upper branch's stream
    k = k+1;
end
k = 1;
for i = lower_order+1:lower_order+len_codes
    Lower_stream(i) = Input_stream(2*k);                                       % the lower branch's stream
    k = k+1;
end 
for i = 1:lower_order                                                     % let the state of the memory be zero after coding
    Upper_stream(upper_order+len_codes+i) = 0;
    Lower_stream(lower_order+len_codes+i) = 0;
end
for t = 1:len_codes+lower_order                                            % the output of the encoder
    upper_codes(t) = 0;
    lower_codes(t) = 0;
    for p = 1:upper_order+1                      
        upper_codes(t) = upper_codes(t)+Upper_stream(t+upper_order+1-p)*Branch_coef(p,1);
        lower_codes(t) = lower_codes(t)+Upper_stream(t+upper_order+1-p)*Branch_coef(p,2);
    end
    for q = 1:lower_order+1
        upper_codes(t) = upper_codes(t)+Lower_stream(t+lower_order+1-q)*Branch_coef(upper_order+1+q,1);
        lower_codes(t) = lower_codes(t)+Lower_stream(t+lower_order+1-q)*Branch_coef(upper_order+1+q,2);
    end
    upper_codes(t) = mod(upper_codes(t),4);
    lower_codes(t) = mod(lower_codes(t),4);
end
out_codes(1,:) = upper_codes;
out_codes(2,:) = lower_codes;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -