codeg1.m

来自「Adaptive Filter_Simon Haykin_Matlab_code」· M 代码 · 共 46 行

M
46
字号
function [err]=codeG1(index,snr,nsymb,Mary,modtype,nRx,err);
%Routine that preforms simulations based on PSK Mary modulation
%and using coding scheme G1 (note this means no coding)

nTx=1;
%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
msg=dmodce(symb,1,1,modtype,Mary);
%Noise Stats
Eav=Smap'*Smap/Mary;
NF=10^(snr/10);
S=sqrt(nTx*Eav/(2*NF));

%Simulate Channel
noise=S*(randn(nsymb,nRx) + i*randn(nsymb,nRx));
H=(randn(nsymb,nRx) + i*randn(nsymb,nRx))/sqrt(2);  %Channel Gain Matrix  
for j=1:nRx,
rx(:,j) = H(:,j).*msg + noise(:,j);
end
%Preform maximum liklihood demodulation
for k=1:nsymb
    h=H(k,:); r=rx(k,:); 
    for L=1:Mary
        C = 0;
        for j=1:nRx,
            C = C + (r(j) - h(j)*Smap(L))' * (r(j) - h(j)*Smap(L));
        end
        est_s1(L) = C;
    end
    %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
end
%Compute symbol errors
err(index)=sum(shat~=symb');





⌨️ 快捷键说明

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