Skip to main content

OFDM Waveform with MATLAB Code

 

In OFDM (Orthogonal Frequency Division Multiplexing), we transmit multiple orthogonal subcarriers simultaneously. Since the subcarriers are orthogonal, they do not interfere with each other, which is one of the main advantages of OFDM. Practically, OFDM converts a wideband signal into multiple narrowband orthogonal subcarriers.

For typical wireless communication, if the signal bandwidth (or symbol duration) exceeds the coherence bandwidth of the channel, the signal experiences frequency-selective fading. Fading distorts the signal, making it difficult to recover the original information. By using OFDM, we transmit the same wideband signal across multiple orthogonal narrowband subcarriers, reducing the effect of fading.

For example, if we want to transmit a signal of bandwidth 1024 kHz, we can divide it into N = 8 subcarriers. Each subcarrier is then spaced by:

Δf = Total Bandwidth N = 1024 8 kHz = 128 kHz

Let N be the number of subcarriers. The subcarrier frequencies are centered around zero and range from:

fk = k Δf, k = -N2, , N2-1

So for our example, the subcarrier frequencies are:

fk = { -512, -384, -256, -128, 0, 128, 256, 384 } kHz

By using OFDM with these orthogonal subcarriers, the communication system becomes robust to frequency-selective fading, and the overall wideband signal can be transmitted and recovered smoothly.

MATLAB Code for Theoretical OFDM Sinc Spectra (Orthogonal)

clc;
clear;
close all;
% Parameters
N = 8;
fs = 1024; % Sampling frequency
T = N/fs;
delta_f = fs/N;
f = linspace(-fs/2, fs/2, 1024);
figure;
hold on;
grid on;
for k = -N/2:N/2-1
fk = k * delta_f;
S = T * sinc(T*(f - fk));
plot(f, abs(S),'LineWidth',1.5);
end
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Theoretical OFDM Sinc Spectra (Orthogonal)');
 

 

 

MATLAB Code for Simulated OFDM Spectrum (Orthogonal Case)

clc;
clear;
close all;
% ===============================
% PARAMETERS
% ===============================
N = 8; % Number of subcarriers
fs = 1000; % Sampling frequency (Hz)
Nfft = 1024; % FFT size for smooth spectrum
Ts = 1/fs;
T = N/fs; % OFDM symbol duration (IMPORTANT)
delta_f = fs/N; % Subcarrier spacing (Fs/N)
fprintf('Subcarrier spacing = %.2f Hz\n', delta_f);
% ===============================
% TRANSMITTER
% ===============================
% Generate random QPSK data
data = randi([0 3],1,N);
symbols = exp(1j*pi/2*data); % QPSK mapping
% IFFT (Discrete OFDM generation)
ofdm_time = ifft(symbols, N);
% Time axis
t = (0:N-1)*Ts;
% ===============================
% SPECTRUM VISUALIZATION
% ===============================
OFDM_spectrum = fftshift(fft(ofdm_time, Nfft));
f_axis = linspace(-fs/2, fs/2, Nfft);
figure;
subplot(3,1,1)
stem(0:N-1, abs(symbols),'filled')
title('Transmitted QPSK Symbols (Frequency Domain)')
xlabel('Subcarrier Index')
ylabel('Magnitude')
grid on;
subplot(3,1,2)
plot(f_axis, abs(OFDM_spectrum)/max(abs(OFDM_spectrum)))
title('OFDM Spectrum (Orthogonal Case)')
xlabel('Frequency (Hz)')
ylabel('Normalized Magnitude')
grid on;
% ===============================
% RECEIVER (NO ICI)
% ===============================
received_symbols = fft(ofdm_time, N);
subplot(3,1,3)
stem(0:N-1, abs(received_symbols),'r','filled')
title('Recovered Symbols (Perfect Orthogonality)')
xlabel('Subcarrier Index')
ylabel('Magnitude')
grid on;
% ===============================
% PART 2: INTRODUCE FREQUENCY OFFSET (ICI)
% ===============================
freq_offset = 20; % 20 Hz frequency offset
ofdm_offset = ofdm_time .* exp(1j*2*pi*freq_offset*t);
received_ici = fft(ofdm_offset, N);
figure;
subplot(2,1,1)
stem(0:N-1, abs(received_symbols),'filled')
title('Recovered Symbols (No ICI)')
xlabel('Subcarrier Index')
ylabel('Magnitude')
grid on;
subplot(2,1,2)
stem(0:N-1, abs(received_ici),'r','filled')
title('Recovered Symbols With Frequency Offset (ICI Present)')
xlabel('Subcarrier Index')
ylabel('Magnitude')
grid on;
 

 

People are good at skipping over material they already know!

View Related Topics to







Contact Us

Name

Email *

Message *

Popular Posts

Theoretical BER vs SNR for binary ASK, FSK, and PSK with MATLAB Code + Simulator

📘 Overview & Theory 🧮 MATLAB Codes 📚 Further Reading Bit Error Rate (BER) Equations BER formulas for ASK, FSK, and PSK modulation schemes. ASK BER = 0.5 × erfc(0.5 × √SNR) FSK BER = 0.5 × erfc(√(SNR / 2)) PSK BER = 0.5 × erfc(√SNR) Theoretical BER vs SNR for Amplitude Shift Keying (ASK) The theoretical Bit Error Rate (BER) for binary ASK depends on how binary bits are mapped to signal amplitudes. For typical cases: If bits are mapped to 1 and -1, the BER is: BER = Q(√(2 × SNR)) If bits are mapped to 0 and 1, the BER becomes: BER = Q(√(SNR / 2)) Where: Q(x) is the Q-function: Q(x) = 0.5 × erfc(x / √2) SNR : Signal-to-Noise Ratio N₀ : Noise Power Spectral Density Understanding the Q-F...

Simulation of ASK, FSK, and PSK using MATLAB Simulink (with Online Simulator)

📘 Overview 🧮 How to use MATLAB Simulink 🧮 Simulation of ASK using MATLAB Simulink 🧮 Simulation of FSK using MATLAB Simulink 🧮 Simulation of PSK using MATLAB Simulink 🧮 Simulator for ASK, FSK, and PSK 🧮 Digital Signal Processing Simulator 📚 Further Reading ASK, FSK & PSK HomePage MATLAB Simulation Simulation of Amplitude Shift Keying (ASK) using MATLAB Simulink In Simulink, we pick different components/elements from MATLAB Simulink Library. Then we connect the components and perform a particular operation. Result A sine wave source, a pulse generator, a product block, a mux, and a scope are shown in the diagram above. The pulse generator generates the '1' and '0' bit sequences. Sine wave sources produce a specific amplitude and frequency. The scope displays the modulated signal as well as the original bit sequence created by the pulse generator. Mux i...

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...(MATLAB Code + Simulator)

Bit Error Rate (BER) & SNR Guide Analyze communication system performance with our interactive simulators and MATLAB tools. 📘 Theory 🧮 Simulators 💻 MATLAB Code 📚 Resources BER Definition SNR Formula BER Calculator MATLAB Comparison 📂 Explore M-ary QAM, PSK, and QPSK Topics ▼ 🧮 Constellation Simulator: M-ary QAM 🧮 Constellation Simulator: M-ary PSK 🧮 BER calculation for ASK, FSK, and PSK 🧮 Approaches to BER vs SNR What is Bit Error Rate (BER)? The BER indicates how many corrupted bits are received compared to the total number of bits sent. It is the primary figure of merit for a...

Power Spectral Density Calculation Using FFT in MATLAB

📘 📘 Overview 🧮 🧮 Steps to calculate 💻 🧮 MATLAB Codes 📚 📚 Further Reading Power spectral density (PSD) tells us how the power of a signal is distributed across different frequency components, whereas Fourier Magnitude gives you the amplitude (or strength) of each frequency component in the signal. Steps to calculate the PSD of a signal Firstly, calculate the fast Fourier transform (FFT) of a signal. Then, calculate the Fourier magnitude (absolute value) of the signal. Square the Fourier magnitude to get the power spectrum. To calculate the Power Spectral Density (PSD), divide the squared magnitude by the product of the sampling frequency (fs) and the total number of samples (N). Formula: PSD = |FFT|^2 / (fs * N) Sampling frequency (fs): The rate at which the continuous-time signal is sampled (in Hz). ...

Online Simulator for ASK, FSK, and PSK

Try our new Digital Signal Processing Simulator!   •   Interactive ASK, FSK, and BPSK tools updated for 2025. Start Now Interactive Modulation Simulators Visualize binary modulation techniques (ASK, FSK, BPSK) in real-time with adjustable carrier and sampling parameters. 📡 ASK Simulator 📶 FSK Simulator 🎚️ BPSK Simulator 📚 More Topics ASK Modulator FSK Modulator BPSK Modulator More Topics Simulator for Binary ASK Modulation Digital Message Bits Carrier Freq (Hz) Sampling Rate (...

MATLAB Code for Constellation Diagram of QAM configurations such as 4, 8, 16, 32, 64, 128, and 256-QAM

📘 Overview of QAM 🧮 4-QAM MATLAB 🧮 16-QAM MATLAB 🚀 Online Simulator 📂 Other Topics on Constellation Diagrams... ▼ 🧮 MATLAB Code for 4-QAM 🧮 MATLAB Code for 16-QAM 🧮 MATLAB Code for m-ary QAM 🧮 Simulator for m-ary PSK 🧮 Simulator for m-ary QAM 🧮 Overview of Energy per Bit (Eb / N0) 🧮 Simulator for ASK, FSK, and PSK Overview of QAM One of the best-performing modulation techniques is QAM [↗] . Here, we modulate the symbols by varying the carrier signal's amplitude and phase in response to the variation in the message signal (or voltage variation). So, we may say that QAM is a combination of phase and amplitude modulation. Additionally, it performs better than ASK or PSK [↗] . In fact, any constellation for any type of modulatio...

MATLAB Codes for Various types of beamforming | Beam Steering, Digital...

📘 How Beamforming Improves SNR 🧮 MATLAB Code 📚 Further Reading 📂 Other Topics on Beamforming in MATLAB ... MIMO / Massive MIMO Beamforming Techniques Beamforming Techniques MATLAB Codes for Beamforming... How Beamforming Improves SNR The mathematical [↗] and theoretical aspects of beamforming [↗] have already been covered. We'll talk about coding in MATLAB in this tutorial so that you may generate results for different beamforming approaches. Let's go right to the content of the article. In analog beamforming, certain codebooks are employed on the TX and RX sides to select the best beam pairs. Because of their beamforming gains, communication created through the strongest beams from both the TX and RX side enhances spectrum efficiency. Additionally, beamforming gain directly impacts SNR improvement. [Read more about Beamforming and How it improves SNR] Wireless...