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

CMOS Logic Gates: Inverter, NAND, and NOR

CMOS Logic Gates: Inverter, NAND, and NOR Complementary metal–oxide–semiconductor (CMOS) technology forms the backbone of modern digital IC design. Patented by Frank Wanlass in 1963 ( US patent 3,356,858 ), CMOS enables low-power, high-speed, and noise-immune logic circuits. CMOS gates, including inverters, NAND, and NOR, are widely used in both large-scale and small-scale integrated circuits due to their efficiency and versatility. CMOS Inverter A CMOS inverter consists of a complementary pair of PMOS and NMOS transistors. The PMOS transistor connects to the supply voltage V DD , while the NMOS connects to ground. The input voltage V IN controls both gates, and the output voltage V OUT is taken from the connected drains. CMOS inverters are highly energy-efficient and produce minimal heat due to their comple...

Decision Feedback Equalizer (DFE) in MATLAB

  MATLAB Code M = 4; % QPSK numSymbols = 10000; numTrainingSymbols = 5000; chtaps = [1 0.5*exp(1i*pi/6) 0.1*exp(-1i*pi/8)]; % Generate QPSK symbols data = randi([0 M-1], numSymbols, 1); tx = pskmod(data, M, pi/4); % DFE setup eq = comm.DecisionFeedbackEqualizer; eq.ReferenceTap = 1; eq.NumForwardTaps = 5; eq.NumFeedbackTaps = 3; % SNR sweep snrVec = 0:5:25; % 0,5,10,...25 dB berBefore = zeros(size(snrVec)); berAfter = zeros(size(snrVec)); for k = 1:length(snrVec) % Apply channel and AWGN rx = awgn(filter(chtaps,1,tx), snrVec(k), 'measured' ); % BER before equalization rxDataNoEq = pskdemod(rx, M, pi/4); [~, berBefore(k)] = biterr(data, rxDataNoEq); % Equalize [y,~,~] = eq(rx, tx(1:numTrainingSymbols)); % Phase correction phaseOffset = angle(mean(conj(tx(1:numTrainingSymbols)) .* y(1:numTrainingSymbols))); yCorrected = y * exp(-1i*phaseOffset); % BER after equalization rxDataEq = pskdemod(yCorrected, M, pi/4); [...

Superheterodyne Receiver Online Simulator

Superheterodyne Receiver Simulator Simulation Controls Message Frequency (Hz): Carrier Frequency (Hz): Intermediate Frequency (Hz): Sampling Frequency (Hz): Simulation Duration (s): Run Simulation Signal Plots Numerical Values (first 10 samples) Superheterodyne Receiver Workflow The superheterodyne receiver converts a received RF signal to an intermediate frequency (IF) to simplify filtering and amplification, and finally recovers the original message signal. Steps: Input Message Signal: A low-frequency signal m(t) (e.g., sine wave). RF Modulation (AM): The message modulates the carrier with amplitude modulation: RF(t) = [1 + K_a * m(t)] * cos(2Ï€ f_c t) Mixing with Local Oscillator (LO): The RF signal is multiplied by a local oscillator LO(t) = cos(2Ï€ f_LO t) to produce: IF(t) = RF(t) * LO(t) Intermediate Frequency Filtering: A low-pass filter extracts t...

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 2026 - Question Paper Download PDF June 202...

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...

Flat vs Frequency Selective Online Simulator

Flat vs Frequency Selective Online Simulator Channel Type Without Fading Flat Fading Multipaths Nakagami m SNR(dB) Run Simulation Input Signal Signal After Fading Constellation Diagram BER vs SNR Explore Advanced Flat vs Frequency-Selective Fading Simulator Want to see these equations in action? Visualize it. Launch Simulator Tool Flat Fading and Frequency-Selective Fading Effects of Multipath Components and the Nakagami-m Parameter 1. Flat Fading Flat fading occurs when the signal bandwidth is smaller than the channel's coherence bandwidth, meaning that all frequency components of the transmitted signal experience approximately the same fading. It is typically associated with narrowband signals, where the multipath delay spread is small relative to the symbol duration. ...

Design of CMOS Flip-Flops (SR, D, JK)

Design of CMOS Flip-Flops (SR, D, JK) A flip-flop or latch is a circuit with two stable states, used to store state information. It is the basic storage element in sequential logic and a fundamental building block in digital electronics systems, including computers and communication devices. Flip-flops and latches act as data storage elements for states, pulse counting, and synchronization of variably-timed input signals to a reference clock. Flip-flops can be transparent/opaque (latches) or clocked (synchronous, edge-triggered). Latches are level-sensitive, while flip-flops are edge-sensitive. In sequential logic, the output depends on current inputs and previous states. Fig.1 shows a sequential circuit combining a combinational block and a memory element. ...

MATLAB code for BER vs SNR for M-QAM, M-PSK, QPSK, BPSK (with Simulation)

🧮 MATLAB Code for BPSK, M-ary PSK, and M-ary QAM Together 🧮 MATLAB Code for M-ary QAM 🧮 MATLAB Code for M-ary PSK 📚 Further Reading MATLAB Script for BER vs. SNR for M-QAM, M-PSK, QPSK, BPSK % Written by Salim Wireless clc; clear; close all; snr_db = -5:2:25; psk_orders = [2, 4, 8, 16, 32]; qam_orders = [4, 16, 64, 256]; ber_psk_results = zeros(length(psk_orders), length(snr_db)); ber_qam_results = zeros(length(qam_orders), length(snr_db)); for i = 1:length(psk_orders) ber_psk_results(i, :) = berawgn(snr_db, 'psk', psk_orders(i), 'nondiff'); end for i = 1:length(qam_orders) ber_qam_results(i, :) = berawgn(snr_db, 'qam', qam_orders(i)); end figure; semilogy(snr_db, ber_psk_results(1, :), 'o-', 'LineWidth', 1.5, 'DisplayName', 'BPSK'); hold on; for i = 2:length(psk_orders) semilogy(snr_db, ber_psk_results(i, :), 'o-', 'DisplayName', sprintf('%d-PSK', psk_or...