Can Anyone help me to solve this error?Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use ‘.
here’s the full code
numAntennasTx = 256; % Number of antennasTx
numAntennasRx = 16; % Number of antennasRx
numBits = 10000000; % Number of random bits
ModulationOrder = 16; % 16QAM
snrValues = 0:5:40; % Range of SNR values
%% Generate Random Bits
bits = randi([0 1], numBits, 1);
%% Convolutional Encoding
trellis = poly2trellis(7, [171 133]); % Example trellis
codedBits = convenc(bits, trellis);
%% Modulation
mod_symbols = qammod(codedBits, ModulationOrder, ‘InputType’, ‘bit’, ‘UnitAveragePower’, true);
%% Ensure the number of symbols can be reshaped properly
numSymbols = length(mod_symbols);
paddingSymbols = mod(numAntennasTx – mod(numSymbols, numAntennasTx), numAntennasTx);
mod_symbols_padded = [mod_symbols; zeros(paddingSymbols, 1)];
%% Reshape modulated symbols to fit Tx antennas
mod_symbols_reshaped = reshape(mod_symbols_padded, numAntennasTx, []);
%% Precoding
H = (randn(numAntennasRx, numAntennasTx) + 1i * randn(numAntennasRx, numAntennasTx)) / sqrt(2*numAntennasRx); % Channel matrix
% Regularized Zero Forcing (RZF) Precoding
lambda = 0.01; % Regularization parameter
WRZF = (H’ / (H*H’ + lambda*eye(numAntennasRx)));
% Phased Zero Forcing (PZF) Precoding
angle_H = angle(H);
phase_shift = exp(-1i*angle_H);
H_pzf = H .* phase_shift;
WPZF = (H_pzf’ / (H_pzf*H_pzf’));
%% Apply Precoding
size(WRZF)
size(mod_symbols_reshaped)
precodedBitsRZF = WRZF * mod_symbols_reshaped; % precoding RZF
precodedBitsPZF = WPZF * mod_symbols_reshaped; % precoding PZF
%% Without Precoding
precodedBitsWP = mod_symbols_reshaped; % No precoding
%% OFDM Modulation with Precoding
OfdmSymbolsRZF = ifft(precodedBitsRZF, [], 2); % OFDM modulation with RZF precoding
OfdmSymbolsPZF = ifft(precodedBitsPZF, [], 2); % OFDM modulation with PZF precoding
OfdmSymbolsWP = ifft(precodedBitsWP, [], 2); % OFDM modulation without precoding
%% Channel AWGN
berRZF = zeros(1, length(snrValues)); % Initialize BER results for RZF
berPZF = zeros(1, length(snrValues)); % Initialize BER results for PZF
berWP = zeros(1, length(snrValues)); % Initialize BER results for no precoding
for i = 1:length(snrValues)
snr = snrValues(i);
noiseVar = 1 / (10^(snr/10));
% Transmit through channel (AWGN) for RZF
rxSymbolsRZF = awgn(H * OfdmSymbolsRZF, snr, ‘measured’) + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsRZF)) + 1i * randn(size(OfdmSymbolsRZF)));
% Transmit through channel (AWGN) for PZF
rxSymbolsPZF = awgn(H * OfdmSymbolsPZF, snr, ‘measured’) + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsPZF)) + 1i * randn(size(OfdmSymbolsPZF)));
% Transmit through channel (AWGN) without precoding
rxSymbolsWP = awgn(H * OfdmSymbolsWP, snr, ‘measured’) + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsWP)) + 1i * randn(size(OfdmSymbolsWP)));
%% OFDM Demodulation
% Serial to Parallel Conversion
receivedSymbolsRZFSerial = reshape(rxSymbolsRZF, [], numAntennasRx).’; % Serial to parallel conversion
receivedSymbolsPZFSerial = reshape(rxSymbolsPZF, [], numAntennasRx).’; % Serial to parallel conversion
receivedSymbolsWPSerial = reshape(rxSymbolsWP, [], numAntennasRx).’; % Serial to parallel conversion
% Perform OFDM demodulation for RZF
rxSymbolsIFFTRZF = fft(receivedSymbolsRZFSerial, [], 2); % FFT
% Perform OFDM demodulation for PZF
rxSymbolsIFFTPZF = fft(receivedSymbolsPZFSerial, [], 2); % FFT
% Perform OFDM demodulation for no precoding
rxSymbolsIFFTWP = fft(receivedSymbolsWPSerial, [], 2); % FFT
%% Parallel to Serial Conversion
rxSymbolsDemod_RZF = reshape(rxSymbolsIFFTRZF.’, [], 1); % Parallel to serial conversion
rxSymbolsDemod_PZF = reshape(rxSymbolsIFFTPZF.’, [], 1); % Parallel to serial conversion
rxSymbolsDemod_WP = reshape(rxSymbolsIFFTWP.’, [], 1); % Parallel to serial conversion
% Remove the padded symbols before demodulation
rxSymbolsDemod_RZF = rxSymbolsDemod_RZF(1:end-paddingSymbols);
rxSymbolsDemod_PZF = rxSymbolsDemod_PZF(1:end-paddingSymbols);
rxSymbolsDemod_WP = rxSymbolsDemod_WP(1:end-paddingSymbols);
% QAM demodulation
demodBitsRZF = qamdemod(rxSymbolsDemod_RZF, ModulationOrder, ‘OutputType’, ‘bit’, ‘UnitAveragePower’, true);
demodBitsPZF = qamdemod(rxSymbolsDemod_PZF, ModulationOrder, ‘OutputType’, ‘bit’, ‘UnitAveragePower’, true);
demodBitsWP = qamdemod(rxSymbolsDemod_WP, ModulationOrder, ‘OutputType’, ‘bit’, ‘UnitAveragePower’, true);
% Calculate the Bit Error Rate (BER)
berRZF(i) = sum(demodBitsRZF ~= codedBits(1:end-paddingSymbols)) / numBits;
berPZF(i) = sum(demodBitsPZF ~= codedBits(1:end-paddingSymbols)) / numBits;
berWP(i) = sum(demodBitsWP ~= codedBits(1:end-paddingSymbols)) / numBits;
end
%% Display Results
fprintf(‘Bit Error Rate (RZF Precoding):n’);
disp(berRZF);
fprintf(‘Bit Error Rate (PZF Precoding):n’);
disp(berPZF);
fprintf(‘Bit Error Rate (Without Precoding):n’);
disp(berWP);
%% Plotting the results
figure;
semilogy(snrValues, berRZF, ‘bs-‘, ‘LineWidth’, 2);
hold on;
semilogy(snrValues, berPZF, ‘gs-‘, ‘LineWidth’, 2);
semilogy(snrValues, berWP, ‘rs-‘, ‘LineWidth’, 2);
xlabel(‘SNR (dB)’);
ylabel(‘Bit Error Rate (BER)’);
legend(‘RZF Precoding’, ‘PZF Precoding’, ‘Without Precoding’);
title(‘Massive MIMO 256×16 Antennas with RZF and PZF Precoding’);
grid on;here’s the full code
numAntennasTx = 256; % Number of antennasTx
numAntennasRx = 16; % Number of antennasRx
numBits = 10000000; % Number of random bits
ModulationOrder = 16; % 16QAM
snrValues = 0:5:40; % Range of SNR values
%% Generate Random Bits
bits = randi([0 1], numBits, 1);
%% Convolutional Encoding
trellis = poly2trellis(7, [171 133]); % Example trellis
codedBits = convenc(bits, trellis);
%% Modulation
mod_symbols = qammod(codedBits, ModulationOrder, ‘InputType’, ‘bit’, ‘UnitAveragePower’, true);
%% Ensure the number of symbols can be reshaped properly
numSymbols = length(mod_symbols);
paddingSymbols = mod(numAntennasTx – mod(numSymbols, numAntennasTx), numAntennasTx);
mod_symbols_padded = [mod_symbols; zeros(paddingSymbols, 1)];
%% Reshape modulated symbols to fit Tx antennas
mod_symbols_reshaped = reshape(mod_symbols_padded, numAntennasTx, []);
%% Precoding
H = (randn(numAntennasRx, numAntennasTx) + 1i * randn(numAntennasRx, numAntennasTx)) / sqrt(2*numAntennasRx); % Channel matrix
% Regularized Zero Forcing (RZF) Precoding
lambda = 0.01; % Regularization parameter
WRZF = (H’ / (H*H’ + lambda*eye(numAntennasRx)));
% Phased Zero Forcing (PZF) Precoding
angle_H = angle(H);
phase_shift = exp(-1i*angle_H);
H_pzf = H .* phase_shift;
WPZF = (H_pzf’ / (H_pzf*H_pzf’));
%% Apply Precoding
size(WRZF)
size(mod_symbols_reshaped)
precodedBitsRZF = WRZF * mod_symbols_reshaped; % precoding RZF
precodedBitsPZF = WPZF * mod_symbols_reshaped; % precoding PZF
%% Without Precoding
precodedBitsWP = mod_symbols_reshaped; % No precoding
%% OFDM Modulation with Precoding
OfdmSymbolsRZF = ifft(precodedBitsRZF, [], 2); % OFDM modulation with RZF precoding
OfdmSymbolsPZF = ifft(precodedBitsPZF, [], 2); % OFDM modulation with PZF precoding
OfdmSymbolsWP = ifft(precodedBitsWP, [], 2); % OFDM modulation without precoding
%% Channel AWGN
berRZF = zeros(1, length(snrValues)); % Initialize BER results for RZF
berPZF = zeros(1, length(snrValues)); % Initialize BER results for PZF
berWP = zeros(1, length(snrValues)); % Initialize BER results for no precoding
for i = 1:length(snrValues)
snr = snrValues(i);
noiseVar = 1 / (10^(snr/10));
% Transmit through channel (AWGN) for RZF
rxSymbolsRZF = awgn(H * OfdmSymbolsRZF, snr, ‘measured’) + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsRZF)) + 1i * randn(size(OfdmSymbolsRZF)));
% Transmit through channel (AWGN) for PZF
rxSymbolsPZF = awgn(H * OfdmSymbolsPZF, snr, ‘measured’) + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsPZF)) + 1i * randn(size(OfdmSymbolsPZF)));
% Transmit through channel (AWGN) without precoding
rxSymbolsWP = awgn(H * OfdmSymbolsWP, snr, ‘measured’) + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsWP)) + 1i * randn(size(OfdmSymbolsWP)));
%% OFDM Demodulation
% Serial to Parallel Conversion
receivedSymbolsRZFSerial = reshape(rxSymbolsRZF, [], numAntennasRx).’; % Serial to parallel conversion
receivedSymbolsPZFSerial = reshape(rxSymbolsPZF, [], numAntennasRx).’; % Serial to parallel conversion
receivedSymbolsWPSerial = reshape(rxSymbolsWP, [], numAntennasRx).’; % Serial to parallel conversion
% Perform OFDM demodulation for RZF
rxSymbolsIFFTRZF = fft(receivedSymbolsRZFSerial, [], 2); % FFT
% Perform OFDM demodulation for PZF
rxSymbolsIFFTPZF = fft(receivedSymbolsPZFSerial, [], 2); % FFT
% Perform OFDM demodulation for no precoding
rxSymbolsIFFTWP = fft(receivedSymbolsWPSerial, [], 2); % FFT
%% Parallel to Serial Conversion
rxSymbolsDemod_RZF = reshape(rxSymbolsIFFTRZF.’, [], 1); % Parallel to serial conversion
rxSymbolsDemod_PZF = reshape(rxSymbolsIFFTPZF.’, [], 1); % Parallel to serial conversion
rxSymbolsDemod_WP = reshape(rxSymbolsIFFTWP.’, [], 1); % Parallel to serial conversion
% Remove the padded symbols before demodulation
rxSymbolsDemod_RZF = rxSymbolsDemod_RZF(1:end-paddingSymbols);
rxSymbolsDemod_PZF = rxSymbolsDemod_PZF(1:end-paddingSymbols);
rxSymbolsDemod_WP = rxSymbolsDemod_WP(1:end-paddingSymbols);
% QAM demodulation
demodBitsRZF = qamdemod(rxSymbolsDemod_RZF, ModulationOrder, ‘OutputType’, ‘bit’, ‘UnitAveragePower’, true);
demodBitsPZF = qamdemod(rxSymbolsDemod_PZF, ModulationOrder, ‘OutputType’, ‘bit’, ‘UnitAveragePower’, true);
demodBitsWP = qamdemod(rxSymbolsDemod_WP, ModulationOrder, ‘OutputType’, ‘bit’, ‘UnitAveragePower’, true);
% Calculate the Bit Error Rate (BER)
berRZF(i) = sum(demodBitsRZF ~= codedBits(1:end-paddingSymbols)) / numBits;
berPZF(i) = sum(demodBitsPZF ~= codedBits(1:end-paddingSymbols)) / numBits;
berWP(i) = sum(demodBitsWP ~= codedBits(1:end-paddingSymbols)) / numBits;
end
%% Display Results
fprintf(‘Bit Error Rate (RZF Precoding):n’);
disp(berRZF);
fprintf(‘Bit Error Rate (PZF Precoding):n’);
disp(berPZF);
fprintf(‘Bit Error Rate (Without Precoding):n’);
disp(berWP);
%% Plotting the results
figure;
semilogy(snrValues, berRZF, ‘bs-‘, ‘LineWidth’, 2);
hold on;
semilogy(snrValues, berPZF, ‘gs-‘, ‘LineWidth’, 2);
semilogy(snrValues, berWP, ‘rs-‘, ‘LineWidth’, 2);
xlabel(‘SNR (dB)’);
ylabel(‘Bit Error Rate (BER)’);
legend(‘RZF Precoding’, ‘PZF Precoding’, ‘Without Precoding’);
title(‘Massive MIMO 256×16 Antennas with RZF and PZF Precoding’);
grid on; here’s the full code
numAntennasTx = 256; % Number of antennasTx
numAntennasRx = 16; % Number of antennasRx
numBits = 10000000; % Number of random bits
ModulationOrder = 16; % 16QAM
snrValues = 0:5:40; % Range of SNR values
%% Generate Random Bits
bits = randi([0 1], numBits, 1);
%% Convolutional Encoding
trellis = poly2trellis(7, [171 133]); % Example trellis
codedBits = convenc(bits, trellis);
%% Modulation
mod_symbols = qammod(codedBits, ModulationOrder, ‘InputType’, ‘bit’, ‘UnitAveragePower’, true);
%% Ensure the number of symbols can be reshaped properly
numSymbols = length(mod_symbols);
paddingSymbols = mod(numAntennasTx – mod(numSymbols, numAntennasTx), numAntennasTx);
mod_symbols_padded = [mod_symbols; zeros(paddingSymbols, 1)];
%% Reshape modulated symbols to fit Tx antennas
mod_symbols_reshaped = reshape(mod_symbols_padded, numAntennasTx, []);
%% Precoding
H = (randn(numAntennasRx, numAntennasTx) + 1i * randn(numAntennasRx, numAntennasTx)) / sqrt(2*numAntennasRx); % Channel matrix
% Regularized Zero Forcing (RZF) Precoding
lambda = 0.01; % Regularization parameter
WRZF = (H’ / (H*H’ + lambda*eye(numAntennasRx)));
% Phased Zero Forcing (PZF) Precoding
angle_H = angle(H);
phase_shift = exp(-1i*angle_H);
H_pzf = H .* phase_shift;
WPZF = (H_pzf’ / (H_pzf*H_pzf’));
%% Apply Precoding
size(WRZF)
size(mod_symbols_reshaped)
precodedBitsRZF = WRZF * mod_symbols_reshaped; % precoding RZF
precodedBitsPZF = WPZF * mod_symbols_reshaped; % precoding PZF
%% Without Precoding
precodedBitsWP = mod_symbols_reshaped; % No precoding
%% OFDM Modulation with Precoding
OfdmSymbolsRZF = ifft(precodedBitsRZF, [], 2); % OFDM modulation with RZF precoding
OfdmSymbolsPZF = ifft(precodedBitsPZF, [], 2); % OFDM modulation with PZF precoding
OfdmSymbolsWP = ifft(precodedBitsWP, [], 2); % OFDM modulation without precoding
%% Channel AWGN
berRZF = zeros(1, length(snrValues)); % Initialize BER results for RZF
berPZF = zeros(1, length(snrValues)); % Initialize BER results for PZF
berWP = zeros(1, length(snrValues)); % Initialize BER results for no precoding
for i = 1:length(snrValues)
snr = snrValues(i);
noiseVar = 1 / (10^(snr/10));
% Transmit through channel (AWGN) for RZF
rxSymbolsRZF = awgn(H * OfdmSymbolsRZF, snr, ‘measured’) + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsRZF)) + 1i * randn(size(OfdmSymbolsRZF)));
% Transmit through channel (AWGN) for PZF
rxSymbolsPZF = awgn(H * OfdmSymbolsPZF, snr, ‘measured’) + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsPZF)) + 1i * randn(size(OfdmSymbolsPZF)));
% Transmit through channel (AWGN) without precoding
rxSymbolsWP = awgn(H * OfdmSymbolsWP, snr, ‘measured’) + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsWP)) + 1i * randn(size(OfdmSymbolsWP)));
%% OFDM Demodulation
% Serial to Parallel Conversion
receivedSymbolsRZFSerial = reshape(rxSymbolsRZF, [], numAntennasRx).’; % Serial to parallel conversion
receivedSymbolsPZFSerial = reshape(rxSymbolsPZF, [], numAntennasRx).’; % Serial to parallel conversion
receivedSymbolsWPSerial = reshape(rxSymbolsWP, [], numAntennasRx).’; % Serial to parallel conversion
% Perform OFDM demodulation for RZF
rxSymbolsIFFTRZF = fft(receivedSymbolsRZFSerial, [], 2); % FFT
% Perform OFDM demodulation for PZF
rxSymbolsIFFTPZF = fft(receivedSymbolsPZFSerial, [], 2); % FFT
% Perform OFDM demodulation for no precoding
rxSymbolsIFFTWP = fft(receivedSymbolsWPSerial, [], 2); % FFT
%% Parallel to Serial Conversion
rxSymbolsDemod_RZF = reshape(rxSymbolsIFFTRZF.’, [], 1); % Parallel to serial conversion
rxSymbolsDemod_PZF = reshape(rxSymbolsIFFTPZF.’, [], 1); % Parallel to serial conversion
rxSymbolsDemod_WP = reshape(rxSymbolsIFFTWP.’, [], 1); % Parallel to serial conversion
% Remove the padded symbols before demodulation
rxSymbolsDemod_RZF = rxSymbolsDemod_RZF(1:end-paddingSymbols);
rxSymbolsDemod_PZF = rxSymbolsDemod_PZF(1:end-paddingSymbols);
rxSymbolsDemod_WP = rxSymbolsDemod_WP(1:end-paddingSymbols);
% QAM demodulation
demodBitsRZF = qamdemod(rxSymbolsDemod_RZF, ModulationOrder, ‘OutputType’, ‘bit’, ‘UnitAveragePower’, true);
demodBitsPZF = qamdemod(rxSymbolsDemod_PZF, ModulationOrder, ‘OutputType’, ‘bit’, ‘UnitAveragePower’, true);
demodBitsWP = qamdemod(rxSymbolsDemod_WP, ModulationOrder, ‘OutputType’, ‘bit’, ‘UnitAveragePower’, true);
% Calculate the Bit Error Rate (BER)
berRZF(i) = sum(demodBitsRZF ~= codedBits(1:end-paddingSymbols)) / numBits;
berPZF(i) = sum(demodBitsPZF ~= codedBits(1:end-paddingSymbols)) / numBits;
berWP(i) = sum(demodBitsWP ~= codedBits(1:end-paddingSymbols)) / numBits;
end
%% Display Results
fprintf(‘Bit Error Rate (RZF Precoding):n’);
disp(berRZF);
fprintf(‘Bit Error Rate (PZF Precoding):n’);
disp(berPZF);
fprintf(‘Bit Error Rate (Without Precoding):n’);
disp(berWP);
%% Plotting the results
figure;
semilogy(snrValues, berRZF, ‘bs-‘, ‘LineWidth’, 2);
hold on;
semilogy(snrValues, berPZF, ‘gs-‘, ‘LineWidth’, 2);
semilogy(snrValues, berWP, ‘rs-‘, ‘LineWidth’, 2);
xlabel(‘SNR (dB)’);
ylabel(‘Bit Error Rate (BER)’);
legend(‘RZF Precoding’, ‘PZF Precoding’, ‘Without Precoding’);
title(‘Massive MIMO 256×16 Antennas with RZF and PZF Precoding’);
grid on; transferred MATLAB Answers — New Questions