correct for these codes and help me to get running codes

3 Ansichten (letzte 30 Tage)
PROSPER
PROSPER am 12 Jul. 2024
% System parameters
M = 50; % Number of antennas
K = 3; % Number of terminals
SNR_dB = 20; % SNR in dB
numSymbols = 1e4; % Number of symbols for simulation
L_prime = 5; % L' = 5
% QPSK Modulator and Demodulator
qpskMod = comm.QPSKModulator('BitInput', false);
qpskDemod = comm.QPSKDemodulator('BitOutput', false);
% Generate random data symbols
dataSymbols = randi([0 3], K, numSymbols);
% Generate transmitted symbols (QPSK)
txSymbols = step(qpskMod, dataSymbols(:)); % Corrected input format
txSymbols = reshape(txSymbols, [], K);
% Channel matrix
H = (randn(M, K) + 1i*randn(M, K))/sqrt(2);
% Received signal with AWGN
rxSignal = awgn(H .* txSymbols, SNR_dB, 'measured'); % Transpose to match dimensions
Arrays have incompatible sizes for this operation.
% MRC Combining
combiner_MRC = conj(H);
rxCombined_MRC = combiner_MRC * rxSignal;
% ZF Combining
combiner_ZF = pinv(H);
rxCombined_ZF = combiner_ZF * rxSignal;
% Demodulate received symbols
rxDataSymbols_MRC = step(qpskDemod, rxCombined_MRC(:));
rxDataSymbols_ZF = step(qpskDemod, rxCombined_ZF(:));
% Decision threshold (for QPSK, it's zero)
detected_MRC = rxDataSymbols_MRC > 0;
detected_ZF = rxDataSymbols_ZF > 0;
% Reshape for plotting
rxCombined_MRC = reshape(rxCombined_MRC, [], 1);
rxCombined_ZF = reshape(rxCombined_ZF, [], 1);
% Plotting
figure;
subplot(1, 2, 1);
scatterplot(rxCombined_MRC);
title('MRC Receiver');
xlabel('In-Phase');
ylabel('Quadrature');
axis equal; % Equal scaling on both axes
grid on;
subplot(1, 2, 2);
scatterplot(rxCombined_ZF);
title('ZF Receiver');
xlabel('In-Phase');
ylabel('Quadrature');
axis equal; % Equal scaling on both axes
grid on;
sgtitle('Constellation of Estimated Symbols for K=3, M=50, L''=5, and \rho=20 dB');
  2 Kommentare
Steven Lord
Steven Lord am 12 Jul. 2024
What makes you think this code is incorrect?
  • Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
  • Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
  • Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
Sam Chak
Sam Chak am 12 Jul. 2024
@PROSPER, You can check the size of the arrays.
% Generate transmitted symbols (QPSK)
txSymbols = step(qpskMod, dataSymbols(:)); % Corrected input format
txSymbols = reshape(txSymbols, [], K);
size(txSymbols)
ans = 1x2
10000 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Channel matrix
H = (randn(M, K) + 1i*randn(M, K))/sqrt(2);
size(H)
ans = 1x2
50 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Received signal with AWGN
rxSignal = awgn(H .* txSymbols, SNR_dB, 'measured'); % Transpose to match dimensions
Arrays have incompatible sizes for this operation.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

sai charan sampara
sai charan sampara am 16 Jul. 2024
Hello,
I made the following changes to the code to make the array sizes compatible.
rxSignal = awgn(H * txSymbols', SNR_dB, 'measured'); % Transpose to match dimensions
% MRC Combining
combiner_MRC = conj(H)';
The following code post changes might help you:
M = 50; % Number of antennas
K = 3; % Number of terminals
SNR_dB = 20; % SNR in dB
numSymbols = 1e4; % Number of symbols for simulation
L_prime = 5; % L' = 5
% QPSK Modulator and Demodulator
qpskMod = comm.QPSKModulator('BitInput', false);
qpskDemod = comm.QPSKDemodulator('BitOutput', false);
% Generate random data symbols
dataSymbols = randi([0 3], K, numSymbols);
% Generate transmitted symbols (QPSK)
txSymbols = step(qpskMod, dataSymbols(:)); % Corrected input format
txSymbols = reshape(txSymbols, [], K);
% Channel matrix
H = (randn(M, K) + 1i*randn(M, K))/sqrt(2);
% Received signal with AWGN
rxSignal = awgn(H * txSymbols', SNR_dB, 'measured'); % Transpose to match dimensions
% MRC Combining
combiner_MRC = conj(H)';
rxCombined_MRC = combiner_MRC * rxSignal;
% ZF Combining
combiner_ZF = pinv(H);
rxCombined_ZF = combiner_ZF * rxSignal;
% Demodulate received symbols
rxDataSymbols_MRC = step(qpskDemod, rxCombined_MRC(:));
rxDataSymbols_ZF = step(qpskDemod, rxCombined_ZF(:));
% Decision threshold (for QPSK, it's zero)
detected_MRC = rxDataSymbols_MRC > 0;
detected_ZF = rxDataSymbols_ZF > 0;
% Reshape for plotting
rxCombined_MRC = reshape(rxCombined_MRC, [], 1);
rxCombined_ZF = reshape(rxCombined_ZF, [], 1);
% Plotting
scatterplot(rxCombined_MRC);
title('MRC Receiver');
xlabel('In-Phase');
ylabel('Quadrature');
axis equal; % Equal scaling on both axes
grid on;
scatterplot(rxCombined_ZF);
title('ZF Receiver');
xlabel('In-Phase');
ylabel('Quadrature');
axis equal; % Equal scaling on both axes
grid on;
sgtitle('Constellation of Estimated Symbols for K=3, M=50, L''=5, and \rho=20 dB');

Community Treasure Hunt

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

Start Hunting!

Translated by