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

📄 codeg2.m

📁 Adaptive Filter_Simon Haykin_Matlab_code STBC
💻 M
字号:
function [err]=codeG2(index,snr,nsymb,Mary,modtype,nRx,err);
%Routine that preforms simulations based on PSK Mary modulation
%and using coding scheme G2.
%G2 : |  x1   x2  |
%     | -x2*  x1* |

nTx=2;
%Generate Data
%Possible Symbol Set
Set=[0:Mary-1]';  
Smap=dmodce(Set,1,1,modtype,Mary);
%Generate Symbols
symb=randsrc(nsymb,1,[0:Mary-1]);
%Encode with PSK
msg=dmodce(symb,1,1,modtype,Mary);
%Noise Stats
Eav=Smap'*Smap/Mary;
NF=10^(snr/10);
S=sqrt(nTx*Eav/(2*NF));
%Operate on a block by block itteration
for k=1:nTx:nsymb,
    Sv=msg(k:k+nTx-1);  %vector of next two bits
    %Make next block
    G2 = [ Sv(1)  Sv(2);
          -Sv(2)' Sv(1)'];
    noise=S*(randn(2,nRx) + i*randn(2,nRx));  %Get noise
    H=(randn(nTx,nRx) + i*randn(nTx,nRx))/sqrt(2);  %Channel Gain Matrix  
    rx=G2*H + noise;
    
    %Demodulate
    %Detecting s1 and s2, minimize decision metric
    S1=0; S2=0; Hnorm=0;
    for j=1:nRx,
        S1 = S1 + rx(1,j)*H(1,j)' + rx(2,j)'*H(2,j);
        
        S2 = S2 + rx(1,j)*H(2,j)' - rx(2,j)'*H(1,j);
        
        Hnorm = Hnorm + H(:,j)'*H(:,j);
    end
    for L=1:Mary
        Con = (-1 + Hnorm) * Smap(L) * Smap(L)';
     
        %For s1
        est_s1(L)= real( (S1 - Smap(L))*(S1 - Smap(L))' + Con);
        
        %For s2
        est_s2(L)= real( (S2 - Smap(L))*(S2 - Smap(L))' + Con);
    end
    %Choose symbols that minimize the est_* vectors
    %Decide in favour of min value 
    [A,B]=min(est_s1);
    shat(k)=B-1;    %-1 b/c index starts at 0 and not 1
    [A,B]=min(est_s2);
    shat(k+1)=B-1;    %-1 b/c index starts at 0 and not 1
end
%Compute symbol errors
err(index)=sum(shat~=symb');    

⌨️ 快捷键说明

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