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 

People are good at skipping over material they already know!

View Related Topics to







Contact Us

Name

Email *

Message *

Popular Posts

Online Simulator for ASK, FSK, and PSK

Try our new Digital Signal Processing Simulator!   Start Simulator for binary ASK Modulation Message Bits (e.g. 1,0,1,0) Carrier Frequency (Hz) Sampling Frequency (Hz) Run Simulation Simulator for binary FSK Modulation Input Bits (e.g. 1,0,1,0) Freq for '1' (Hz) Freq for '0' (Hz) Sampling Rate (Hz) Visualize FSK Signal Simulator for BPSK Modulation ...

Channel Impulse Response (CIR)

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

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...

📘 Overview of BER and SNR 🧮 Online Simulator for BER calculation of m-ary QAM and m-ary PSK 🧮 MATLAB Code for BER calculation of M-ary QAM, M-ary PSK, QPSK, BPSK, ... 📚 Further Reading 📂 View Other Topics on M-ary QAM, M-ary PSK, QPSK ... 🧮 Online Simulator for Constellation Diagram of m-ary QAM 🧮 Online Simulator for Constellation Diagram of m-ary PSK 🧮 MATLAB Code for BER calculation of ASK, FSK, and PSK 🧮 MATLAB Code for BER calculation of Alamouti Scheme 🧮 Different approaches to calculate BER vs SNR What is Bit Error Rate (BER)? The abbreviation BER stands for Bit Error Rate, which indicates how many corrupted bits are received (after the demodulation process) compared to the total number of bits sent in a communication process. BER = (number of bits received in error) / (total number of tran...

Constellation Diagrams of ASK, PSK, and FSK

📘 Overview of Energy per Bit (Eb / N0) 🧮 Online Simulator for constellation diagrams of ASK, FSK, and PSK 🧮 Theory behind Constellation Diagrams of ASK, FSK, and PSK 🧮 MATLAB Codes for Constellation Diagrams of ASK, FSK, and PSK 📚 Further Reading 📂 Other Topics on Constellation Diagrams of ASK, PSK, and FSK ... 🧮 Simulator for constellation diagrams of m-ary PSK 🧮 Simulator for constellation diagrams of m-ary QAM BASK (Binary ASK) Modulation: Transmits one of two signals: 0 or -√Eb, where Eb​ is the energy per bit. These signals represent binary 0 and 1.    BFSK (Binary FSK) Modulation: Transmits one of two signals: +√Eb​ ( On the y-axis, the phase shift of 90 degrees with respect to the x-axis, which is also termed phase offset ) or √Eb (on x-axis), where Eb​ is the energy per bit. These signals represent binary 0 and 1.  BPSK (Binary PSK) Modulation: Transmits one of two signals...

Gaussian minimum shift keying (GMSK)

📘 Overview & Theory 🧮 Simulator for GMSK 🧮 MSK and GMSK: Understanding the Relationship 🧮 MATLAB Code for GMSK 📚 Simulation Results for GMSK 📚 Q & A and Summary 📚 Further Reading Dive into the fascinating world of GMSK modulation, where continuous phase modulation and spectral efficiency come together for robust communication systems! Core Process of GMSK Modulation Phase Accumulation (Integration of Filtered Signal) After applying Gaussian filtering to the Non-Return-to-Zero (NRZ) signal, we integrate the smoothed NRZ signal over time to produce a continuous phase signal: θ(t) = ∫ 0 t m filtered (Ī„) dĪ„ This integration is crucial for avoiding abrupt phase transitions, ensuring smooth and continuous phase changes. Phase Modulation The next step involves using the phase signal to modulate a...

Q-function in BER vs SNR Calculation

Q-function in BER vs. SNR Calculation In the context of Bit Error Rate (BER) and Signal-to-Noise Ratio (SNR) calculations, the Q-function plays a significant role, especially in digital communications and signal processing . What is the Q-function? The Q-function is a mathematical function that represents the tail probability of the standard normal distribution. Specifically, it is defined as: Q(x) = (1 / sqrt(2Ī€)) ∫ₓ∞ e^(-t² / 2) dt In simpler terms, the Q-function gives the probability that a standard normal random variable exceeds a value x . This is closely related to the complementary cumulative distribution function of the normal distribution. The Role of the Q-function in BER vs. SNR The Q-function is widely used in the calculation of the Bit Error Rate (BER) in communication systems, particularly in systems like Binary Phase Shift Ke...

LDPC Encoding and Decoding Techniques

📘 Overview & Theory 🧮 LDPC Encoding Techniques 🧮 LDPC Decoding Techniques 📚 Further Reading 'LDPC' is the abbreviation for 'low density parity check'. LDPC code H matrix contains very few amount of 1's and mostly zeroes. LDPC codes are error correcting code. Using LDPC codes, channel capacities that are close to the theoretical Shannon limit can be achieved.  Low density parity check (LDPC) codes are linear error-correcting block code suitable for error correction in a large block sizes transmitted via very noisy channel. Applications requiring highly reliable information transport over bandwidth restrictions in the presence of noise are increasingly using LDPC codes. 1. LDPC Encoding Technique The proper form of H matrix is derived from the given matrix by doing multiple row operations as shown above. In the above, H is parity check matrix and G is generator matrix. If you consider matrix H as [-P' | I] then matrix G will b...

MATLAB code for Pulse Code Modulation (PCM) and Demodulation

📘 Overview & Theory 🧮 Quantization in Pulse Code Modulation (PCM) 🧮 MATLAB Code for Pulse Code Modulation (PCM) 🧮 MATLAB Code for Pulse Amplitude Modulation and Demodulation of Digital data 🧮 Other Pulse Modulation Techniques (e.g., PWM, PPM, DM, and PCM) 📚 Further Reading MATLAB Code for Pulse Code Modulation clc; close all; clear all; fm=input('Enter the message frequency (in Hz): '); fs=input('Enter the sampling frequency (in Hz): '); L=input('Enter the number of the quantization levels: '); n = log2(L); t=0:1/fs:1; % fs nuber of samples have tobe selected s=8*sin(2*pi*fm*t); subplot(3,1,1); t=0:1/(length(s)-1):1; plot(t,s); title('Analog Signal'); ylabel('Amplitude--->'); xlabel('Time--->'); subplot(3,1,2); stem(t,s);grid on; title('Sampled Sinal'); ylabel('Amplitude--->'); xlabel('Time--->'); % Quantization Process vmax=8; vmin=-vmax; %to quanti...