How come the Bit Error Rate for my Vitrebi soft decoder always returns as 0.5 for all values of SNR?

7 Ansichten (letzte 30 Tage)
So this is my code in which I'm trying to get the BER for soft decision Vitrebi decoding using BPSK modulation in an AWGN channel with code rate 1/3:
input_size = 400;
terminate_length = 3;
total_input_size = 403;
kin = 1;
n = 3;
v = 3;
total_states = 2^v;
current_state = 0;
SNR = 1:1:12;
% Data generation
data = [randi([0 1], 12, input_size), zeros(12, terminate_length)];
% BPSK Modulation
% Decoder
temp_reg = randn(12, 1209);
trellis_poly = poly2trellis(4, {'x3 + x2 + 1', 'x3 + x + 1', 'x3 + 1'});
for i = 1:length(SNR)
% Add noise
codeword(i,:) = convenc(data(i,:),trellis_poly);
codeword_bpsk(i,:) = codeword(i,:) * 2 -1;
corrupted_codeword(i, :) = sqrt(0.5*(1./SNR(i)))*codeword_bpsk(i, :) + temp_reg(i, :);
decoded(i,:) = vitdec(corrupted_codeword(i, :), trellis_poly, 3, 'term', 'unquant');
BER(i) = biterr(data(i, 1:end-3),decoded(i,3+1:end))/403;
end
The input size is of 400 bits + 3 bits to get back to state 0. I generate therefore 12x403 data bits. I define my trellis polynomial and begin the for loop.
For each value of SNR from 1 - 12, I convolutionally encode the data, I convert it to BPSK and then I add noise. This is done by multiplying a custom variance by the data and adding some noise drawn from the normal distribution.
I then decode this using the corrupted_codeword, my trellis polynomial, the traceback length is 3 as this is the maximum amount of bits needed to return to state 0. Term means it should terminate at state 0 and from examples I saw that MATLAB used 'unquant' for soft decoding. I know you can use 'soft' but that only lets you use positive integers which I don't quite understand as I thought the whole point of soft decoding was that you could economically do it with Vitrebi using any kind of value.
Anyway, I then compute the number of bit errors between the original data and the decoded data, excluding the trailing bits hence the 1:end-3, then divide by the number of bits. However, for every single value of SNR I'm getting a Bit Error Rate of roughly 0.5 which obviously isn't right. I've tried changing the 403 to 400 to account for the missing trailing bits but that makes no difference. If I also try just doing data(i,:) and decoded(i,:) in biterr I still get the same thing. I don't quite get where this is going wrong since I'm using MATLAB's built in functions, also the decoded data looks right since they start and terminate with data corresponding to state 0 but it just doesn't match up with the actual data.

Antworten (1)

Simran
Simran am 3 Apr. 2025 um 5:42
I see you’re trying to simulate a communication system using MATLAB focusing mainly BER for a convolutionally encoded and Viterbi-decoded signal but there are some corrections in your code. Follow these steps:
1.) Change the constraint length in poly2trellis from 4 to 3 to match the generator polynomials [7 5 3]. This will resolve the error related to the constraint length mismatch.
% Trellis definition
trellis_poly = poly2trellis(3, [7 5 3]); % Constraint length 3, using octal representation
2.) Adjust the noise variance calculation to ensure that it aligns with the expected SNR and code rate.
% Noise addition
noise_variance = 1/(2 * code_rate * 10^(SNR(i)/10));
noise = sqrt(noise_variance) * randn(size(codeword_bpsk));
corrupted_codeword = codeword_bpsk + noise;
3.) Introduce a scaling and quantization process for the corrupted_codeword to prepare it for soft-decision decoding. This involves normalilizing the corrupted_codeword to fit within the range expected by the vitdec function and quantizing the normalized values into integers ranging from 0 to 7 (for 3-bit soft decision decoding).
L = 3; % Number of soft decision bits
max_val = 2^L - 1;
% Normalize and scale
scaled_codeword = (corrupted_codeword + 1) * (max_val / 2);
quantized_codeword = round(scaled_codeword);
quantized_codeword = min(max(quantized_codeword, 0), max_val);
4.) Use the vitdec function with the 'soft' option and specify the number of soft decision bits as 3.
% Decoding
traceback_length = 5 * v;
decoded = vitdec(quantized_codeword, trellis_poly, traceback_length, 'term', 'soft', L);
5.) Calculate the Bit Error Rate (BER) by comparing the original data with the decoded data, ensuring the trailing bits are excluded from the comparison.
% BER Calculation
BER(i) = biterr(data(i, 1:end-terminate_length), decoded(1:input_size)) / input_size;
I ran this code and got this figure:
You can refer to the following documentation for more help:

Produkte


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by