MATLAB Code for Zero-Forcing (ZF) Beamforming in 4×4 MIMO Systems
clc; clear; close all;
%% Parameters
Nt = 4; % Transmit antennas
Nr = 4; % Receive antennas (must be >= Nt for ZFBF)
numBits = 1e4; % Number of bits per stream
SNRdB = 0; % SNR in dB
numRuns = 100; % Number of independent runs for averaging
%% Precompute noise standard deviation
noiseSigma = 10^(-SNRdB / 20);
%% Accumulator for total errors
totalErrors = 0;
for run = 1:numRuns
% Generate random bits: [4 x 10000]
bits = randi([0 1], Nt, numBits);
% BPSK modulation: 0 → +1, 1 → -1
txSymbols = 1 - 2 * bits;
% Rayleigh channel matrix: [4 x 4]
H = (randn(Nr, Nt) + 1j * randn(Nr, Nt)) / sqrt(2);
%% === Zero Forcing Beamforming at Transmitter ===
W_zf = pinv(H); % Precoding matrix: [Nt x Nr]
txPrecoded = W_zf * txSymbols; % Apply ZF precoding
% Normalize transmit power (optional but useful)
txPrecoded = txPrecoded / sqrt(mean(abs(txPrecoded(:)).^2));
%% Channel transmission with AWGN
noise = noiseSigma * (randn(Nr, numBits) + 1j * randn(Nr, numBits)) / sqrt(2);
y = H * txPrecoded + noise; % Received signal: y = H * W_zf * x + n
%% Receiver directly demodulates (ideally H*W_zf ≈ I)
rxBits = real(y) < 0;
% Count bit errors
totalErrors = totalErrors + sum(rxBits(:) ~= bits(:));
end
%% Final BER
BER = totalErrors / (Nt * numBits * numRuns);
fprintf('Average BER over %d runs for 4x4 MIMO ZF Beamforming at %d dB SNR: %.5f\n', numRuns, SNRdB, BER);
Output
Average BER over 100 runs for 4x4 MIMO ZF Beamforming at 0 dB SNR: 0.16115
Mathematical Concept of Zero-Forcing (ZF)
In a MIMO (Multiple-Input Multiple-Output) system, the received signal is represented as y = Hx + n. The goal of Zero-Forcing Beamforming is to eliminate Inter-Stream Interference (ISI) by applying a weight matrix W at the transmitter.
The ZF Condition: The precoding matrix W is designed such that HW = I (the Identity Matrix).
This is achieved using the Moore-Penrose Pseudo-inverse:
This is achieved using the Moore-Penrose Pseudo-inverse:
W = HH(HHH)-1
By applying this at the transmitter, the receiver "sees" independent parallel channels, making demodulation as simple as a BPSK decision.
Why is Zero-Forcing not always ideal?
While ZF completely eliminates interference, it suffers from Noise Enhancement at low SNR. For a more robust system, engineers use MMSE Beamforming, which balances interference cancellation with noise suppression.
Learn how to upgrade this code to MMSE →