單入單出SISO系統(tǒng):- clear all;
- close all;
- clc;
- M = 1000;
- Nt = [1]; % Nt = [2]; Nt = [4]; Nt = [8];
- Nr = [1];
- s={'b-hexagram'};
- SNR = [0:2:50]; %dB
- figure(1);
- title('單入單出系統(tǒng)');
- xlabel('SNR [dB]');
- ylabel('CU');
- grid on;
- hold on;
- for n = 1:length(Nt)
- t = Nt(n);
- r = Nr(n);
- for m = 1:M
- H = raylrnd(1,r,t);
- for l = 1:length(SNR)
- rou = 10^(SNR(l)/10);
- % Find the capacity while CSIT unknown
- CU(m,l) = log2(real(det(eye(r)+rou*H*H'/t)));
- end
- end
- C_unknown(:,n) = mean(CU)'
- for l = 1:length(SNR)
- [cdf_u,co_u] = hist(CU(:,l),100);
- cdf_u = cumsum(cdf_u);%數(shù)組累加
- idx_ten_percent = find(abs(cdf_u-100)==min(abs(cdf_u-100)));
- C_unknown_outage(l,n) = co_u(idx_ten_percent(1));
- end
- figure(1);
- linetype = s(n);
- plot(SNR,C_unknown(:,n),deal(linetype{:}));
- legend('Mt=1');
- end
復(fù)制代碼
二發(fā)單收系統(tǒng): 四發(fā)單收系統(tǒng): 八發(fā)單收系統(tǒng): 多發(fā)多收和單發(fā)單收系統(tǒng)比較: - clear all;
- close all;
- clc;
- M = 1000;
- Nt = [1,2,4,8];
- Nr = [1,2,4,8];
- s={'b-o','b-*','b-square','b-hexagram'};
- SNR = [0:2:50]; %dB
- figure(1);
- title('多發(fā)多收和單發(fā)單收系統(tǒng)比較')
- xlabel('SNR [dB]');
- ylabel('CU');
- grid on;
- hold on;
- for n = 1:length(Nt)
- t = Nt(n);
- r = Nr(n);
- for m = 1:M
- H = raylrnd(1,r,t);
- for l = 1:length(SNR)
- rou = 10^(SNR(l)/10);
- % Find the capacity while CSIT unknown
- CU(m,l) = log2(real(det(eye(r)+rou*H*H'/t)));
- end
- end
- C_unknown(:,n) = mean(CU)';
- for l = 1:length(SNR)
- [cdf_u,co_u] = hist(CU(:,l),100);
- cdf_u = cumsum(cdf_u);%數(shù)組各行累加
- idx_ten_percent = find(abs(cdf_u-100)==min(abs(cdf_u-100)));
- C_unknown_outage(l,n) = co_u(idx_ten_percent(1));
- end
- figure(1);
- linetype = s(n);
- plot(SNR,C_unknown(:,n),deal(linetype{:}));
- legend('Mt=1','Mt=2','Mt=4','Mt=8');
- end
復(fù)制代碼
STBC編碼原理:
x及其共軛的線性組合。一個編碼碼字共有P個時刻,并按行由N副天線同時發(fā)送,即在第一個時刻發(fā)送第一行,第二個時刻發(fā)送第二行,依此類推。在第t個時刻發(fā)送第t行,總共需P個時刻才可完成一個編碼碼字的發(fā)送。因此,矩陣的每一列符號實際是由同一副發(fā)送天線在不同時刻發(fā)送的。
Clear
N = 10^6; % number of bits or symbols
Eb_N0_dB = [0:25]; % multiple Eb/N0 values多個信噪比,信號傳輸?shù)乃ト醭潭炔灰?/font>
nRx = 2;%接收天線的個數(shù)為2
for ii = 1:length(Eb_N0_dB)%信噪比的個數(shù)有多少,就做多少次循環(huán)
% Transmitter發(fā)射機
ip = rand(1,N)>0.5; % generating 0,1 with equal probability(rand產(chǎn)生一個1行N列的隨機數(shù))后面的">0.5"的意思是指當隨機取得的數(shù)大于0.5時,那個數(shù)直接變?yōu)橐唬斝∮?.5時為0
s = 2*ip-1; % BPSK 調(diào)制 0 -> -1; 1 -> 0(另外的一種調(diào)試方法,估計是仿真的時候用來對比的)
% Alamouti STBC sCode = 1/sqrt(2)*kron(reshape(s,2,N/2),ones(1,2)) ;%kron(A,B)是求矩陣A和矩陣B的乘積
reshape(s,2,N/2)是將s矩陣改成2行,N/2列的矩陣;ones(1,2)生成一個1行2列的全1矩陣
% channel h = 1/sqrt(2)*[randn(nRx,N) + 1i*randn(nRx,N)]; % Rayleigh channel (sqrt平方根)
n = 1/sqrt(2)*[randn(nRx,N) + 1i*randn(nRx,N)]; % white gaussian noise, 0dB variance
% y = zeros(nRx,N);
yMod = zeros(nRx*2,N);
hMod = zeros(nRx*2,N);
for kk = 1:nRx %從1一直循環(huán)到nRx
hMod = kron(reshape(h(kk,:),2,N/2),ones(1,2)); % repeating the same channel for two symbols (重復(fù)相同信道的兩個符號)
temp = hMod;
hMod(1,[2:2:end]) = conj(temp(2,[2:2:end]));
hMod(2,[2:2:end]) = -conj(temp(1,[2:2:end]));
% Channel and noise Noise addition y(kk,:) = sum(hMod.*sCode,1) + 10^(-Eb_N0_dB(ii)/20)*n(kk,:);
% Receiver yMod([2*kk-1:2*kk],:) = kron(reshape(y(kk,:),2,N/2),ones(1,2));
% forming the equalization matrix(形成均衡矩陣)
hEq([2*kk-1:2*kk],:) = hMod;
hEq(2*kk-1,[1:2:end]) = conj(hEq(2*kk-1,[1:2:end]));
hEq(2*kk, [2:2:end]) = conj(hEq(2*kk, [2:2:end]));
end
% equalization hEqPower = sum(hEq.*conj(hEq),1);
yHat = sum(hEq.*yMod,1)./hEqPower; % [h1*y1 + h2y2*, h2*y1 -h1y2*, ... ]
yHat(2:2:end) = conj(yHat(2:2:end));
% receiver - hard decision decoding
ipHat = real(yHat)>0;
% counting the errors
nErr(ii) = size(find([ip- ipHat]),2);
end
simBer = nErr/N; % simulated ber
EbN0Lin = 10.^(Eb_N0_dB/10);
theoryBer_nRx1 = 0.5.*(1-1*(1+1./EbN0Lin).^(-0.5));
p = 1/2 - 1/2*(1+1./EbN0Lin).^(-1/2);
theoryBerMRC_nRx2 = p.^2.*(1+2*(1-p));
pAlamouti = 1/2 - 1/2*(1+2./EbN0Lin).^(-1/2);
theoryBerAlamouti_nTx2_nRx1 = pAlamouti.^2.*(1+2*(1-pAlamouti));
close all
figure
semilogy(Eb_N0_dB,theoryBer_nRx1,'bp-','LineWidth',2); %semilogy:繪制半對數(shù)坐標圖形
hold on;
semilogy(Eb_N0_dB,theoryBerMRC_nRx2,'kd-','LineWidth',2);
semilogy(Eb_N0_dB,theoryBerAlamouti_nTx2_nRx1,'c+-','LineWidth',2);
semilogy(Eb_N0_dB,simBer,'mo-','LineWidth',2); axis([0 25 10^-5 0.5]);
grid on;
legend('theory (nTx=1,nRx=1)', 'theory (nTx=1,nRx=2, MRC)', 'theory (nTx=2, nRx=1, Alamouti)', 'sim (nTx=2, nRx=2, Alamouti)');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation with 2Tx, 2Rx Alamouti STBC (Rayleigh channel)');
|