can you help me to fix this error in code?

3 views (last 30 days)
% 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');

Answers (2)

KSSV
KSSV on 15 Dec 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 Comments
Batuhan Samet Demirci
Batuhan Samet Demirci on 15 Dec 2022
Edited: Batuhan Samet Demirci on 15 Dec 2022
after replacing it i got this error;
Arrays have incompatible sizes for this operation.
what should we do now sir?
the question was;
Write a MATLAB program that calculates the symbol error probability of the Alamouti scheme via numerical simulation using the QPSK symbol constellation in a Rayleigh fading MISO channel with two transmit and one receive antenna for the SNR range of 5 to 30 dB.
Walter Roberson
Walter Roberson on 16 Dec 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?

Sign in to comment.


Image Analyst
Image Analyst on 15 Dec 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.
  1 Comment
Batuhan Samet Demirci
Batuhan Samet Demirci on 15 Dec 2022
thanks but i coudnt still make this code work. Anyone else can help me?

Sign in to comment.

Categories

Find more on Propagation and Channel Models in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!