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

Online Simulator for ASK, FSK, and PSK Signal Generation

Interactive Digital Signal Processing (DSP) Tutorial and Simulator for ASK, FSK, and BPSK modulation techniques. Try our new Digital Signal Processing Simulator!   •   Interactive ASK, FSK, and BPSK tools updated for 2025. Start Now Digital Modulation Visualizer: ASK, FSK, & BPSK Simulator Learn and visualize binary modulation techniques (ASK, FSK, BPSK) in real-time with adjustable carrier and sampling parameters. Perfect for DSP students and engineers. 📡 ASK Simulator 📶 FSK Simulator 🎚️ BPSK Simulator 📚 More Topics ASK Modulator FSK Modulator BPSK Modulator Demodulation More Topics 1. ASK (Ampli...

Direction of Arrival (DoA) Online Simulator (using MUSIC)

Interactive DOA Simulator X-axis XY angle (deg): 45 XZ angle (deg): 30 Noise: 0.05 Y-axis XY angle (deg): 60 YZ angle (deg): 45 Noise: 0.05 Z-axis XZ angle (deg): 60 YZ angle (deg): 30 Noise: 0.05 Estimated DOA (deg): 0 Simulation Workflow and Mathematical Background This simulator demonstrates Direction of Arrival (DOA) estimation using three-axis sensor signals (X, Y, Z), Maximal Ratio Combining (MRC) , and the MUSIC algorithm . It allows interactive control of signal angles and noise for teaching purposes. 1. Signal Generation A pure sinewave signal of frequency f is projected onto three axes using user-defined angles in different planes: X-axis: θ XY , θ XZ Y-axis: θ XY , θ YZ Z-axis: θ XZ , θ YZ Mathematically, for each time sample t : x(t) = s(t) * cos(θ_xy_x) * cos(θ_xz_x) + n_x(t) y(t) = s(t) * sin(θ_xy_y) * cos(θ_yz_y) + n_y(t) z(t) = s(t) * sin(θ_xz_z) * sin(θ_yz_z) + n_z(t) wh...

UGC NET Electronic Science Previous Year Question Papers with Solutions

Download Papers and Solutions Exam Pattern Preparation Tips FAQs More Home / Engineering & Other Exams / UGC NET 2026 PYQ 📊 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 - Sol...

Constellation Diagrams of ASK, PSK, and FSK (with MATLAB Code + Simulator)

Constellation Diagrams: ASK, FSK, and PSK Comprehensive guide to signal space representation, including interactive simulators and MATLAB implementations. 📘 Overview 🧮 Simulator ⚖️ Theory 📈 Q-function 📚 Resources BASK Modulation Transmits one of two signals: 0 or $\sqrt{E_b}$, representing binary 0 and 1. Simple but sensitive to noise. BFSK Modulation Transmits one of two signals: $\sqrt{E_b}$ on the Y-axis or $\sqrt{E_b}$ on the X-axis. These are orthogonal signals. BPSK Modulation Transmits $+\sqrt{E_b}$ or $-\sqrt{E_b}$ (antipodal signaling). Most efficient binary scheme. ...

DSB-SC Modulation and Demodulation

📘 Overview 🧮 DSB-SC Modulator 🧮 DSB-SC Detector 🧮 Comparisons 🧮 Q & A Summary 📚 Further Reading Double-sideband suppressed-carrier transmission (DSB-SC) is transmission in which frequencies produced by amplitude modulation (AM) are symmetrically spaced above and below the carrier frequency and the carrier level is reduced to the lowest practical level, ideally being completely suppressed. In the DSB-SC modulation, unlike in AM, the wave carrier is not transmitted; thus, much of the power is distributed between the sidebands, which implies an increase of the cover in DSB-SC, compared to AM, for the same power use. DSB-SC transmission is a special case of double-sideband reduced carrier transmission. It is used for radio data systems. This model is frequently used in Amateur radio voice communications, especially on High-Frequency bands. Spectrum DSB-SC i...

Design of CMOS XOR/XNOR Gates

Design of CMOS XOR/XNOR Gates The semiconductor industry has experienced rapid integration of multimedia applications into mobile electronics, leading to very high integration density in CMOS VLSI. As operating frequencies increase, power consumption, speed, silicon area, and reliability become critical considerations. The XOR-XNOR circuits are fundamental building blocks in arithmetic circuits (Full Adders, Multipliers), compressors, comparators, parity checkers, code converters, error-detecting/correcting codes, and phase detectors. Their performance directly impacts the complex circuits they are used in. Design goals include full output voltage swing, low power consumption, reduced transistor count, minimal delay, and simultaneous non-skewed outputs. Static Logic (Static CMOS) Stat...