clear all; Tx_n = 2; Rx_n = 2; %---------------SNR vector------------- SNRindB = 2:1:10; SNR = 10.^(SNRindB/10); %------------modulation----------------- L = 20000; BitPerSymbol = 2; s0 = randi(1,1,L); h_1 = pskmod('M',2^BitPerSymbol,'gray','InputType','Bit'); s = modulate(h_1,s0.').'; %-------------seperation-------------- s1 = zeros(Tx_n,length(s)); for ii = 1:Tx_n:(length(s)-1) %stbc s1(1,ii) = s(ii); s1(2,ii) = s(ii+1); s1(1,ii+1) = conj(s(ii+1)); s1(2,ii+1) = -conj(s(ii)); end L1 = length(s1(1,:)); %----------noise and channel-------------- S = zeros(2, 2); S1 = zeros(1, L1); rx = zeros(L, 1); BER = zeros(length(SNR), 1); SER = zeros(length(SNR), 1); for ii = 1:length(SNR) sigma = 1/(sqrt(2*SNR(ii))); for iii = 1:2:L1-1 noise = sigma*(randn(Rx_n,1)+1i*randn(Rx_n,1)); H = sqrt(0.5)*(randn(Rx_n, Tx_n) + 1i*randn(Rx_n, Tx_n)); %----------add noise------------------------ R1 = H*s1(:,iii)+noise; %接收信号1,Rx_n * 1 R2 = H*s1(:,iii+1)+noise; %接收信号2,Rx_n * 1 %----------receive MMSE------------------- hh = H(:,1).*conj(H(:,1)) + H(:,2).*conj(H(:,2)); S_t1 = conj(H(:,1)).*R1-H(:,2).*conj(R2); S_t2 = conj(H(:,2)).*R1+H(:,1).*conj(R2); S(:,1) = S_t1./hh; S(:,2) = S_t2./hh; for si = 1:1:Rx_n S1(1,iii) = S1(1,iii) + S(si,1); S1(1,iii+1) = S1(1,iii+1) + S(si,2); end S1(1,iii) = S1(1,iii)/Rx_n; S1(1,iii+1) = S1(1,iii+1)/Rx_n; end h_2 = modem.pskdemod('M', 2^BitPerSymbol,'SymbolOrder','gray', 'OutputType', 'Bit'); rx = demodulate(h_2,S1.'); remod = modulate(h_1, rx); %------------calculate ber--------------------------- SER(ii,:) = symerr(remod.',s)/L1; BER(ii,:) = biterr(rx.',s0)/L; end semilogy(SNRindB,BER,'g-^'); hold on; semilogy(SNRindB,SER,'m-^'); grid on; xlabel('SNR(dB)'); ylabel('BER'); title('STBC SNR-BER curve'); legend('BER 2x1','SER 2x1','BER 2x2','SER 2x2');代码有误,帮忙修改一下
时间: 2023-09-06 20:07:37 浏览: 122
WiMedia_MAC-PHY_Interface_1v2 R1.pdf
以下是修改后的代码,主要是将`pskmod`函数的参数传递方式改正、修正一些语法错误和变量名错误:
```matlab
clear all;
Tx_n = 2;
Rx_n = 2;
%---------------SNR vector-------------
SNRindB = 2:1:10;
SNR = 10.^(SNRindB/10);
%------------modulation-----------------
L = 20000;
BitPerSymbol = 2;
s0 = randi([0 1],1,L);
h_1 = pskmod(s0,2^BitPerSymbol,pi/4,'gray');
%-------------seperation--------------
s1 = zeros(Tx_n,length(h_1));
for ii = 1:Tx_n:(length(h_1)-1)
%stbc
s1(1,ii) = h_1(ii);
s1(2,ii) = h_1(ii+1);
s1(1,ii+1) = -conj(h_1(ii+1));
s1(2,ii+1) = conj(h_1(ii));
end
L1 = length(s1(1,:));
%----------noise and channel--------------
S = zeros(2, 2);
S1 = zeros(1, L1);
rx = zeros(L, 1);
BER = zeros(length(SNR), 1);
SER = zeros(length(SNR), 1);
for ii = 1:length(SNR)
sigma = 1/(sqrt(2*SNR(ii)));
for iii = 1:2:L1-1
noise = sigma*(randn(Rx_n,1)+1i*randn(Rx_n,1));
H = sqrt(0.5)*(randn(Rx_n, Tx_n) + 1i*randn(Rx_n, Tx_n));
%----------add noise------------------------
R1 = H*s1(:,iii)+noise; %接收信号1,Rx_n * 1
R2 = H*s1(:,iii+1)+noise; %接收信号2,Rx_n * 1
%----------receive MMSE-------------------
hh = H(:,1).*conj(H(:,1)) + H(:,2).*conj(H(:,2));
S_t1 = conj(H(:,1)).*R1-H(:,2).*conj(R2);
S_t2 = conj(H(:,2)).*R1+H(:,1).*conj(R2);
S(:,1) = S_t1./hh;
S(:,2) = S_t2./hh;
for si = 1:1:Rx_n
S1(1,iii) = S1(1,iii) + S(si,1);
S1(1,iii+1) = S1(1,iii+1) + S(si,2);
end
S1(1,iii) = S1(1,iii)/Rx_n;
S1(1,iii+1) = S1(1,iii+1)/Rx_n;
end
h_2 = modem.pskdemod('M',2^BitPerSymbol,'SymbolOrder','gray', 'OutputType', 'Bit');
rx = demodulate(h_2,S1.');
remod = pskmod(rx,2^BitPerSymbol,pi/4,'gray');
%------------calculate ber---------------------------
SER(ii,:) = symerr(remod.',h_1)/L1;
BER(ii,:) = biterr(rx.',s0)/L;
end
semilogy(SNRindB,BER,'g-^');
hold on;
semilogy(SNRindB,SER,'m-^');
grid on;
xlabel('SNR(dB)');
ylabel('BER');
title('STBC SNR-BER curve');
legend('BER 2x1','SER 2x1','BER 2x2','SER 2x2');
```
修正后的代码应该可以正常运行并绘制出STBC的SNR-BER曲线。
阅读全文