bits = randi([0 1], numBits, 1);
trellis = poly2trellis(7, [171 133]);
codedBits = convenc(bits, trellis);
mod_symbols = qammod(codedBits, ModulationOrder, 'InputType', 'bit', 'UnitAveragePower', true);
numSymbols = length(mod_symbols);
paddingSymbols = mod(numAntennasTx - mod(numSymbols, numAntennasTx), numAntennasTx);
mod_symbols_padded = [mod_symbols; zeros(paddingSymbols, 1)];
mod_symbols_reshaped = reshape(mod_symbols_padded, numAntennasTx, []);
H = (randn(numAntennasRx, numAntennasTx) + 1i * randn(numAntennasRx, numAntennasTx)) / sqrt(2*numAntennasRx);
WRZF = (H' / (H*H' + lambda*eye(numAntennasRx)));
phase_shift = exp(-1i*angle_H);
H_pzf = H .* phase_shift;
WPZF = (H_pzf' / (H_pzf*H_pzf'));
size(WRZF)
ans =
256 16
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
size(mod_symbols_reshaped)
ans =
256 19532
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
precodedBitsRZF = WRZF * mod_symbols_reshaped;
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 operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.
precodedBitsPZF = WPZF * mod_symbols_reshaped;
precodedBitsWP = mod_symbols_reshaped;
OfdmSymbolsRZF = ifft(precodedBitsRZF, [], 2);
OfdmSymbolsPZF = ifft(precodedBitsPZF, [], 2);
OfdmSymbolsWP = ifft(precodedBitsWP, [], 2);
berRZF = zeros(1, length(snrValues));
berPZF = zeros(1, length(snrValues));
berWP = zeros(1, length(snrValues));
for i = 1:length(snrValues)
noiseVar = 1 / (10^(snr/10));
rxSymbolsRZF = awgn(H * OfdmSymbolsRZF, snr, 'measured') + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsRZF)) + 1i * randn(size(OfdmSymbolsRZF)));
rxSymbolsPZF = awgn(H * OfdmSymbolsPZF, snr, 'measured') + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsPZF)) + 1i * randn(size(OfdmSymbolsPZF)));
rxSymbolsWP = awgn(H * OfdmSymbolsWP, snr, 'measured') + sqrt(noiseVar/2) * (randn(size(OfdmSymbolsWP)) + 1i * randn(size(OfdmSymbolsWP)));
receivedSymbolsRZFSerial = reshape(rxSymbolsRZF, [], numAntennasRx).';
receivedSymbolsPZFSerial = reshape(rxSymbolsPZF, [], numAntennasRx).';
receivedSymbolsWPSerial = reshape(rxSymbolsWP, [], numAntennasRx).';
rxSymbolsIFFTRZF = fft(receivedSymbolsRZFSerial, [], 2);
rxSymbolsIFFTPZF = fft(receivedSymbolsPZFSerial, [], 2);
rxSymbolsIFFTWP = fft(receivedSymbolsWPSerial, [], 2);
rxSymbolsDemod_RZF = reshape(rxSymbolsIFFTRZF.', [], 1);
rxSymbolsDemod_PZF = reshape(rxSymbolsIFFTPZF.', [], 1);
rxSymbolsDemod_WP = reshape(rxSymbolsIFFTWP.', [], 1);
rxSymbolsDemod_RZF = rxSymbolsDemod_RZF(1:end-paddingSymbols);
rxSymbolsDemod_PZF = rxSymbolsDemod_PZF(1:end-paddingSymbols);
rxSymbolsDemod_WP = rxSymbolsDemod_WP(1:end-paddingSymbols);
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);
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;
fprintf('Bit Error Rate (RZF Precoding):\n');
fprintf('Bit Error Rate (PZF Precoding):\n');
fprintf('Bit Error Rate (Without Precoding):\n');
semilogy(snrValues, berRZF, 'bs-', 'LineWidth', 2);
semilogy(snrValues, berPZF, 'gs-', 'LineWidth', 2);
semilogy(snrValues, berWP, 'rs-', 'LineWidth', 2);
ylabel('Bit Error Rate (BER)');
legend('RZF Precoding', 'PZF Precoding', 'Without Precoding');
title('Massive MIMO 256x16 Antennas with RZF and PZF Precoding');