- http://spacetimecodes.blogspot.com/p/alamouti-code.html
- https://in.mathworks.com/help/matlab/ref/pinv.html?searchHighlight=pinv&s_tid=srchtitle_support_results_1_pinv
Correcting the error in Alamouti code (2 x 1)
16 views (last 30 days)
Show older comments
I trying to code Alamouti code for BPSK in Rayleigh fading channel for BER simulation.There is a matrix dimention mismatch in decode section.I tried to correct it ,but it did not work.
Need your help to correct it.Thank you
clear all;
close all;
clc;
Ps = 1;%Transmit power
N = 10^6; % number of bits or symbols
NR = 1;
num_runs = 10;
snr_dB = -3:10 ; % in dB
rand('seed',1); % initializing the rand() function so that random bits produced are same in every simulation
randn('seed',1);
% Transmitter
x_data1 = rand(1,N/2)>0.5;
x_data2 = rand(1,N/2)>0.5;
binaryData = [x_data1; x_data2];
BPSK_data1 = 2*x_data1 - 1;
BPSK_data2 = 2*x_data2 - 1;
% BPSK modulation - 2x500000 matrix
BPSK_data =[BPSK_data1; BPSK_data2];
n1 = AWGN(1);
n2 = AWGN(1);
h1 = Rayleigh(1);
h2 = Rayleigh(1);
SNR = 10.^(snr_dB/10);
Noise_power = zeros(1,length(snr_dB));
for k = 1:length(snr_dB)
% Add complex AWGN noise power
Noise_power = Ps./SNR(k);
% In the first time slot, the received signal
y1 = h1.*BPSK_data1 + h2.*BPSK_data2 + n1;
% In the first time slot, the received signal
y2 = h1.*(-conj(BPSK_data2)) + h2.*(conj(BPSK_data1)) + n2;
%Rayleigh fading channel - 2x1 matrix
H = [h1 h2 ; conj(h2) -conj(h1)];
%Decode the sysmbols - ZF decoder
x1_hat = pinv(H).*y1;
x2_hat = pinv(H).*conj(y2);
rx_bits = [x1_hat;x2_hat];
rx_bits = real(rx_bits) > 0;
% Count errors
nErr(k) = size(find(binaryData - rx_bits),1);
end
% counting the errors
ber = nErr/N; % simulated ber
figure(1);
semilogy(snr_dB,ber,'b.-');
% axis([0 10 10^-4 0.6])
grid on;
legend( 'MIMO - BER');
xlabel('SNR[dB]');
ylabel('Bit Error Rate');
title('BER for MIMO-BPSK');
%%%%% AWGN noise %%%%%
function n = AWGN(N)
n = rand(1,N);
end
%%%%% Rayleigh channel %%%%%%
function h = Rayleigh(N);
x = sqrt(1/2).*rand(1,N);
y = sqrt(1/2).*rand(1,N);
h = abs(x + i*y);
end
0 Comments
Answers (1)
Shashi Kiran
on 31 Jul 2024
Hi Kasun,
I see that you are implementing the Alamouti code and generating the BER curve.
I have made a few adjustments to the code to ensure it works as expected. One key point is that the noise should be complex since we are dealing with complex baseband signals.
Also, while decoding using Zero Forcing decoder, I have used the below calculations for simplicity.
On solving the equation, it can be minimized to:
% Decode the symbols - Alamouti scheme
x_hat1 = conj(h1).*y1 + h2.*conj(y2);
x_hat2 = conj(h2).*y1 - h1.*conj(y2);
% Normalize by the channel power
h_power = abs(h1).^2 + abs(h2).^2;
x_hat1 = x_hat1 ./ h_power;
x_hat2 = x_hat2 ./ h_power;
Here is the updated version of the code with the changes made .
clear all;
close all;
clc;
Ps = 1; % Transmit power
N = 10^6; % Number of bits or symbols
snr_dB = -8:18; % in dB
rand('seed',1); % Initializing the rand() function so that random bits produced are the same in every simulation
randn('seed',1);
% Transmitter
x_data1 = rand(1,N/2) > 0.5;
x_data2 = rand(1,N/2) > 0.5;
binaryData = [x_data1; x_data2];
BPSK_data1 = 2*x_data1 - 1;
BPSK_data2 = 2*x_data2 - 1;
% BPSK modulation - 2x500000 matrix
BPSK_data = [BPSK_data1; BPSK_data2];
SNR = 10.^(snr_dB/10);
Noise_power = zeros(1,length(snr_dB));
nErr = zeros(1,length(snr_dB)); % Initialize the error count array
for k = 1:length(snr_dB)
% Add complex AWGN noise power
% disp(k)
Noise_power(k) = Ps./SNR(k);
% Generate noise
n1 = sqrt(Noise_power(k)/2) * AWGN(N/2);
n2 = sqrt(Noise_power(k)/2) * AWGN(N/2);
% Generate Rayleigh fading channel coefficients
h1 = Rayleigh(N/2);
h2 = Rayleigh(N/2);
% In the first time slot, the received signal
y1 = h1.*BPSK_data1 + h2.*BPSK_data2 + n1;
% In the second time slot, the received signal
y2 = h1.*(-conj(BPSK_data2)) + h2.*(conj(BPSK_data1)) + n2;
% Decode the symbols - Alamouti scheme
x_hat1 = conj(h1).*y1 + h2.*conj(y2);
x_hat2 = conj(h2).*y1 - h1.*conj(y2);
% Normalize by the channel power
h_power = abs(h1).^2 + abs(h2).^2;
x_hat1 = x_hat1 ./ h_power;
x_hat2 = x_hat2 ./ h_power;
rx_bits1 = real(x_hat1) > 0;
rx_bits2 = real(x_hat2) > 0;
rx_bits = [rx_bits1; rx_bits2];
% Count errors
nErr(k) = sum(sum(binaryData ~= rx_bits));
end
% Calculate BER
ber = nErr/N; % Simulated BER
%%%%% AWGN noise %%%%%
function n = AWGN(N)
n = randn(1, N) + 1i*randn(1, N);
end
%%%%% Rayleigh channel %%%%%%
function h = Rayleigh(N)
x = sqrt(1/2) * randn(1, N);
y = sqrt(1/2) * randn(1, N);
h = x + 1i*y;
end
% Plot results
semilogy(snr_dB, ber, 'b.-');
grid on;
legend('MIMO - BER');
xlabel('SNR [dB]');
ylabel('Bit Error Rate');
title('BER for MIMO-BPSK with Alamouti Scheme');
Refer below for the working of Alamouti code.
Hope this solves your query.
0 Comments
See Also
Categories
Find more on Link-Level Simulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!