- 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 次查看(过去 30 天)
显示 更早的评论
% 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 个评论
Steven Lord
2024-7-12
What makes you think this code is incorrect?
Sam Chak
2024-7-12
@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
回答(1 个)
sai charan sampara
2024-7-16
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 QPSK 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!