Skip to main content

MATLAB Code for OTFS (Orthogonal Time Frequency Space)


MATLAB Code for OTFS (Orthogonal Time Frequency Space)

%% Clear workspace
clc; clear; close all;
%% Step 1: OTFS Parameters
N_delay = 4; % Number of delay bins (rows)
N_doppler = 4; % Number of Doppler bins (columns)
N_sym = N_delay * N_doppler;
modOrder = 4; % QPSK
SNR_dB = 20; % Noise level
%% Step 2: Generate random data symbols
data = randi([0 modOrder-1], N_sym, 1);
txSymbols = pskmod(data, modOrder, pi/4);
disp('Transmitted Delay-Doppler symbols:');
disp(reshape(txSymbols, N_delay, N_doppler));
%% Step 3: Map Delay-Doppler → Time-Frequency (ISFFT)
% ISFFT: Inverse Symplectic Finite Fourier Transform
% 1. Take IDFT along Doppler (columns)
% 2. Take DFT along Delay (rows)
ddSymbols = reshape(txSymbols, N_delay, N_doppler);
% Step 3a: IDFT along columns (Doppler)
tfGrid = ifft(ddSymbols, N_doppler, 2);
%IFFT (accross columns) along Doppler → spreads in time (Delay → Time)
%FFT (accross rows)along Delay → spreads in frequency (Delay → Frequency)
% Step 3b: DFT along rows (Delay)
tfGrid = fft(tfGrid, N_delay, 1);
disp('Time-Frequency Grid (TF domain):');
disp(tfGrid);
%% Step 4: Serialize TF grid for transmission
txSerial = tfGrid(:); % Column-wise flatten
disp('Serial transmission stream:');
disp(txSerial);
%% Step 5: Channel Model
% Flat fading for simplicity
h = (randn(size(txSerial)) + 1j*randn(size(txSerial)))/sqrt(2);
rxSerial = txSerial .* h; % Apply channel
rxSerial = awgn(rxSerial, SNR_dB, 'measured'); % Add noise
%% Step 6: Reshape back into TF grid
rxTFGrid = reshape(rxSerial, N_delay, N_doppler);
hTFGrid = reshape(h, N_delay, N_doppler); % Channel coefficients per tile
%% Step 7: Equalization in TF domain
eqTFGrid = rxTFGrid ./ hTFGrid; % Simple one-tap per TF tile
%% Step 8: Map TF → Delay-Doppler (SFFT)
% SFFT: Symplectic Fourier Transform (inverse of ISFFT)
% 1. IDFT along Delay (rows)
% 2. DFT along Doppler (columns)
rxDD = ifft(eqTFGrid, N_delay, 1); % IDFT along rows
rxDD = fft(rxDD, N_doppler, 2); % DFT along columns
%% Step 9: Flatten and demap symbols
rxSymbols = rxDD(:);
rxData = pskdemod(rxSymbols, modOrder, pi/4);
%% Step 10: Display results
disp('Recovered Delay-Doppler symbols:');
disp(reshape(rxSymbols, N_delay, N_doppler));
numErrors = sum(data ~= rxData);
fprintf('Symbol errors: %d out of %d\n', numErrors, N_sym);
%% Optional: Plot constellations
figure;
subplot(1,2,1); plot(txSymbols,'o'); title('Transmitted Symbols'); grid on; axis equal;
subplot(1,2,2); plot(rxSymbols,'o'); title('Received Symbols'); grid on; axis equal;
web('https://www.salimwireless.com/search?q=otfs%20ofdm', '-browser');


Output

 Transmitted Delay-Doppler symbols:
  -0.7071 - 0.7071i  -0.7071 + 0.7071i  -0.7071 + 0.7071i  -0.7071 + 0.7071i
  -0.7071 + 0.7071i  -0.7071 - 0.7071i  -0.7071 - 0.7071i  -0.7071 - 0.7071i
  -0.7071 - 0.7071i   0.7071 + 0.7071i   0.7071 + 0.7071i  -0.7071 - 0.7071i
  -0.7071 - 0.7071i   0.7071 - 0.7071i  -0.7071 - 0.7071i   0.7071 + 0.7071i

Time-Frequency Grid (TF domain):
  -1.4142 - 0.3536i  -0.3536 + 0.0000i  -0.7071 - 0.3536i  -0.3536 - 0.7071i
  -0.7071 + 1.0607i   1.0607 - 0.0000i   0.7071 - 1.0607i   0.3536 + 0.0000i
   0.0000 + 1.0607i  -1.0607 - 0.7071i   0.7071 - 0.3536i   0.3536 - 1.4142i
  -0.7071 - 0.3536i   0.3536 - 0.7071i  -0.7071 + 0.3536i  -0.3536 + 0.7071i

Serial transmission stream:
  -1.4142 - 0.3536i
  -0.7071 + 1.0607i
   0.0000 + 1.0607i
  -0.7071 - 0.3536i
  -0.3536 + 0.0000i
   1.0607 - 0.0000i
  -1.0607 - 0.7071i
   0.3536 - 0.7071i
  -0.7071 - 0.3536i
   0.7071 - 1.0607i
   0.7071 - 0.3536i
  -0.7071 + 0.3536i
  -0.3536 - 0.7071i
   0.3536 + 0.0000i
   0.3536 - 1.4142i
  -0.3536 + 0.7071i

Recovered Delay-Doppler symbols:
  -0.6366 - 0.6820i  -0.7347 + 0.6199i  -0.7577 + 0.7180i  -0.5586 + 0.8659i
  -0.6824 + 0.8404i  -0.6304 - 0.9573i  -0.5014 - 0.4702i  -0.8630 - 0.8956i
  -0.7453 - 1.0323i   0.6771 + 1.0969i   0.6840 + 0.4994i  -0.5991 - 0.5179i
  -0.8816 - 0.4403i   0.7372 - 0.7281i  -0.7871 - 0.7687i   0.5789 + 0.7468i

Symbol errors: 0 out of 16

 

Plot BER vs SNR for OTFS using MATLAB

%% Clear workspace
clc; clear; close all;
%% Step 1: OTFS Parameters
N_delay = 4;
N_doppler = 4;
N_sym = N_delay * N_doppler;
modOrder = 4;
M_bits = log2(modOrder);
% --- NEW: SNR Range and Storage ---
SNR_vec = 0:2:16; % Range of SNR values to test
numFrames = 100; % Number of iterations per SNR for smooth curve
BER = zeros(size(SNR_vec));
%% --- NEW: SNR Loop ---
for i = 1:length(SNR_vec)
SNR_dB = SNR_vec(i);
totalBitErrors = 0;
for f = 1:numFrames
%% Step 2: Generate random data bits (Changed to bits for BER)
txBits = randi([0 1], N_sym * M_bits, 1);
txSymbols = pskmod(txBits, modOrder, pi/4, 'InputType', 'bit');
%% Step 3: Map Delay-Doppler → Time-Frequency (ISFFT)
ddSymbols = reshape(txSymbols, N_delay, N_doppler);
tfGrid = ifft(ddSymbols, N_doppler, 2);
tfGrid = fft(tfGrid, N_delay, 1);
%% Step 4: Serialize TF grid
txSerial = tfGrid(:);
%% Step 5: Channel Model
h = ones(size(txSerial)); %(randn(size(txSerial)) + 1j*randn(size(txSerial)))/sqrt(2);
rxSerial = txSerial .* h;
rxSerial = awgn(rxSerial, SNR_dB, 'measured');
%% Step 6: Reshape back into TF grid
rxTFGrid = reshape(rxSerial, N_delay, N_doppler);
hTFGrid = reshape(h, N_delay, N_doppler);
%% Step 7: Equalization in TF domain
eqTFGrid = rxTFGrid ./ hTFGrid;
%% Step 8: Map TF → Delay-Doppler (SFFT)
rxDD = ifft(eqTFGrid, N_delay, 1);
rxDD = fft(rxDD, N_doppler, 2);
%% Step 9: Flatten and demap symbols to bits
rxSymbols = rxDD(:);
rxBits = pskdemod(rxSymbols, modOrder, pi/4, 'OutputType', 'bit');
%% Step 10: Count Errors
totalBitErrors = totalBitErrors + sum(txBits ~= rxBits);
end
% Calculate average BER for this SNR
BER(i) = totalBitErrors / (N_sym * M_bits * numFrames);
fprintf('SNR: %d dB | BER: %e\n', SNR_dB, BER(i));
end
%% --- NEW: Plot Results ---
figure;
semilogy(SNR_vec, BER, 'b-o', 'LineWidth', 2);
grid on;
xlabel('SNR (dB)');
ylabel('Bit Error Rate (BER)');
title('OTFS BER vs SNR');

 Output

 



Contact Us

Name

Email *

Message *

Popular Posts

Hybrid Beamforming | Page 1

Beamforming Techniques Hybrid Beamforming... Page 1 | Page 2 | Hybrid Beamforming: Hybrid beam formation was developed to address some of the limitations of digital pre-coding approaches. Every antenna element is connected to an RF chain in digital pre-coding (beam forming) method. We also know that each RF chain is in charge of providing a separate data stream between the transmitter and the receiver. We know that a larger number of independent data streams leads to higher data rates. It has a spatial multiplexing feature for MIMO. As a result, we may assume that switching from MIMO to massive MIMO will benefit us more in terms of spatial multiplexing in massive MIMO, where each antenna is coupled to a single RF chain. We'll proceed with a definition of hybrid beam forming. Overview of hybrid beam forming with example: Unlike digital beam forming, more than one antenna element is connected to a single RF chain in hybr...

MATLAB Code for 8-PSK, 16-PSK, ...

📘 Overview & Theory 🧮 MATLAB Code for BPSK, QPSK, 8-PSK, 16-PSK, 32-PSK 🧮 Simulator for m-ary PSK 📚 Further Reading   MATLAB Code for BPSK, QPSK, 8-PSK, 16-PSK, 32-PSK clc; clear all; close all; rng(10) M = 8; % M = 2, 4, 8, 16, 32, etc. N_Bits = 2520; Phase = 0; data_info_bit = randi([0,1],N_Bits,1); data_temp = bi2de(reshape(data_info_bit,N_Bits/log2(M),log2(M))); modData = pskmod(data_temp,M,Phase); figure(1); scatterplot(modData); channelAWGN = 15; rxData2 = awgn(modData, channelAWGN); figure(2); scatterplot(rxData2); demodData = pskdemod(rxData2,M,Phase);   for BPSK, Constellation Size, M = 2 for QPSK, M = 4 for 8-PSK, M = 8, and so on    Output Figure: 8-PSK Modulation Figure: 8-PSK Demodulation after adding AWGN Noise Using the above MATLAB code you'll able be to modulate and demodulate 2-PSK, 4-PSK, 8-PSK, 16-PSK, 32-PSK and so on.  16-PSK   Fig: 16-PSK In this above code ' M ' is the number of the conste...

UGC NET Electronic Science Previous Year Question Papers with Solutions

Home / Engineering & Other Exams / UGC NET 2026 PYQ ⬇️ Download Papers and Solutions 📋 Exam Pattern 💡 Preparation Tips ❓ FAQs 📊 Exam Highlights: Electronic Science (88) Feature Details Junior Research Fellowship (JRF) ₹37,000 + HRA per month Eligibility M.Sc/M.Tech in Electronics (55%) Validity of Certificate JRF (3 Years) | Lectureship (Lifetime) 📥 Download UGC NET Electronics PDFs Complete collection of previous year question papers, answer keys and explanations for Subject Code 88. Start Downloading 📂 View All Question Papers June 2025 - Question Paper Download PDF June 2025 - Solved Paper + Explanation ...

How Windowing Affects Your Periodogram

The windowed periodogram is a widely used technique for estimating the Power Spectral Density (PSD) of a signal. It enhances the classical periodogram by mitigating spectral leakage through the application of a windowing function. This technique is essential in signal processing for accurate frequency-domain analysis.   Power Spectral Density (PSD) The PSD characterizes how the power of a signal is distributed across different frequency components. For a discrete-time signal, the PSD is defined as the Fourier Transform of the signal’s autocorrelation function: S x (f) = FT{R x (Ï„)} Here, R x (Ï„)}is the autocorrelation function. FT : Fourier Transform   Classical Periodogram The periodogram is a non-parametric PSD estimation method based on the Discrete Fourier Transform (DFT): P x (f) = \(\frac{1}{N}\) X(f) 2 Here: X(f): DFT of the signal x(n) N: Signal length However, the classical periodogram suffers from spectral leakage due to abrupt truncation of the ...

Advanced M-ary Modulation Simulator: Constellation, min dist, Efficiency, SER, EVM (RMS)

Advanced M-ary Communication Lab Analytical & Statistical Performance of Digital Modulation Theoretical Probability of Error (\(P_s\)) \[ P_s = Q\left(\sqrt{\frac{2 E_b}{N_0}}\right) \] Modulation (M-ary) BPSK (M=2) QPSK (M=4) 8-PSK (M=8) 16-QAM (M=16) 64-QAM (M=64) 256-QAM (M=256) SNR (\(E_b/N_0\)): 12 dB Efficiency 2 bps/Hz Min Dist (\(d_{min}\)) 1.41 Symbol Error 1.2e-5 EVM (RMS) 0.0% Constellation Diagram Noise PDF & Decision Tail 1. Geometric Mapping ...

Frequency Shift Keying (FSK) Modulation & Demodulation (with Simulation)

Frequency Shift Keying (FSK) Theoretical Foundations: Frequency Shift Keying (FSK) is a discrete frequency modulation scheme wherein the digital information is encoded via instantaneous shifts in the carrier signal's frequency. The fundamental implementation is Binary FSK (BFSK), which maps binary data onto two distinct, discrete spectral states. A binary '1' (the "mark" state) is represented by a carrier frequency \( f_1 \), while a binary '0' (the "space" state) corresponds to frequency \( f_2 \). Each symbol is sustained for a bit interval denoted by \( T_b \). FSK Transmitter Characterization: The mathematical model for the modulated BFSK output \( s(t) \) is defined as: \[ s(t) = \begin{cases} A_c \cos(2\pi f_1 t), & \text{for } m = 1 \\ A_c \cos(2\pi f_2 t), & \text{for } m = 0 \end{cases} \] ...

Galois Fields: GF(2) and GF(2m) and Primitive Polynomial

Galois Fields: GF(2) and GF(2 m ) 1. What is a Galois Field (GF)? A Galois Field (GF) is a finite set of elements in which the four basic arithmetic operations—addition, subtraction, multiplication, and division (except by zero)— are all well defined and closed. GF(q) ⇒ a field with exactly q elements 2. The Simplest Field: GF(2) GF(2) is the smallest possible finite field and forms the foundation of all digital systems. GF(2) = {0, 1} Addition in GF(2) Addition is performed modulo 2 (XOR operation): + 0 1 0 0 1 1 1 0 Multiplication in GF(2) × 0 1 0 0 0 1 0 1 GF(2) is used in binary logic, XOR operations, and simple error-control codes. 3. Meaning of GF(2 m ) GF(2 m ) is a finite field containing exactly 2 m elements . Each element represents an m-bit symbol . Field Number of Elements GF(2) 2 GF(2²) 4 GF(2³) 8 GF(2⁸) 256 Important: GF(2 m ) is not integer arithmetic modulo 2 m . It is polynomial-based arithmetic. 4....