# Strange bug with simulation of comparison of 1T1R, Beamforming(2T1R), STBC(2T1R)

Status
Not open for further replies.

#### a00achild1

##### Newbie level 1
Hello,

I'm trying to make a Matlab simulation about the comparison of 1T1R, Beamforming(2T1R), and STBC(2T1R) under Rayleigh fading channel, but something strange happend.
Below is my code. When I comment the first part of my code(1T1R), the results of the others is good, but when I uncomment the first part, the BER of the other two became 1! Could anyone help me with the strange bug? Thanks a lot.

Code:
%% 1T1R/ BF/ STBC Comparison
clear;clc;
SNRdB = 1:1:30;
SNR = 10.^(SNRdB/10);
N = 1e3;                % number of symbols
BER_1T1R = zeros(1,length(SNRdB));
BER_BF = zeros(1,length(SNRdB));
BER_STBC = zeros(1,length(SNRdB));

%% 1T1R
fprintf('1T1R\n');
for k = 1:length(SNR)
x = (2*floor(2*rand(1,N)))-1;          % -1/1
x = sqrt(SNR(k))*x;
H = randn(1,N) + randn(1,N)*1i;          % Rayleigh Channel
y = [];
for i = 1:N
y = [y x(i)+(1/sqrt(2))*(randn + randn*1i)/H(i)]; % Received signal
end
BER_1T1R(k) = length(find((real(y).*real(x))<0));
end
BER_1T1R = BER_1T1R/N;
semilogy(SNRdB,BER_1T1R,'k-<');
hold on
x=[];H=[];y=[];

%% BF
fprintf('BF\n');
for k = 1:length(SNR)
x = (2*floor(2*rand(2,N)))-1;          % -1/1
x = sqrt(SNR(k))*x;
H = randn(2,N) + randn(2,N)*1i;          % Rayleigh Channel
y = [];
for l = 1:N
y = [y x(:,l)+inv(H(:,l)'*H(:,l))*(1/sqrt(2))*(randn(2,1) + randn(2,1)*i)];
end
BER_BF(k) = length(find((real(y).*real(x))<0));
end
BER_BF = BER_BF/N;
semilogy(SNRdB,BER_BF,'r-o');
hold on

%% STBC
fprintf('STBC\n');
for k = 1:length(SNR)
x = (2*floor(2*rand(2,N)))-1;          % -1/1
x = sqrt(SNR(k))*x;
H = randn(2,N) + randn(2,N)*1i;          % Rayleigh Channel
y = [];
for l = 1:N
h = [H(:,l)' ; conj(H(2,l)) -conj(H(1,l))];
w = [sqrt(1/2)*(randn+randn*i); sqrt(1/2)*(randn+randn*i)];
y = [y x(:,l)+inv(h'*h)*h'*w];
end
BER_STBC(k) = length(find((real(y).*real(x))<0));
end
BER_STBC = BER_STBC/N;
semilogy(SNRdB,BER_STBC,'g-*');
legend('1T1R','BF','STBC');
grid on;

Status
Not open for further replies.