📄 codeg4.m
字号:
function [err]=codeG4(index,snr,nsymb,Mary,modtype,nRx,err);
%Routine that preforms simulations based on QAM Mary modulation
%and using coding scheme G3.
%G4 : | x1 x2 x3 x4 |
% | -x2 x1 -x4 x3 |
% | -x3 x4 x1 -x2 |
% | -x4 -x3 x2 x1 |
% | x1* x2* x3* x4*|
% | -x2* x1* -x4* x3*|
% | -x3* x4* x1* -x2*|
% | -x4* -x3* x2* x1*|
nTx = 4;
delay = 8;
%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));
%Operate on a block by block itteration
for k=1:4:nsymb,
Sv=msg(k:k+3); %vector of next nTx bits
%Make next block
G4_1 = [Sv(1) Sv(2) Sv(3) Sv(4);
-Sv(2) Sv(1) -Sv(4) Sv(3);
-Sv(3) Sv(4) Sv(1) -Sv(2);
-Sv(4) -Sv(3) Sv(2) Sv(1)];
G4= [G4_1; conj(G4_1)];
noise=S*(randn(8,nRx) + i*randn(8,nRx)); %Dimension (Blocksize , nRx)
H=(randn(nTx,nRx) + i*randn(nTx,nRx))/sqrt(2); %Channel Gain Matrix
rx=G4*H + noise;
%Modification due to symbol uncertainty
%dBdec = 10^(25/10); %25 dB
%H = H + sqrt(nTx*Eav/(2*dBdec))*(randn(nTx,nRx) + i*randn(nTx,nRx))/sqrt(2);
%Demodulate
S1=0; S2=0; S3=0; S4=0; Hnorm=0;
for j=1:nRx,
S1 = S1 + rx(1,j)*H(1,j)' + rx(2,j)*H(2,j)' + rx(3,j)*H(3,j)' + rx(4,j)*H(4,j)' ...
+rx(5,j)'*H(1,j) + rx(6,j)'*H(2,j) + rx(7,j)'*H(3,j) + rx(8,j)'*H(4,j);
S2 = S2 + rx(1,j)*H(2,j)' - rx(2,j)*H(1,j)' - rx(3,j)*H(4,j)' + rx(4,j)*H(3,j)' ...
+rx(5,j)'*H(2,j) - rx(6,j)'*H(1,j) - rx(7,j)'*H(4,j) + rx(8,j)'*H(3,j);
S3 = S3 + rx(1,j)*H(3,j)' + rx(2,j)*H(4,j)' - rx(3,j)*H(1,j)' - rx(4,j)*H(2,j)' ...
+rx(5,j)'*H(3,j) + rx(6,j)'*H(4,j) - rx(7,j)'*H(1,j) - rx(8,j)'*H(2,j);
S4 = S4 + rx(1,j)*H(4,j)' - rx(2,j)*H(3,j)' + rx(3,j)*H(2,j)' - rx(4,j)*H(1,j)' ...
+rx(5,j)'*H(4,j) - rx(6,j)'*H(3,j) + rx(7,j)'*H(2,j) - rx(8,j)'*H(1,j);
Hnorm = Hnorm + H(:,j)'*H(:,j);
end
for L=1:Mary
Con = (-1 + 2*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);
%For s3
est_s3(L)= real( (S3 - Smap(L))*(S3 - Smap(L))' + Con);
%For s4
est_s4(L)= real( (S4 - Smap(L))*(S4 - 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
[A,B]=min(est_s3);
shat(k+2)=B-1; %-1 b/c index starts at 0 and not 1
[A,B]=min(est_s4);
shat(k+3)=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 + -