I'm trying to create an LDPC code simulation for learning with matlab. The code I made earlier is as follows.
% Define DVB-S.2 LDPC code parameters
dvbS2Rate = 1/2; % Code rate for demonstration
dvbS2ldpc = dvbs2ldpc(dvbS2Rate); % Get the LDPC object for DVB-S.2
numInfoBits = size(dvbS2ldpc, 2) - size(dvbS2ldpc, 1); % Number of information bits
% Set up simulation parameters
SNR_dB = 1:10; % SNR range from 1 to 10 dB
Nstop = 1000; % Number of frames to simulate
WER = zeros(1, length(SNR_dB)); % Pre-allocate WER for each SNR value
% Create LDPC encoder and decoder objects
ldpcEncoder = comm.LDPCEncoder('ParityCheckMatrix', dvbS2ldpc);
ldpcDecoder = comm.LDPCDecoder('ParityCheckMatrix', dvbS2ldpc);
% Simulation loop over SNR values
for snr_idx = 1:length(SNR_dB)
% Convert SNR from dB to linear scale for noise variance
SNR_linear = 10^(SNR_dB(snr_idx) / 10);
noiseVar = 1 / (2 * SNR_linear * (1/dvbS2Rate));
% Create AWGN channel object
awgnChannel = comm.AWGNChannel('NoiseMethod', 'Variance', 'Variance', noiseVar);
% Initialize error counters
numberOfBitErrors = 0;
numberOfWordErrors = 0;
for frame = 1:Nstop
% Generate random information bits
infoBits = logical(randi([0 1], numInfoBits, 1));
% LDPC encoding
encodedBits = ldpcEncoder(infoBits);
% BPSK Modulation
modulatedSignal = 2 * double(encodedBits) - 1;
% Pass through AWGN Channel
receivedSignal = awgnChannel(modulatedSignal);
% BPSK Demodulation
receivedBits = receivedSignal < 0;
% LDPC Decoding
decodedBits = ldpcDecoder(double(receivedBits));
% Calculate the number of bit errors
bitErrors = sum(infoBits ~= logical(decodedBits));
numberOfBitErrors = numberOfBitErrors + bitErrors;
numberOfWordErrors = numberOfWordErrors + (bitErrors > 0);
end
% Calculate WER for the current SNR
WER(snr_idx) = numberOfWordErrors / Nstop;
end
% Plot the WER vs SNR graph
figure;
semilogy(SNR_dB, WER, 'b-o');
xlabel('SNR in E_b/N_0 in dB');
ylabel('WER');
title('Word Error Rate vs. SNR for DVB-S.2 LDPC Code');
grid on;
And here's the result.
So far, there's nothing wrong. But when I saw my code, my teacher said the following.
It looks like you are making hard decisions, which is not suitable for this project. The LDPC decoder should accept soft inputs or LLRs, and you need to compute the LLRs from receivedSignal. We talked about this (multiply by 2/sig^2) in our meeting. If you make this change, the performance should improve, perhaps by 3 dB (depending on the code rate).
So I fixed the code after seeing what the teacher said.
% Define DVB-S.2 LDPC code parameters
dvbS2Rate = 1/2; % Code rate for demonstration
dvbS2ldpc = dvbs2ldpc(dvbS2Rate); % Get the LDPC object for DVB-S.2
numInfoBits = size(dvbS2ldpc, 2) - size(dvbS2ldpc, 1); % Number of information bits
% Set up simulation parameters
SNR_dB = 1:10; % SNR range from 1 to 10 dB
Nstop = 1000; % Number of frames to simulate
WER = zeros(1, length(SNR_dB)); % Pre-allocate WER for each SNR value
% Create LDPC encoder and decoder objects
ldpcEncoder = comm.LDPCEncoder('ParityCheckMatrix', dvbS2ldpc);
ldpcDecoder = comm.LDPCDecoder('ParityCheckMatrix', dvbS2ldpc);
% Simulation loop over SNR values
for snr_idx = 1:length(SNR_dB)
% Convert SNR from dB to linear scale for noise variance
SNR_linear = 10^(SNR_dB(snr_idx) / 10);
noiseVar = 1 / (2 * SNR_linear * (1/dvbS2Rate));
% Create AWGN channel object
awgnChannel = comm.AWGNChannel('NoiseMethod', 'Variance', 'Variance', noiseVar);
% Initialize error counters
numberOfBitErrors = 0;
numberOfWordErrors = 0;
for frame = 1:Nstop
% Generate random information bits
infoBits = logical(randi([0 1], numInfoBits, 1));
% LDPC encoding
encodedBits = ldpcEncoder(infoBits);
% BPSK Modulation
modulatedSignal = 2 * double(encodedBits) - 1;
% Pass through AWGN Channel
receivedSignal = awgnChannel(modulatedSignal);
% Calculate LLRs for LDPC Decoding
llrs = 2 * receivedSignal / noiseVar;
% LDPC Decoding using LLRs
decodedBits = ldpcDecoder(llrs);
% Calculate the number of bit errors
bitErrors = sum(infoBits ~= logical(decodedBits));
numberOfBitErrors = numberOfBitErrors + bitErrors;
numberOfWordErrors = numberOfWordErrors + (bitErrors > 0);
end
% Calculate WER for the current SNR
WER(snr_idx) = numberOfWordErrors / Nstop;
end
% Plot the WER vs SNR graph
figure;
semilogy(SNR_dB, WER, 'b-o');
xlabel('SNR in E_b/N_0 in dB');
ylabel('WER');
title('Word Error Rate vs. SNR for DVB-S.2 LDPC Code');
grid on;
But then I got a strange result.
So I asked my teacher for help and my teacher modified the code a little.
% Define DVB-S.2 LDPC code parameters
dvbS2Rate = 1/2; % Code rate for demonstration
dvbS2ldpc = dvbs2ldpc(dvbS2Rate); % Get the LDPC object for DVB-S.2
numInfoBits = size(dvbS2ldpc, 2) - size(dvbS2ldpc, 1); % Number of information bits
% Set up simulation parameters
SNR_dB = 1:10; % SNR range from 1 to 10 dB
Nstop = 1000; % Number of frames to simulate
WER = zeros(1, length(SNR_dB)); % Pre-allocate WER for each SNR value
% Create LDPC encoder and decoder objects
ldpcEncoder = comm.LDPCEncoder('ParityCheckMatrix', dvbS2ldpc);
ldpcDecoder = comm.LDPCDecoder('ParityCheckMatrix', dvbS2ldpc);
% Simulation loop over SNR values
for snr_idx = 1:length(SNR_dB)
% Convert SNR from dB to linear scale for noise variance
SNR_linear = 10^(SNR_dB(snr_idx) / 10);
noiseVar = 1 / (2 * SNR_linear * (1/dvbS2Rate));
% Create AWGN channel object
awgnChannel = comm.AWGNChannel('NoiseMethod', 'Variance', 'Variance', noiseVar);
% Initialize error counters
numberOfBitErrors = 0;
numberOfWordErrors = 0;
for frame = 1:Nstop
% Generate random information bits
infoBits = logical(randi([0 1], numInfoBits, 1));
% LDPC encoding
encodedBits = ldpcEncoder(infoBits);
% BPSK Modulation
modulatedSignal = 1 - 2 * double(encodedBits);
% Pass through AWGN Channel
receivedSignal = awgnChannel(modulatedSignal);
% Calculate LLRs for LDPC Decoding
llrs = 2 * receivedSignal / noiseVar;
% LDPC Decoding using LLRs
decodedBits = ldpcDecoder(llrs);
% Calculate the number of bit errors
bitErrors = sum(infoBits ~= logical(decodedBits));
numberOfBitErrors = numberOfBitErrors + bitErrors;
numberOfWordErrors = numberOfWordErrors + (bitErrors > 0);
end
% Calculate WER for the current SNR
WER(snr_idx) = numberOfWordErrors / Nstop;
end
% Plot the WER vs SNR graph
figure;
semilogy(SNR_dB, WER, 'b-o');
xlabel('SNR in E_b/N_0 in dB');
ylabel('WER');
title('Word Error Rate vs. SNR for DVB-S.2 LDPC Code');
grid on;
But the results are still strange. I should have a graph where the value drops down like the first one, but it's not like that at all... Can I ask for help?
And also, since the input is so big, my teacher told me to reduce the input so that it can be used for a normal PC (I actually used a supercomputer) how should I reduce this?
Thank you for looking at the long text, please help.
I expected graph like this. but as you can see result is really weird/