can you help me to fix this error in code?
2 次查看(过去 30 天)
显示 更早的评论
% 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 个评论
回答(2 个)
KSSV
2022-12-15
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 个评论
Walter Roberson
2022-12-16
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
2022-12-15
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!