Error regarding array while creating Nakagami-m Fading Model

3 visualizaciones (últimos 30 días)
Muhammad Omama
Muhammad Omama el 7 de Mayo de 2023
Respondida: the cyclist el 7 de Mayo de 2023
I have writen this code and have found an error as shown below,
%% Signal parameters
bit_rate = 900e6; % bit rate in bits per second
samples_per_bit = 32; % number of samples per bit
carrier_freq = 1200e6; % carrier frequency in Hz
symbol_rate = bit_rate / log2(16); % symbol rate in symbols per second
symbols_per_bit = samples_per_bit / log2(16); % number of symbols per bit
rolloff = 0.5; % pulse shaping rolloff factor
span = 6; % pulse shaping filter span in symbols
sps = 4; % samples per symbol for pulse shaping
%% Generate random data
num_bits = 1e6; % number of bits to transmit
data = randi([0 1], num_bits, 1); % generate random binary data
%% Modulate data
tx_symbols = qammod(data, 16); % modulate data using 16-QAM
%% Pulse shaping
tx_filter = rcosdesign(rolloff, span, sps); % generate pulse shaping filter
tx_waveform = upfirdn(tx_symbols, tx_filter, sps); % apply pulse shaping filter
%% Add carrier and transmit waveform
t = (0:length(tx_waveform)-1) / bit_rate; % time vector
carrier = exp(1j * 2 * pi * carrier_freq * t); % generate carrier waveform
tx_waveform = real(tx_waveform .* carrier.'); % modulate waveform onto carrier
%% Simulate Nakagami-m fading channel
m = 1.5; % Nakagami-m fading parameter
snr_db = 20; % SNR in dB
snr = 10^(snr_db / 10); % convert SNR to linear scale
rx_waveform = nakagami_fading(tx_waveform, snr, m); % apply Nakagami-m fading
%% Demodulate data
rx_symbols = rx_waveform ./ carrier.'; % demodulate waveform
rx_data = qamdemod(rx_symbols, 16); % demodulate symbols into binary data
%% Compute BER
ber = sum(data ~= rx_data) / num_bits; % compute bit error rate
fprintf('Bit error rate: %g\n', ber);
%% Nakagami-m fading function
function [rx_waveform] = nakagami_fading(tx_waveform, snr, m)
h = (randn(size(tx_waveform)) + 1j * randn(size(tx_waveform))) / sqrt(2); % generate Rayleigh fading channel
g = sqrt(gamrnd(m, 1/m, size(tx_waveform))); % generate Nakagami-m fading envelope
n = sqrt(1 / (2 * snr)) * (randn(size(tx_waveform)) + 1j * randn(size(tx_waveform))); % generate Gaussian noise
rx_waveform = g .* h .* tx_waveform + n; % apply fading and noise
end
Arrays have incompatible sizes for this operation.
Error in untitled (line 38)
ber = sum(data ~= rx_data) / num_bits; % compute bit error rate
How to fix this error?

Respuestas (1)

the cyclist
the cyclist el 7 de Mayo de 2023
If you use the MATLAB debugger, and stop your code just before that line, you'll see that the variable data and rx_data are not the same size, and therefore cannot be compare with the ~= operator.

Categorías

Más información sobre Test and Measurement en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by