error shows up when run the code
Afficher commentaires plus anciens
% Clear all variables and close all figures
clear all; clf;
% Set the mode to 1 for regularized channel inversion
mode = 1;
% Set the number of frames per packet and the number of packets
N_frame = 10;
N_packet = 200;
% Set the number of bits per frame and the total number of bits
b = 2;
NT = 4;
N_user = 20;
N_act_user = 4;
I = eye(N_act_user, NT);
N_pbits = N_frame * NT * b;
N_tbits = N_pbits * N_packet;
% Set the range of SNR values
SNRdBs = (0:2:20);
sq2 = sqrt(2);
% Initialize the BER vector
BER = zeros(length(SNRdBs), 1);
% Loop over the SNR values
for i_SNR = 1:length(SNRdBs)
% Set the SNR
SNRdB = SNRdBs(i_SNR);
% Initialize the number of errors
N_ebits = 0;
% Set the random number seed
rand('state', seed);
% Generate the transmitted symbols
msg_bit = randi(1, N_pbits);
symbol = QPSK_mapper(msg_bit);
x = reshape(symbol, NT, N_frame);
% Generate the channel matrices
for i_user = 1:N_user
H(i_user, :) = (randn(1, NT) + 1i * randn(1, NT)) / sq2;
Channel_norm(i_user) = norm(H(i_user, :));
end
% Sort the channel matrices by channel norm
[Ch_norm, Index] = sort(Channel_norm, 'descend');
H_used = H(Index(1:N_act_user), :);
% Calculate the BD precoding matrix
W_bd = H_used * inv(H_used' * H_used + (mode == 1) * sigma2 * I) * H_used';
% Precode the transmitted symbols
Tx_signal = W_bd * x;
% Add noise to the transmitted signal
Rx_signal = H_used * Tx_signal + sigma * (randn(N_act_user, N_frame) + 1i * randn(N_act_user, N_frame));
% Equalize the received signal
x_hat = Rx_signal;
% Reshape the equalized signal
symbol_hat = reshape(x_hat, NT * N_frame, 1);
% Slice the received symbols
symbol_sliced = QPSK_slicer(symbol_hat);
% Demap the sliced symbols
demapped = QPSK_demapper(symbol_sliced);
% Count the number of errors
N_ebits = N_ebits + sum(msg_bit ~= demapped);
end
% Calculate the BER
BER = N_ebits / N_tbits;
% Plot the BER vs. SNR
semilogy(SNRdBs, BER, '-o');
grid on;
when run this code , Error in Untitled7 (line 35)
rand('state', seed); this error show up so how can i fix it please?
1 commentaire
Dyuman Joshi
le 5 Oct 2023
"how can i fix it please?"
By defining the variable seed
Réponses (1)
Cris LaPierre
le 5 Oct 2023
Déplacé(e) : Dyuman Joshi
le 5 Oct 2023
0 votes
1 commentaire
Dyuman Joshi
le 5 Oct 2023
Catégories
En savoir plus sur Propagation and Channel Models dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!