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

📄 dcode2.m

📁 根据空时分组编码的特性及缺陷,考虑使用差分空时编码,该程序实现差分空时分组编码的性能仿真,是根据Space–Time Block Coding for Wireless一书的性能仿真
💻 M
字号:
function [err] = dcode2(M,V,Mary,nsymb,snr)
%Routine to do coding / decoding for differential stbc

%Possible Symbol Set
Set=[0:Mary-1]';  
Smap=dmodce(Set,1,1,'psk',Mary)/sqrt(2);
%Generate Symbols
symb=randsrc(nsymb,1,[0:Mary-1]);
%symb=[0 1 1 1 0 1 0 0]'; nsymb = length(symb); 
%Encode with PSK
msg=dmodce(symb,1,1,'psk',Mary)/sqrt(2);
%Noise Stats
Eav=Smap'*Smap/Mary;
NF=10^(snr/10);
S=sqrt(2*Eav/(2*NF));

%To start the encoder
%Channel components
h = (randn(2,1) + i*randn(2,1))/sqrt(2); 
H = [h(1) h(2)'; h(2) -h(1)'];
N1 = S*(randn(1,2) + i*randn(1,2));  %Get noise for time 2t-1 
Nold = [N1(1) N1(2)'];

%Message
Gold = [msg(1) msg(2);
    -msg(2)' msg(1)'];
Sest = [msg(1) msg(2)];
%Use step index of 4 b/c decoding is done over 2 blocks or 4 time steps
for t=3:2:nsymb,
    %ENCODING
    a1 = Smap(1); a2 = Smap(1);
    %Get next two bits and preform mapping
    A = msg(t)*a1' + msg(t+1)*a2';
    B = -msg(t)*a2 + msg(t+1)*a1;
    
    s = A*Gold(1,:) + B*Gold(2,:);
    Gnew = [s(1) s(2);
        -s(2)' s(1)'];
    
    %CHANNEL
    N2 = S*(randn(1,2) + i*randn(1,2));  %Get noise for time 2t+1 
    Nnew = [N2(1) N2(2)'];

    
    %DECODING
    D = zeros(1,2);
    Rold1 = Gold(1,:)*H + Nold;
    Rnew1 = Gnew(1,:)*H + Nnew;
    
    Rold2 = Gold(2,:)*H + [Nold(2) -Nold(1)'];
    
    D(1) = Rnew1*Rold1';
    D(2) = Rnew1*Rold2';
    D = D/norm(D); %confine to unit circle
    
    %Preform ML decoding
    dist = 9*ones(Mary^2,1);
    for k = 1:Mary^2,
        dist(k) = (D - V(k,:))*(D - V(k,:))';
    end
    [x,p] = sort(dist);
    est = M(p(1),:);
    Sest = [Sest est];
    
    %Set for next itteration
    Gold = Gnew;  
    Nold = Nnew;
end
Sest = conj(Sest');
msg(1:2) = [];
Sest(1:2) = [];
err = sum(msg~=Sest);
return

⌨️ 快捷键说明

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