- 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.
correct for these codes and help me to get running codes
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
% 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
% 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 comentarios
Steven Lord
el 12 de Jul. de 2024
What makes you think this code is incorrect?
Sam Chak
el 12 de Jul. de 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)
% Channel matrix
H = (randn(M, K) + 1i*randn(M, K))/sqrt(2);
size(H)
% Received signal with AWGN
rxSignal = awgn(H .* txSymbols, SNR_dB, 'measured'); % Transpose to match dimensions
Respuestas (1)
sai charan sampara
el 16 de Jul. de 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');
0 comentarios
Ver también
Categorías
Más información sobre QPSK en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!