The code below is an example of 2 X 2 MIMO.
MATLAB Code
clc;clear all;
close all;
% MIMO System Parameters
numTx = 2; % Number of transmit antennas
numRx = 2; % Number of receive antennas
numSymbols = 50; % Number of symbols to transmit
% Generate random binary data
data = randi([0, 1], numTx, numSymbols);
% PSK Modulation (BPSK)
modulatedSymbols = 1 - 2 * data; % BPSK modulation: '0' maps to +1, '1' maps to -1
% Precoding (Identity Matrix for demonstration)
precodingMatrix = eye(numTx);
% Transmit Signal
transmitSignal = precodingMatrix * modulatedSymbols;
% Channel (Rayleigh Fading Channel)
H = (randn(numRx, numTx) + 1i * randn(numRx, numTx)) / sqrt(2); % Rayleigh fading channel
% Received Signal
receivedSignal = H * transmitSignal;
% Demodulation
demodulatedSymbols = H' * receivedSignal;
% PSK Demodulation (BPSK)
receivedData = demodulatedSymbols < 0; % Decision threshold at 0
Output
Fig 1: Original Message Bits
Fig 2: Received Message Bits