Skip to main content

MATLAB Code for Zak Transform (Time-Frequency Transform)

 

MATLAB Code for Zak Transform (Time-Frequency Transform) 

%% The code is developed by www.salimwireless.com
clc; clear; close all;
%% Step 1: Parameters
N = 16; % Total number of symbols
M = 4; % Lattice rows (time slots)
SNR_dB = 20; % Noise level
modOrder = 4; % QPSK
%% Step 2: Generate random QPSK symbols
data = randi([0 modOrder-1], N, 1);
txSymbols = pskmod(data, modOrder, pi/4);
disp('Transmitted symbols:');
disp(txSymbols);
%% Step 3: Discrete Zak Transform (map to 2D lattice)
lattice = zeros(M, N/M);
for n = 0:N-1
m = mod(n, M) + 1; % row (time slot)
k = floor(n / M) + 1; % column (frequency slot)
lattice(m,k) = lattice(m,k) + txSymbols(n+1)*exp(-1j*2*pi*(k-1)*n/N);
end
% Optional: Apply simple phase rotation per column to illustrate Zak Transform
%for k = 1:N/M
% lattice(:,k) = lattice(:,k) .* exp(-1j*2*pi*(k-1)*(0:M-1)'/N);
%end
disp('Zak lattice:');
disp(lattice);
%% Step 4: Serialize lattice for transmission
txSerial = lattice(:); % Column-wise flattening
disp('Serial transmission stream:');
disp(txSerial);
%% Step 5: Channel (flat fading + noise)
h = (randn(size(txSerial)) + 1j*randn(size(txSerial)))/sqrt(2);
rxSerial = txSerial .* h; % Apply channel
rxSerial = awgn(rxSerial, SNR_dB, 'measured'); % Add noise
disp('Received serial stream:');
disp(rxSerial);
%% Step 6: Reshape back into lattice at receiver
rxLattice = reshape(rxSerial, M, N/M);
disp('Received lattice (reshaped):');
disp(rxLattice);
%% Step 7: Equalization (remove channel effect)
hLattice = reshape(h, M, N/M);
eqLattice = rxLattice ./ hLattice;
disp('Equalized lattice:');
disp(eqLattice);
%% Step 8: Inverse Zak Transform (flatten back to 1D symbols)
rxSymbols = zeros(N,1);
for m = 1:M
for k = 1:N/M
n = (k-1)*M + (m-1); % original index
rxSymbols(n+1) = eqLattice(m,k) * exp(1j*2*pi*(k-1)*n/N);
end
end
disp('Recovered 1D symbols:');
disp(rxSymbols);
%% Step 9: Demap symbols
rxData = pskdemod(rxSymbols, modOrder, pi/4);
disp('Recovered data bits:');
disp(rxData);
%% Step 10: Compute Symbol Error
numErrors = sum(data ~= rxData);
fprintf('Symbol errors: %d out of %d\n', numErrors, N);
web('https://www.salimwireless.com/search?q=otfs%20ofdm', '-browser'); 
 

 Output

Transmitted 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

Zak lattice:
   0.7071 - 0.7071i   0.7071 - 0.7071i  -0.7071 + 0.7071i   0.7071 + 0.7071i
   0.7071 - 0.7071i  -0.3827 + 0.9239i  -1.0000 - 0.0000i   0.9239 - 0.3827i
  -0.7071 + 0.7071i   1.0000 + 0.0000i   0.7071 - 0.7071i   0.0000 + 1.0000i
  -0.7071 - 0.7071i   0.9239 - 0.3827i   0.0000 - 1.0000i   0.9239 + 0.3827i

Serial transmission stream:
   0.7071 - 0.7071i
   0.7071 - 0.7071i
  -0.7071 + 0.7071i
  -0.7071 - 0.7071i
   0.7071 - 0.7071i
  -0.3827 + 0.9239i
   1.0000 + 0.0000i
   0.9239 - 0.3827i
  -0.7071 + 0.7071i
  -1.0000 - 0.0000i
   0.7071 - 0.7071i
   0.0000 - 1.0000i
   0.7071 + 0.7071i
   0.9239 - 0.3827i
   0.0000 + 1.0000i
   0.9239 + 0.3827i

Received serial stream:
   0.8979 - 0.2337i
   0.6302 + 0.0081i
   0.5156 - 0.1635i
  -0.1600 + 0.7016i
  -0.5541 + 0.6423i
  -0.2204 + 1.0218i
  -0.4239 - 0.2612i
  -0.8138 + 1.0080i
   1.5777 - 0.8193i
   0.3525 + 0.1960i
   1.2537 - 0.5949i
   0.6953 - 0.4729i
   1.1553 - 1.2822i
  -0.2305 + 0.5419i
   0.4042 - 0.7063i
  -0.7030 + 1.3476i

Received lattice (reshaped):
   0.8979 - 0.2337i  -0.5541 + 0.6423i   1.5777 - 0.8193i   1.1553 - 1.2822i
   0.6302 + 0.0081i  -0.2204 + 1.0218i   0.3525 + 0.1960i  -0.2305 + 0.5419i
   0.5156 - 0.1635i  -0.4239 - 0.2612i   1.2537 - 0.5949i   0.4042 - 0.7063i
  -0.1600 + 0.7016i  -0.8138 + 1.0080i   0.6953 - 0.4729i  -0.7030 + 1.3476i

Equalized lattice:
   0.6493 - 0.5983i   0.6756 - 0.6211i  -0.7041 + 0.7505i   0.6701 + 0.7524i
   0.7856 - 0.8601i  -0.3434 + 1.0541i  -0.6994 + 0.1083i   0.7405 - 0.4090i
  -0.5754 + 0.6370i   0.8883 - 0.0777i   0.6756 - 0.6978i   0.0747 + 1.0447i
  -0.6840 - 0.6918i   0.8995 - 0.4555i  -0.0477 - 0.8712i   0.9284 + 0.4356i

Recovered 1D symbols:
   0.6493 - 0.5983i
   0.7856 - 0.8601i
  -0.5754 + 0.6370i
  -0.6840 - 0.6918i
   0.6211 + 0.6756i
  -0.8425 - 0.7206i
  -0.5732 + 0.6831i
  -0.6567 + 0.7651i
  -0.7041 + 0.7505i
  -0.5711 - 0.4179i
   0.6978 + 0.6756i
   0.6498 + 0.5823i
  -0.7524 + 0.6701i
  -0.5276 + 0.6612i
   0.6859 - 0.7915i
   0.7577 - 0.6910i

Recovered data bits:
     2
     2
     1
     3
     0
     3
     1
     1
     1
     3
     0
     0
     1
     1
     2
     2

Symbol errors: 0 out of 16 



Contact Us

Name

Email *

Message *

Popular Posts

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

Q-function in BER vs SNR Calculation (with Simulation)

Q-function in BER vs. SNR Calculation In digital communications and signal processing, the Q-function plays a significant role in predicting system reliability. It allows engineers to quantify the probability that Gaussian noise will exceed a specific threshold, causing a bit error. What is the Q-function? The Q-function is a mathematical function representing the tail probability of the standard normal (Gaussian) distribution. It is the complementary cumulative distribution function (CCDF) of a standard Gaussian distribution. Q(x) = (1 / √(2Ï€)) ∫â‚“∞ e^(-t² / 2) dt The Role of the Q-function in BER vs. SNR The Q-function is the standard tool for calculating BER in systems like BPSK or QPSK over AWGN (Additive White Gaussian Noise) channels. For BPSK: In BPSK, we transmit +√E b (bit 1) and -√E b (bit 0). The decision boundary is set at 0 . If -√E b was sent, an error occurs if noise r > √...

Pulse Width Modulation (PWM)

Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a method of controlling the average power delivered by an electrical signal.   Fig: An example of PWM in an idealized inductor driven by a blue line voltage source modulated as a series of sawtooth pulses, resulting in a red line current in the inductor.    Generating a PWM Signal The simplest way to generate a PWM signal is the intersection method, which requires only a sawtooth or a triangle waveform (easily generated using a simple oscillator) and a comparator. When the value of the reference signal is more than the modulation waveform, the PWM signal (magenta) is in the high state; otherwise, it is in the low state.      Duty cycle A low duty cycle equates to low power because the power is off for most of the time; the word duty cycle reflects the ratio of "on" time to the regular interval or "period" of time. The duty cycle is measured in percent, with 100% representing full o...

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

Channel Impulse Response (CIR) (with MATLAB + Simulator)

📘 Overview & Theory 📘 How CIR Affects the Signal 🧮 Online Channel Impulse Response Simulator 🧮 MATLAB Codes 📚 Further Reading What is the Channel Impulse Response (CIR)? The Channel Impulse Response (CIR) is a concept primarily used in the field of telecommunications and signal processing. It provides information about how a communication channel responds to an impulse signal. It describes the behavior of a communication channel in response to an impulse signal. In signal processing, an impulse signal has zero amplitude at all other times and amplitude ∞ at time 0 for the signal. Using a Dirac Delta function, we can approximate this. Fig: Dirac Delta Function The result of this calculation is that all frequencies are responded to equally by δ(t) . This is crucial since we never know which frequenci...

FFT Butterfly Method Explained (with Simulations)

4-Point FFT Using Butterfly Method Given: x[n] = {0, 1, 2, 3} Step 1: Split into Even & Odd Even indices: x e = {x[0], x[2]} = {0, 2} Odd indices: x o = {x[1], x[3]} = {1, 3} Step 2: 2-point DFT For any {a, b}: DFT = {a + b, a - b} Even Part (E): {0+2, 0-2} = {2, -2} Odd Part (O): {1+3, 1-3} = {4, -2} Step 3: Combine Using Butterfly X[k] = E[k] + W 4 k O[k] X[k + 2] = E[k] - W 4 k O[k] Twiddle Factors (N=4): W 4 0 = 1, W 4 1 = -j Final Calculations: X[0] = E[0] + W 4 0 O[0] = 2 + (1)(4) = 6 X[2] = E[0] - W 4 0 O[0] = 2 - (1)(4) = -2 X[1] = E[1] + W 4 1 O[1] = -2 + (-j)(-2) = -2 + 2j X[3] = E[1] - W 4 1 O[1] = -2 - (-j)(-2) = -2 - 2j Final Answer: X[k] = {6, -2 + 2j, -2, -2 - 2j} 8-Point FFT Using Butterfly Method Given: x[n] = {0,1,2,3,4,5,6,7} Step 1: Split into Bit-Reversed Order To perform DIT-FFT, split the 8 points into pairs of two: Group A: {x[0], x[4]} = {0, 4}...

AM Modulation Online Simulator

Amplitude Modulation Simulator s AM (t) = A c [1 + k a m(t)] cos(ω c t) where, ω = 2πf & k a = Amplitude Sensitivity Modulation index, μ = k a A m Message Frequency (fm): Carrier Frequency (fc): Carrier Amplitude (Ac): Modulation Index (m = Am / Ac):

Frequency Bands : EHF, SHF, UHF, VHF, HF, MF, LF, VLF and Their Uses

Frequency Bands >> EHF, SHF, UHF, VHF, HF, MF, LF... Frequency Bands and Their Uses 1. Extremely High Frequency (EHF) 30 - 300 GHz Uses 5G Networks 5G millimeter wave band 6G and beyond (Experimental) RADAR 2. Super High Frequency (SHF) 3 - 30 GHz Uses Ultra-wideband (UWB) Airborne RADAR Satellite Communication Microwave Link Communication or SATCOM 3. Ultra High Frequency (UHF) 300 - 3000 MHz Uses Satellite Communication Television Surveillance Navigation aids Also, read important wireless communication terms 4....