can you help me to fix this error in code?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% Set the parameters of the simulation
N = 10000; % number of symbols to simulate
snr_range = 5:30; % range of SNR values in dB
% Generate a QPSK symbol constellation
constellation = qammod(0:3, 4);
% Create a vector of complex Gaussian noise samples with zero mean and unit variance
noise = randn(1, N) + 1i * randn(1, N);
% Loop over the SNR values
for snr_db = snr_range
% Calculate the SNR in linear scale
snr = 10^(snr_db/10);
% Initialize the error counter
errors = 0;
% Loop over the symbols to be transmitted
for i = 1:N
% Select two random QPSK symbols
s1 = constellation(randi(4));
s2 = constellation(randi(4));
% Generate the Alamouti coded symbol
s = sqrt(1/2) * [s1 -s2*conj(s1); s2 conj(s1)];
% Generate two independent Rayleigh fading coefficients
h1 = sqrt(1/2) * (randn(1) + 1i * randn(1));
h2 = sqrt(1/2) * (randn(1) + 1i * randn(1));
% Calculate the received signal
r = h1 * s(1,:) + h2 * s(2,:) + noise / sqrt(snr);
% Decode the received signal using the Alamouti scheme
s_hat = sqrt(1/2) * [r(1) conj(r(2)); r(2) r(1)];
% Calculate the symbol error rate (SER) for this SNR value
errors= errors + sum(s1
= s_hat(1,1)) + sum(s2
=s
h
at(1,1))+sum(s2
= s_hat(1,2));
end
% Calculate the symbol error probability (SEP) for this SNR value
sep(snr_db - min(snr_range) + 1) = errors / (N * 2);
end
% Plot the symbol error probability curve
semilogy(snr_range, sep);
xlabel('SNR (dB)');
ylabel('SEP');
title('Alamouti Scheme in Rayleigh Fading MISO Channel with QPSK');
0 commentaires
Réponses (2)
KSSV
le 15 Déc 2022
Replace
errors= errors + sum(s1
= s_hat(1,1)) + sum(s2
=s
h
at(1,1))+sum(s2
= s_hat(1,2));
with
errors= errors + sum(s1) + s_hat(1,1) + sum(s2=shat(1,1))+sum(s2=s_hat(1,2));
2 commentaires
Walter Roberson
le 16 Déc 2022
sum(s2=shat(1,1))
Provided that you have not replaced sum with a variable, that sub-expression is equivalent to
sum('s2', shat(1,1))
Are you sure you want to do that, pass in an option named s2 to sum() ? Wouldn't you prefer a comparison == instead?
Image Analyst
le 15 Déc 2022
Read the FAQ starting from here:
There are lots of related error messages there and explains what causes them and how to avoid the problem.
Voir également
Catégories
En savoir plus sur Modulation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!