Matlab code simulation of mimo2*2 ofdm with stbc

1 view (last 30 days)
Hello everybody, I am student in telecom, and I evolves on a subject bringing on the simulation of a mimo transmission chain (2*2) ofdm with stbc code. and i need help to write ecripts of simulation, so if someone has some programs wich can help me, please post theme here thnks ( sorry for my english)
  1 Comment
Rayhan
Rayhan on 10 Jun 2025
Edited: Walter Roberson on 10 Jun 2025
clc; clear; close all;
% Parameters
N = 64; % FFT size
cpLen = 16; % Cyclic prefix length
numSymbols = 1000; % Number of OFDM symbols
SNR_dB = 0:5:30; % SNR range in dB
% Modulation (QPSK)
mod_order = 4;
M = log2(mod_order);
data = randi([0 1], 2*N*numSymbols*M, 1);
dataSym = qammod(reshape(data, [], M)*2.^(M-1:-1:0).', mod_order, 'InputType', 'integer');
% STBC Alamouti Encoding
dataSym = reshape(dataSym, 2, []); % Pair symbols for STBC
x1 = dataSym(1,:);
x2 = dataSym(2,:);
s1 = x1; s2 = x2;
s3 = -conj(x2); s4 = conj(x1);
% IFFT for OFDM
s1_OFDM = ifft(reshape(s1, N, []), N);
s2_OFDM = ifft(reshape(s2, N, []), N);
s3_OFDM = ifft(reshape(s3, N, []), N);
s4_OFDM = ifft(reshape(s4, N, []), N);
% Add CP
s1_OFDM = [s1_OFDM(end-cpLen+1:end, :); s1_OFDM];
s2_OFDM = [s2_OFDM(end-cpLen+1:end, :); s2_OFDM];
s3_OFDM = [s3_OFDM(end-cpLen+1:end, :); s3_OFDM];
s4_OFDM = [s4_OFDM(end-cpLen+1:end, :); s4_OFDM];
% Transmit through Rayleigh Channel
BER = zeros(size(SNR_dB));
for snrIdx = 1:length(SNR_dB)
snr = 10^(SNR_dB(snrIdx)/10);
% Channel (flat fading per subcarrier)
h11 = (randn(1, size(s1,2)) + 1j*randn(1, size(s1,2))) / sqrt(2);
h12 = (randn(1, size(s1,2)) + 1j*randn(1, size(s1,2))) / sqrt(2);
h21 = (randn(1, size(s1,2)) + 1j*randn(1, size(s1,2))) / sqrt(2);
h22 = (randn(1, size(s1,2)) + 1j*randn(1, size(s1,2))) / sqrt(2);
% Transmit two time slots
y1 = h11 .* s1 + h12 .* s2;
y2 = h21 .* s1 + h22 .* s2;
y3 = h11 .* s3 + h12 .* s4;
y4 = h21 .* s3 + h22 .* s4;
% Noise
noise = @(x) x + sqrt(1/(2*snr))*(randn(size(x)) + 1j*randn(size(x)));
y1 = noise(y1); y2 = noise(y2);
y3 = noise(y3); y4 = noise(y4);
% Receiver: Alamouti decoding (per subcarrier)
r1 = conj(h11).*y1 + h12.*conj(y3);
r2 = conj(h21).*y2 + h22.*conj(y4);
r3 = conj(h12).*y1 - h11.*conj(y3);
r4 = conj(h22).*y2 - h21.*conj(y4);
s1_hat = r1 + r2;
s2_hat = r3 + r4;
% Combine
rxSym = [s1_hat; s2_hat];
rxSym = reshape(rxSym, [], 1);
% Demodulate
rxBits = de2bi(qamdemod(rxSym, mod_order, 'OutputType', 'integer'), M);
rxBits = reshape(rxBits.', [], 1);
% BER
BER(snrIdx) = mean(data ~= rxBits(1:length(data)));
end
% Plot
figure;
semilogy(SNR_dB, BER, '-o');
xlabel('SNR (dB)'); ylabel('Bit Error Rate');
title('2x2 MIMO-OFDM STBC (QPSK)');
grid on;

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!