0
0
SimulinkHow-ToBeginner · 4 min read

How to Simulate OFDM in Simulink: Step-by-Step Guide

To simulate OFDM in Simulink, use blocks like OFDM Modulator and OFDM Demodulator from the Communications Toolbox. Connect these with source, channel, and sink blocks to model transmission and reception, then run the simulation to analyze performance.
📐

Syntax

The basic setup for OFDM simulation in Simulink involves these key blocks:

  • OFDM Modulator: Converts input bits into OFDM symbols.
  • Channel: Models the transmission medium (e.g., AWGN, fading).
  • OFDM Demodulator: Converts received OFDM symbols back to bits.
  • Source and Sink: Generate input data and collect output data.

Connect these blocks in sequence to simulate the OFDM system.

matlab
OFDM_Modulator = comm.OFDMModulator('FFTLength',64,'NumGuardBandCarriers',[6;5],'InsertDCNull',true);
Channel = comm.AWGNChannel('NoiseMethod','Signal to noise ratio (SNR)','SNR',20);
OFDM_Demodulator = comm.OFDMDemodulator('FFTLength',64,'NumGuardBandCarriers',[6;5],'RemoveDCCarrier',true);

% Example data generation
data = randi([0 1], OFDM_Modulator.NumDataSubcarriers*2, 1); % QPSK bits

% Modulate
modSignal = OFDM_Modulator(data);

% Pass through channel
rxSignal = Channel(modSignal);

% Demodulate
receivedData = OFDM_Demodulator(rxSignal);
💻

Example

This example shows a simple OFDM simulation in Simulink using MATLAB Function blocks to create an OFDM transmitter and receiver with AWGN channel noise.

matlab
% Parameters
FFTLength = 64;
NumGuardBandCarriers = [6;5];
InsertDCNull = true;
SNR = 15; % Signal to noise ratio in dB

% Create OFDM modulator and demodulator
ofdmMod = comm.OFDMModulator('FFTLength',FFTLength,'NumGuardBandCarriers',NumGuardBandCarriers,'InsertDCNull',InsertDCNull);
ofdmDemod = comm.OFDMDemodulator('FFTLength',FFTLength,'NumGuardBandCarriers',NumGuardBandCarriers,'RemoveDCCarrier',InsertDCNull);

% Generate random bits
numBits = ofdmMod.NumDataSubcarriers * 2; % QPSK bits
dataIn = randi([0 1], numBits, 1);

% Modulate
modSignal = ofdmMod(dataIn);

% Add AWGN noise
channel = comm.AWGNChannel('NoiseMethod','Signal to noise ratio (SNR)','SNR',SNR);
rxSignal = channel(modSignal);

% Demodulate
dataOut = ofdmDemod(rxSignal);

% Calculate bit errors
numErrors = sum(dataIn ~= dataOut);
fprintf('Number of bit errors: %d\n', numErrors);
Output
Number of bit errors: 0
⚠️

Common Pitfalls

  • Mismatched Parameters: Ensure FFTLength, guard bands, and DC null settings match between modulator and demodulator.
  • Incorrect Data Size: Input data length must match the number of data subcarriers times bits per symbol.
  • Channel Model: Using no or unrealistic channel models can give misleading results.
  • Ignoring Synchronization: Real OFDM systems require timing and frequency synchronization which Simulink models may omit.
matlab
% Wrong: Mismatched FFT length
ofdmModWrong = comm.OFDMModulator('FFTLength',64);
ofdmDemodWrong = comm.OFDMDemodulator('FFTLength',32); % Different FFT length

% Right: Matching FFT length
ofdmModRight = comm.OFDMModulator('FFTLength',64);
ofdmDemodRight = comm.OFDMDemodulator('FFTLength',64);
📊

Quick Reference

Key tips for OFDM simulation in Simulink:

  • Use comm.OFDMModulator and comm.OFDMDemodulator blocks for easy setup.
  • Match all parameters between modulator and demodulator.
  • Model the channel realistically (AWGN, fading).
  • Check input data size matches subcarriers and modulation scheme.
  • Use scopes or error rate calculators to analyze results.

Key Takeaways

Use the OFDM Modulator and Demodulator blocks from the Communications Toolbox for simulation.
Ensure all parameters like FFT length and guard bands match between transmitter and receiver.
Model the channel realistically to get meaningful simulation results.
Input data size must match the number of data subcarriers and modulation scheme.
Check results with error calculations or visualization blocks in Simulink.