📄 codeh3.m
字号:
function [err]=codeH3(index,snr,nsymb,Mary,modtype,nRx,err);
%Routine that preforms simulations based on QAM Mary modulation
%and using coding scheme H3.
nTx=3;
%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:3:nsymb,
Sv=msg(k:k+2); %vector of next three bits
%Make next block
F1=Sv(3)/sqrt(2);
F2=(-Sv(1) - Sv(1)' + Sv(2) - Sv(2)') / 2;
F3=(+Sv(2) + Sv(2)' + Sv(1) - Sv(1)') / 2;
H3 = [+Sv(1) Sv(2) F1;
-Sv(2)' Sv(1)' F1;
F1' F1' F2;
F1' -F1' F3];
noise=S*(randn(4,1) + i*randn(4,1)); %Get noise
H=(randn(nTx,1) + i*randn(nTx,1))/sqrt(2); %Channel Gain Matrix
rx= H3*H + noise;
%Demodulate
S1 = + rx(1)*H(1)' + rx(2)'*H(2) ...
+ (rx(4) - rx(3))*H(3)'/2 ...
- (rx(3) + rx(4))'*H(3)/2;
S2 = + rx(1)*H(2)' - rx(2)'*H(1) ...
+ (rx(4) + rx(3))*H(3)'/2 ...
+ (-rx(3) + rx(4))'*H(3)/2;
S3 = + (rx(1) + rx(2))*H(3)'/sqrt(2) ...
+ rx(3)'*(H(1) + H(2))/sqrt(2) ...
+ rx(4)'*(H(1) - H(2))/sqrt(2);
for L=1:Mary
Con = (-1 + H'*H) * 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);
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
end
%Compute symbol errors
err(index)=sum(shat~=symb');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -