Bit error rate VS Signal to noise ratio plot in MATLAB
7 次查看(过去 30 天)
显示 更早的评论
Hello all, I am trying to plot BER Vs SNR plot in MATLAB for the following case: V2V Communications using Doppler: Rayleigh channel, Fourier Transform (FT) and Inverse Fourier Transform (IFT), Orthogonal Frequency Division Multiplexing (OFDM),Modulation Techniques: 16-QAM and 4-QPSK modulation schemes. Use of LDPC (Low-Density Parity Check) for error correction. Encapsulation of the signal for protection from noise, improving transmission and reducing errors.
This is what I had tried:
clc; clear all; close all;
% Parameters
nSym = 10^4; % Number of OFDM symbols
EbN0dB = 0:2:20; % SNR Range
M_vals = [4, 16]; % Modulation schemes: 4-QAM (QPSK) and 16-QAM
N = 64; % OFDM Subcarriers
Ncp = 16; % Cyclic Prefix Length
L = 10; % Number of channel taps
fd = 100; % Doppler Frequency (Hz)
Fs = 1e3; % Sampling Frequency
Ts = 1/Fs; % Sampling Interval
t = (0:nSym-1) * Ts; % Time vector
ber_simulated = zeros(length(M_vals), length(EbN0dB)); % BER for QPSK & 16-QAM
for m = 1:length(M_vals)
m
M = M_vals(m); % Current Modulation Order
bitsPerSymbol = log2(M);
for i = 1:length(EbN0dB)
i
errors = 0;
total_bits = 0;
for j = 1:nSym
% **Generate Transmitted Symbols**
data_bits = randi([0 1], 1, bitsPerSymbol * N); % Random bits
if M == 4
% **QPSK Modulation**
si = 2 * (data_bits(1:2:end) - 0.5);
sq = 2 * (data_bits(2:2:end) - 0.5);
s = si + 1j * sq; % QPSK Symbols
else
% **16-QAM Modulation (Gray Coded)**
sI = 2 * (mod(data_bits(1:4:end) + 2 * data_bits(2:4:end), 4) - 1.5);
sQ = 2 * (mod(data_bits(3:4:end) + 2 * data_bits(4:4:end), 4) - 1.5);
s = (sI + 1j * sQ) / sqrt(10); % Normalize power
end
% **Generate Rayleigh Fading**
h = (randn(1, N) + 1j * randn(1, N)) / sqrt(2); % Rayleigh fading
% **Noise Scaling (AWGN)**
N0 = (10^(EbN0dB(i)/10))^-1;
n = sqrt(N0/2) * (randn(1, N) + 1j * randn(1, N)); % AWGN
% **Received Signal**
r = h .* s + n; % Apply Rayleigh fading
% **Zero-Forcing Equalization**
h(abs(h) < 1e-3) = 1; % Avoid division by small values
r_eq = r ./ h; % Equalized signal
% **Hard Decision Decoding**
if M == 4
% **QPSK Detection**
si_hat = 2 * (real(r_eq) > 0) - 1;
sq_hat = 2 * (imag(r_eq) > 0) - 1;
received_bits = [si_hat > 0; sq_hat > 0];
else
% **16-QAM Detection**
sI_hat = real(r_eq) * sqrt(10) / 2; % Scale to match constellation levels
sQ_hat = imag(r_eq) * sqrt(10) / 2;
% **Hard Decision Levels for 16-QAM**
sI_decoded = 3 * (sI_hat > 2) + 1 * (sI_hat > 0 & sI_hat <= 2) ...
-1 * (sI_hat <= 0 & sI_hat > -2) - 3 * (sI_hat <= -2);
sQ_decoded = 3 * (sQ_hat > 2) + 1 * (sQ_hat > 0 & sQ_hat <= 2) ...
-1 * (sQ_hat <= 0 & sQ_hat > -2) - 3 * (sQ_hat <= -2);
% **Convert Symbol Decisions to Bits (Gray Mapping)**
received_bits = [mod(sI_decoded + 3, 4) > 1; mod(sI_decoded + 1, 4) > 1;
mod(sQ_decoded + 3, 4) > 1; mod(sQ_decoded + 1, 4) > 1];
end
% **BER Calculation**
errors = errors + sum(data_bits ~= received_bits(:)');
total_bits = total_bits + length(data_bits);
end
ber_simulated(m, i) = errors / total_bits; % Compute BER
end
end
% **Plot BER vs. Eb/N0**
figure;
semilogy(EbN0dB, ber_simulated(1, :), '-o', 'LineWidth', 2);
hold on;
semilogy(EbN0dB, ber_simulated(2, :), '-s', 'LineWidth', 2);
xlabel('E_b/N_0 (dB)');
ylabel('Bit Error Rate (BER)');
title('BER vs. SNR for QPSK and 16-QAM over Rayleigh Fading');
grid on;
legend('QPSK', '16-QAM');
My query is I am not getting how to implement LDPC part in above code. Any help in this regard will be highly appreciated.
1 个评论
vidyesh
2025-7-30
Hello Chaaru,
Since LDPC is an error correction algorithm, you will have to add the LDPC Encoder before the Modulator and LDPC Decoder after the Demodulator.
The code generates 10^4 data bits, taking this into account create an appropriate Generator Matrix and use that to obtain the codewords.
For decoder the first k bits will be your codeword (If systematic) or use the Generator Matrix to decode the codeword.
There are multiple ways to create the Generator and Parity-Check Matrices, you can implement any one of them.
Alternatively you can use the "ldpcEncode" and "ldpcDecode" MATLAB functions.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Propagation and Channel Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!