Effacer les filtres
Effacer les filtres

OFDM transmitter and receiver BER value

16 vues (au cours des 30 derniers jours)
Jose Iglesias
Jose Iglesias le 24 Avr 2023
Commenté : Jose Iglesias le 19 Mai 2023
Need assistance in updating my code to remove an error I keep getting. The OFDM transmission and receiver Matlab code is shown below. This is the error I keep getting:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in ofdm_bpsk_ji_7 (line 93)
BER(i) = BER(i) + ber; % accumulate BER over all symbols
I need to come up with a better way of updating BER value for current SNR values.
Please help me to correct this line of code so this error is no longer occurring. Thanks in advance!
clear all;
close all;
% Initiation
no_of_data_bits = 64;
M = 64; %Number of subcarrier channel
n = 256; %Total number of bits to be transmitted at transmitter
block_size = 64; %Size of each OFDM block to add cyclic prefix
cp_len = round(0.25*block_size); %Length of cyclic prefix
% Initiate SNR range and BER array
SNR_range = -10:1:10;
BER = zeros(size(SNR_range));
% Read the video file
video = VideoReader('pexels-pixabay-856027-960x540-25fps.mp4');
% Calculate the total number of bits in the video
total_bits = 0;
% Initialize error count for all frames
error_count = 0;
% Loop through each frame of the video and convert it to a binary data stream
while hasFrame(video)
frame = readFrame(video);
decimal_data = reshape(frame,numel(frame),1);
binary_data = reshape(de2bi(decimal_data,8)',[],1);
% Increment total_bits
total_bits = total_bits + numel(binary_data);
% Loop over SNR range
for i = 1:length(SNR_range)
% Loop through each symbol
for j = 1:numel(binary_data)/no_of_data_bits
% Use the binary data as the input source data
data = binary_data((j-1)*no_of_data_bits+1:j*no_of_data_bits);
% Perform BPSK modulation on the input source data
bpsk_modulated_data = pskmod(data,2);
% Converting the series data stream into parallel data stream to form subcarriers
S2P = reshape(bpsk_modulated_data,no_of_data_bits/M,M);
% Generate channel
channel_len = 10;
channel = (randn(1, channel_len) + 1i * randn(1, channel_len)) / sqrt(2);
% Zero-padding
channel_padded = [channel, zeros(1, block_size - length(channel))];
% IFFT of subcarriers and add cyclic prefix
number_of_subcarriers = M;
% IFFT does parallel to serial conversion
ifft_Subcarrier = ifft(S2P, block_size);
% Add cyclic prefix
cyclic_prefix = ifft_Subcarrier(:,end-cp_len+1:end);
Append_prefix = [cyclic_prefix ifft_Subcarrier];
% Multipath channel
rcvd_symbol = filter(channel,1,Append_prefix);
% Calculate noise variance for current SNR
snr = SNR_range(i);
noise_var = 1 / (10^(snr/10));
% Generate noisy channel coefficients
noisy_symbol = rcvd_symbol + sqrt(noise_var/2)*(randn(1,80)+1i*randn(1,80));
% Remove cyclic prefix at the receiver
rx_no_cp = noisy_symbol(cp_len+1:end);
% Perform FFT on received data
rx_fft = fft(rx_no_cp, block_size);
% FFT on the channel
channel_fft = fft(channel_padded);
% Equalize channel effect
rx_equalized = rx_fft ./ channel_fft;
% Perform BPSK demodulation
rx_demod = pskdemod(rx_equalized(:), 2); % (:) used to create vectors
% Calculate bit error rate
ber = sum(rx_demod ~= data.') / numel(data);
% Update BER value for current SNR value
BER(i) = BER(i) + ber; % accumulate BER over all symbols
% Divide the accumulated BER by the total number of symbols to get the average BER for this SNR
BER = BER / (total_bits/no_of_data_bits);
% Plot BER vs SNR
semilogy(SNR_range, BER, 'o-');
grid on;
xlabel('SNR (dB)');
ylabel('Bit Error Rate');
title('Probability of Error vs SNR');

Réponses (1)

Harsh le 15 Mai 2023
Hi Jose,
I understand that you are facing an error while assigning computed "ber" value to the "BER" vector index.
The error you are facing is shown when dimension of left and right of the assignment operator are not same.
Therefore, kindly ensure that variable "rx_demod" and "data" have same dimension before computing variable "ber". This measure should resolve the error.




Community Treasure Hunt

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

Start Hunting!

Translated by