Skip to main content

Frequency Selective Fading vs Flat Fading in MATLAB


In the MATLAB code below, a comparison between frequency-selective fading and flat fading is shown.
In frequency-selective fading, multipath propagation causes multiple delayed copies of the signal to arrive at the receiver. When the channel delay spread exceeds the symbol duration, these delayed components overlap, resulting in inter-symbol interference (ISI). In flat fading, ISI does not occur because the signal bandwidth is much smaller than the channel’s coherence bandwidth. Therefore, the channel response remains approximately constant across the signal bandwidth, and all symbols experience the same fading.

MATLAB Code for frequency selective fading channel


% OFDM over frequency selective Rayleigh fading channel
clc; clearvars; close all;
% Simulation parameters
nSym = 10^4; % Number of OFDM symbols
EbN0dB = 0:2:20; % Eb/N0 range
MOD_TYPE = 'MPSK'; % 'MPSK' or 'MQAM'
M = 4; % QPSK
N = 64; % Total number of subcarriers
Ncp = 16; % Cyclic prefix length
L = 10; % Number of channel taps
k = log2(M); % Bits per symbol
EsN0dB = 10*log10(k*(N/(N+Ncp))) + EbN0dB; % account CP loss
errors = zeros(1,length(EsN0dB));
% Monte Carlo simulation
for i = 1:length(EsN0dB)
for j = 1:nSym
% -------- Transmitter --------
d = ceil(M*rand(1,N)); % Random symbols
[X , ref] = modulation_mapper(MOD_TYPE,M,d);
x = ifft(X,N); % IDFT
s = add_cyclic_prefix(x,Ncp); % Add CP
% -------- Channel (Freq-selective Rayleigh) --------
h = 1/sqrt(2)*(randn(1,L)+1i*randn(1,L)); % CIR
H = fft(h,N); % Freq response
hs = conv(h,s); % Channel filtering
r = awgn(hs,EsN0dB(i)); % Add noise
% -------- Receiver --------
y = remove_cyclic_prefix(r,Ncp,N); % Remove CP
Y = fft(y,N); % DFT
V = Y ./ H; % Equalization
[~, dcap] = iqOptDetector(V,ref);
errors(i) = errors(i) + sum(d ~= dcap);
end
end
% SER results
simulatedSER = errors/(nSym*N);
theoreticalSER = ser_rayleigh(EbN0dB,MOD_TYPE,M);
% Plot
semilogy(EbN0dB,simulatedSER,'ko'); hold on;
title(['Performance of ',num2str(M),'-',MOD_TYPE,...
' OFDM over Freq Selective Rayleigh channel']);
xlabel('Eb/N0 (dB)');
ylabel('Symbol Error Rate');
function [X, ref] = modulation_mapper(MOD_TYPE, M, d)
% Modulation mapper for OFDM transmitter
% MOD_TYPE - 'MPSK' or 'MQAM'
% M - Modulation order (BPSK=2, QPSK=4, 16-QAM=16, etc.)
% d - Data symbols drawn from {1,2,...,M}
%
% Outputs:
% X - Modulated complex symbols
% ref - Ideal constellation points (for IQ detector)
if strcmpi(MOD_TYPE, 'MPSK')
[X, ref] = mpsk_modulator(M, d); % M-PSK modulation
elseif strcmpi(MOD_TYPE, 'MQAM')
[X, ref] = mqam_modulator(M, d); % M-QAM modulation
else
error('Invalid modulation type. Use ''MPSK'' or ''MQAM''.');
end
end
function [s,ref]=mpsk_modulator(M,d)
%Function to MPSK modulate the vector of data symbols - d
%[s,ref]=mpsk_modulator(M,d) modulates the symbols defined by the
%vector d using MPSK modulation, where M specifies the order of
%M-PSK modulation and the vector d contains symbols whose values
%in the range 1:M. The output s is the modulated output and ref
%represents the reference constellation that can be used in demod
ref_i= 1/sqrt(2)*cos(((1:1:M)-1)/M*2*pi);
ref_q= 1/sqrt(2)*sin(((1:1:M)-1)/M*2*pi);
ref = ref_i+1i*ref_q;
s = ref(d); %M-PSK Mapping
end
function s = add_cyclic_prefix(x,Ncp)
%function to add cyclic prefix to the generated OFDM symbol x that
%is generated at the output of the IDFT block
% x - ofdm symbol without CP (output of IDFT block)
% Ncp-num. of samples at x's end that will copied to its beginning
% s - returns the cyclic prefixed OFDM symbol
s = [x(end-Ncp+1:end) x]; %Cyclic prefixed OFDM symbol
end
function y = remove_cyclic_prefix(r,Ncp,N)
%function to remove cyclic prefix from the received OFDM symbol r
% r - received ofdm symbol with CP
% Ncp - num. of samples at beginning of r that need to be removed
% N - number of samples in a single OFDM symbol
% y - returns the OFDM symbol without cyclic prefix
y=r(Ncp+1:N+Ncp);%cut from index Ncp+1 to N+Ncp
end
function [idealPoints,indices]= iqOptDetector(received,ref)
%Optimum Detector for 2-dim. signals (MQAM,MPSK,MPAM) in IQ Plane
%received - vector of form I+jQ
%ref - reference constellation of form I+jQ
%Note: MPAM/BPSK are one dim. modulations. The same function can be
%applied for these modulations since quadrature is zero (Q=0).
x=[real(received); imag(received)]';%received vec. in cartesian form
y=[real(ref); imag(ref)]';%reference vec. in cartesian form
[idealPoints,indices]= minEuclideanDistance(x,y);
end
function [idealPoints,indices]= minEuclideanDistance(x,y)
%function to compute the pairwise minimum Distance between two
%vectors x and y in p-dimensional signal space and select the
%vectors in y that provides the minimum distances.
% x - a matrix of size mxp
% y - a matrix of size nxp. This acts as a reference against
% which each point in x is compared.
% idealPoints - contain the decoded vector
% indices - indices of the ideal points in reference matrix y
[m,p1] = size(x);[n,p2] = size(y);
if p1~=p2
error('Dimension Mismatch: x and y must have same dimension')
end
X = sum(x.*x,2);
Y = sum(y.*y,2)';
d = X(:,ones(1,n)) + Y(ones(1,m),:) - 2*x*y';%Squared Euclidean Dist.
[~,indices]=min(d,[],2); %Find the minimum value along DIM=2
idealPoints=y(indices,:);
indices=indices.';
end
function [ser] = ser_rayleigh(EbN0dB,MOD_TYPE,M)
%Compute Theoretical Symbol Error rates for MPSK or MQAM modulations
%EbN0dB - list of SNR per bit points
%MOD_TYPE - 'MPSK' or 'MQAM'
%M - Modulation level for the chosen modulation
% - For MPSK M can be any power of 2
% - For MQAM M must be even power of 2 (square QAM only)
gamma_b = 10.^(EbN0dB/10); %SNR per bit in linear scale
gamma_s = log2(M)*gamma_b; %SNR per symbol in linear scale
switch lower(MOD_TYPE)
case {'bpsk'}
ser = 0.5*(1-sqrt(gamma_b/(1+gamma_b)));
case {'mpsk','psk'}
ser = zeros(size(gamma_s));
for i=1:length(gamma_s), %for each SNR point
g = sin(pi/M).^2;
fun = @(x) 1./(1+(g.*gamma_s(i)./(sin(x).^2))); %MGF
ser(i) = (1/pi)*integral(fun,0,pi*(M-1)/M);
end
case {'mqam','qam'}
ser = zeros(size(gamma_s));
for i=1:length(gamma_s) %for each SNR point
g = 1.5/(M-1);
fun = @(x) 1./(1+(g.*gamma_s(i)./(sin(x).^2)));%MGF
ser(i) = 4/pi*(1-1/sqrt(M))*integral(fun,0,pi/2)-4/pi*(1-1/sqrt(M))^2* ...
integral(fun,0,pi/4);
end
case {'mpam','pam'}
ser = zeros(size(gamma_s));
for i=1:length(gamma_s) %for each SNR point
g = 3/(M^2-1);
fun = @(x) 1./(1+(g.*gamma_s(i)./(sin(x).^2)));%MGF
ser(i) = 2*(M-1)/(M*pi)*integral(fun,0,pi/2);
end
end
end

Output 

 



MATLAB Code for flat fading channel


% OFDM over flat Rayleigh fading channel
clc; clearvars; close all;
% Simulation parameters
nSym = 10^4; % Number of OFDM symbols
EbN0dB = 0:2:20; % Eb/N0 range
MOD_TYPE = 'MPSK'; % 'MPSK' or 'MQAM'
M = 4; % QPSK
N = 64; % Total number of subcarriers
Ncp = 16; % Cyclic prefix length
k = log2(M); % Bits per symbol
EsN0dB = 10*log10(k*(N/(N+Ncp))) + EbN0dB; % account CP loss
errors = zeros(1,length(EsN0dB));
% Monte Carlo simulation
for i = 1:length(EsN0dB)
for j = 1:nSym
% -------- Transmitter --------
d = ceil(M*rand(1,N)); % Random symbols
[X , ref] = modulation_mapper(MOD_TYPE,M,d);
x = ifft(X,N); % IDFT
s = add_cyclic_prefix(x,Ncp); % Add CP
% -------- Channel (Flat Rayleigh) --------
h = 1/sqrt(2)*(randn + 1i*randn); % Single-tap flat fading
H = h; % Frequency response
r = h*s; % Flat-fading multiplication
r = awgn(r,EsN0dB(i),'measured'); % Add AWGN noise
% -------- Receiver --------
y = remove_cyclic_prefix(r,Ncp,N); % Remove CP
Y = fft(y,N); % DFT
V = Y ./ H; % Equalization
[~, dcap] = iqOptDetector(V,ref);
errors(i) = errors(i) + sum(d ~= dcap);
end
end
% SER results
simulatedSER = errors/(nSym*N);
theoreticalSER = ser_rayleigh(EbN0dB,MOD_TYPE,M);
% Plot
semilogy(EbN0dB,simulatedSER,'ko'); hold on;
title(['Performance of ',num2str(M),'-',MOD_TYPE,...
' OFDM over Flat Rayleigh channel']);
xlabel('Eb/N0 (dB)');
ylabel('Symbol Error Rate');
%% ------------------------ Functions ------------------------
function [X, ref] = modulation_mapper(MOD_TYPE, M, d)
if strcmpi(MOD_TYPE, 'MPSK')
[X, ref] = mpsk_modulator(M, d);
elseif strcmpi(MOD_TYPE, 'MQAM')
[X, ref] = mqam_modulator(M, d);
else
error('Invalid modulation type. Use ''MPSK'' or ''MQAM''.');
end
end
function [s, ref] = mpsk_modulator(M,d)
ref_i= 1/sqrt(2)*cos(((1:M)-1)/M*2*pi);
ref_q= 1/sqrt(2)*sin(((1:M)-1)/M*2*pi);
ref = ref_i + 1i*ref_q;
s = ref(d);
end
function s = add_cyclic_prefix(x,Ncp)
s = [x(end-Ncp+1:end) x];
end
function y = remove_cyclic_prefix(r,Ncp,N)
y = r(Ncp+1:N+Ncp);
end
function [idealPoints,indices] = iqOptDetector(received,ref)
x = [real(received); imag(received)]';
y = [real(ref); imag(ref)]';
[idealPoints,indices] = minEuclideanDistance(x,y);
end
function [idealPoints,indices] = minEuclideanDistance(x,y)
[m,p1] = size(x); [n,p2] = size(y);
if p1 ~= p2, error('Dimension mismatch'); end
X = sum(x.*x,2);
Y = sum(y.*y,2)';
d = X(:,ones(1,n)) + Y(ones(1,m),:) - 2*x*y';
[~,indices] = min(d,[],2);
idealPoints = y(indices,:);
indices = indices.';
end
function ser = ser_rayleigh(EbN0dB,MOD_TYPE,M)
gamma_b = 10.^(EbN0dB/10); % SNR per bit linear
gamma_s = log2(M)*gamma_b; % SNR per symbol linear
switch lower(MOD_TYPE)
case {'bpsk'}
ser = 0.5*(1-sqrt(gamma_b./(1+gamma_b)));
case {'mpsk','psk'}
ser = zeros(size(gamma_s));
for i=1:length(gamma_s)
g = sin(pi/M)^2;
fun = @(x) 1./(1 + (g*gamma_s(i)./(sin(x).^2)));
ser(i) = (1/pi)*integral(fun,0,pi*(M-1)/M);
end
case {'mqam','qam'}
ser = zeros(size(gamma_s));
for i=1:length(gamma_s)
g = 1.5/(M-1);
fun = @(x) 1./(1 + (g*gamma_s(i)./(sin(x).^2)));
ser(i) = 4/pi*(1-1/sqrt(M))*integral(fun,0,pi/2) ...
- 4/pi*(1-1/sqrt(M))^2*integral(fun,0,pi/4);
end
end
end
 

 

 Output

 

 


Further Reading


People are good at skipping over material they already know!

View Related Topics to







Contact Us

Name

Email *

Message *

Popular Posts

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...(MATLAB Code + Simulator)

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

Theoretical BER vs SNR for binary ASK, FSK, and PSK with MATLAB Code + Simulator

📘 Overview & Theory 🧮 MATLAB Codes 📚 Further Reading Theoretical BER vs SNR for Amplitude Shift Keying (ASK) The theoretical Bit Error Rate (BER) for binary ASK depends on how binary bits are mapped to signal amplitudes. For typical cases: If bits are mapped to 1 and -1, the BER is: BER = Q(√(2 × SNR)) If bits are mapped to 0 and 1, the BER becomes: BER = Q(√(SNR / 2)) Where: Q(x) is the Q-function: Q(x) = 0.5 × erfc(x / √2) SNR : Signal-to-Noise Ratio N₀ : Noise Power Spectral Density Understanding the Q-Function and BER for ASK Bit '0' transmits noise only Bit '1' transmits signal (1 + noise) Receiver decision threshold is 0.5 BER is given by: P b = Q(0.5 / σ) , where σ = √(N₀ / 2) Using SNR = (0.5)² / N₀, we get: BER = Q(√(SNR / 2)) Theoretical BER vs ...

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

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

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

BER performance of QPSK with BPSK, 4-QAM, 16-QAM, 64-QAM, 256-QAM, etc (MATLAB + Simulator)

📘 Overview 📚 QPSK vs BPSK and QAM: A Comparison of Modulation Schemes in Wireless Communication 📚 Real-World Example 🧮 MATLAB Code 📚 Further Reading   QPSK provides twice the data rate compared to BPSK. However, the bit error rate (BER) is approximately the same as BPSK at low SNR values when gray coding is used. On the other hand, QPSK exhibits similar spectral efficiency to 4-QAM and 16-QAM under low SNR conditions. In very noisy channels, QPSK can sometimes achieve better spectral efficiency than 4-QAM or 16-QAM. In practical wireless communication scenarios, QPSK is commonly used along with QAM techniques, especially where adaptive modulation is applied. Modulation Bits/Symbol Points in Constellation Usage Notes BPSK 1 2 Very robust, used in weak signals QPSK 2 4 Balanced speed & reliability 4-QAM ...

Simulation of ASK, FSK, and PSK using MATLAB Simulink (with Online Simulator)

📘 Overview 🧮 How to use MATLAB Simulink 🧮 Simulation of ASK using MATLAB Simulink 🧮 Simulation of FSK using MATLAB Simulink 🧮 Simulation of PSK using MATLAB Simulink 🧮 Simulator for ASK, FSK, and PSK 🧮 Digital Signal Processing Simulator 📚 Further Reading ASK, FSK & PSK HomePage MATLAB Simulation Simulation of Amplitude Shift Keying (ASK) using MATLAB Simulink      In Simulink, we pick different components/elements from MATLAB Simulink Library. Then we connect the components and perform a particular operation.  Result A sine wave source, a pulse generator, a product block, a mux, and a scope are shown in the diagram above. The pulse generator generates the '1' and '0' bit sequences. Sine wave sources produce a specific amplitude and frequency. The scope displays the modulated signal as well as the original bit sequence created by the pulse generator. Mux is a tool for displaying b...

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

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