Viterbi hard demodulator project

5 次查看(过去 30 天)
Carmen Chira
Carmen Chira 2023-6-16
Hello,
I have the following requirements for a project:
Step 3. Change the Matlab model (or add code) to simulate and estimate the BER for the corresponding non-coded scheme (the same Modulation type, with no CC).
Step 4. Present and explain all the changes you made in the Matlab code (in both Steps 2 and 3).
Step 5. Run the simulation(s) and plot the BER curves of the new schemes (coded and non-coded).
Step 6. Determine the coding gain (in dB) of the coded scheme (Step 2) as compared to the non-coded scheme (Step 3).
With my specific values being:
To achieve this I have written the following code:
%STEP 2
clear all % Clear all variables in the workspace
close all % Close all figure windows
clc % Clear the command window
rand('state', sum(100*clock)) % Set the random number generator seed
lng_bits = 100; % Number of information bits to be transmitted
constraint_length = 6; % Set the constraint length of the convolutional code to 6
G = [57 65 71]; % Generator polynomial vectors for convolutional code
trellis = poly2trellis(constraint_length, G); % Create a trellis structure based on the code parameters
nr_in = log2(trellis.numInputSymbols); % Number of input symbols per trellis stage
nr_out = log2(trellis.numOutputSymbols); % Number of output symbols per trellis stage
EbN0_dB = [0 : 7]; % Eb/N0 values in decibels for simulation
lng_SNR = length(EbN0_dB); % Number of simulation points
wait = waitbar(0, 'Please wait...'); % Create a progress bar
% Loop over different Eb/N0 values
for i_SNR = 1:lng_SNR
Num_er_bit = 0; % Initialize the number of error bits
no_frames = 0; % Initialize the number of transmitted frames
% Keep simulating until a sufficient number of error bits is obtained
while Num_er_bit < 100
clear u v s_QPSK Noise r s_demod u_estim; % Clear variables for each simulation
u = randsrc(1, lng_bits, [0 1]); % Generate random information bits
v = convenc(u, trellis); % Convolutional encoding of information bits
M = 4; % Modulation type: QPSK (4-QAM)
h = comm.QPSKModulator('BitInput', true); % Create a QPSK modulator object
s_QPSK = h(v'); % Modulate the encoded bits to obtain QPSK symbols
SNRdB = EbN0_dB(i_SNR) + 10*log10(nr_in / nr_out * log2(M)); % Calculate SNR in dB
Noise = wgn(1, lng_bits * nr_out / (nr_in * log2(M)), -SNRdB, 'complex'); % Generate complex Gaussian noise
r = s_QPSK + Noise.'; % Add noise to the received QPSK symbols
g = comm.QPSKDemodulator('BitOutput', true); % Create a QPSK demodulator object
s_demod = g(r); % Demodulate the received symbols to obtain demodulated bits
tblen = 5 * nr_out * max(constraint_length); % Set traceback length for Viterbi decoding
u_estim = vitdec(s_demod', trellis, tblen, 'cont', 'soft', 3); % Perform Viterbi decoding with soft decision and 3-bit output
[nr_er, Rat] = biterr(u(1:lng_bits - tblen), u_estim(tblen + 1:lng_bits)); % Calculate the number of error bits
Num_er_bit = Num_er_bit + nr_er; % Update the total number of error bits
no_frames = no_frames + 1; % Increment the number of transmitted frames
end
BER(i_SNR) = Num_er_bit / ((lng_bits - tblen) * no_frames); % Calculate the Bit Error Rate (BER)
waitbar(i_SNR / lng_SNR, wait) % Update the progress bar
end
close(wait) % Close the progress bar
figure; % Create a new figure window
semilogy(EbN0_dB, BER, '--ob', 'linewidth', 2); % Plot BER values on a semilog scale
grid % Display grid lines in the plot
set(gca, 'FontSize', 14) % Set font size for the axes
legend(['\fontname{Times}\fontsize{14}Coded QPSK + CC, R=1/3, comm.x, soft, 3 bits']) % Add a legend to the plot
ylabel('\fontname{Times}\fontsize{16}\it\bf{BER}'); % Set the y-axis label
xlabel('\fontname{Times}\fontsize{16}\it\bf{E_b/N\rm\bf_0}'); % Set the x-axis label
% STEP 3
clear all
close all
clc
rand('state', sum(100*clock))
lng_bits = 100;
constraint_length = 6;
G = [57 65 71];
trellis = poly2trellis(constraint_length, G);
nr_in = log2(trellis.numInputSymbols);
nr_out = log2(trellis.numOutputSymbols);
EbN0_dB = [0 : 7];
lng_SNR = length(EbN0_dB);
wait = waitbar(0, 'Please wait...');
for i_SNR = 1:lng_SNR
Num_er_bit = 0;
no_frames = 0;
while Num_er_bit < 100
clear u v s_QPSK Noise r s_demod u_estim;
u = randsrc(1, lng_bits, [0 1]);
v = convenc(u, trellis);
M = 4;
h = comm.QPSKModulator('BitInput', true);
s_QPSK = h(v');
SNRdB = EbN0_dB(i_SNR) + 10*log10(nr_in / nr_out * log2(M));
Noise = wgn(1, lng_bits * nr_out / (nr_in * log2(M)), -SNRdB, 'complex');
r = s_QPSK + Noise.';
g = comm.QPSKDemodulator('BitOutput', true);
s_demod = g(r);
tblen = 5 * nr_out * max(constraint_length);
u_estim = vitdec(s_demod', trellis, tblen, 'cont', 'soft', 3);
[nr_er, Rat] = biterr(u(1:lng_bits - tblen), u_estim(tblen + 1:lng_bits));
Num_er_bit = Num_er_bit + nr_er;
no_frames = no_frames + 1;
end
BER_coded(i_SNR) = Num_er_bit / ((lng_bits - tblen) * no_frames);
waitbar(i_SNR / lng_SNR, wait)
end
close(wait)
wait = waitbar(0, 'Please wait...');
for i_SNR = 1:lng_SNR
Num_er_bit = 0;
no_frames = 0;
while Num_er_bit < 100
clear u v s_QPSK Noise r s_demod u_estim;
u = randsrc(1, lng_bits, [0 1]);
M = 4;
h = comm.QPSKModulator('BitInput', true);
s_QPSK = h(u');
SNRdB = EbN0_dB(i_SNR);
Noise = wgn(1, lng_bits * log2(M), -SNRdB, 'complex');
r = s_QPSK + Noise;
g = comm.QPSKDemodulator('BitOutput', true);
s_demod = g(r(:));
s_demod_truncated = s_demod(1:lng_bits);
[nr_er, Rat] = biterr(u, s_demod_truncated');
Num_er_bit = Num_er_bit + nr_er;
no_frames = no_frames + 1;
end
BER_noncoded(i_SNR) = Num_er_bit / (lng_bits * no_frames);
waitbar(i_SNR / lng_SNR, wait)
end
close(wait)
figure;
semilogy(EbN0_dB, BER_coded, '--ob', 'linewidth', 2);
hold on;
semilogy(EbN0_dB, BER_noncoded, '--sr', 'linewidth', 2);
grid
set(gca, 'FontSize', 14)
legend('\fontname{Times}\fontsize{14}Coded QPSK + CC, R=1/3, comm.x, soft, 3 bits', '\fontname{Times}\fontsize{14}Non-Coded QPSK, R=1, comm.x')
ylabel('\fontname{Times}\fontsize{16}\it\bf{BER}');
xlabel('\fontname{Times}\fontsize{16}\it\bf{E_b/N\rm\bf_0}');
And the final ggraph is the following:
Since my classmates and I haven't reached a decision and asking the proffessor is nor quite an option, could anybody, please, tell me if the result is correct or if there are any mistakes in the code that could result in an incorrect graph?
All opinions are welcomed.
Thank you!
the models given to us are in attachment.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Error Detection and Correction 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by