OFDM probability of error vs SNR
이전 댓글 표시
Need some assistance is possibly troubleshooting my OFDM transmitter and receiver Matlab code shown below. I removed all possible errors and issues I was having when I was initially developing the code. When I run the code there are no errors, but the code was running for many hours and after a while I decided to stop it from running. Does it usually take many hours to produce a BER vs SNR plot for an OFDM with BPSK modulation transmitter and receiver? Any advice is welcome. Again, there are no errors when I run the code, but it never finishes and completes the program. Thank you in advance!
clc;
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 error count array
SNR_range = -10:1:10;
% BER = zeros(size(SNR_range));
errors = zeros(size(SNR_range));
symbols = 0;
% 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);
% errors(i) = errors(i) + sum(rx_demod ~= data.');
errors(i) = errors(i) + sum(rx_demod.' ~= data.');
symbols = symbols + numel(data);
% Update BER value for current SNR value
% BER(i) = BER(i) + ber; % accumulate BER over all symbols
end
end
end
% 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);
% Calculate BER for each SNR
BER = errors ./ symbols
% Plot BER vs SNR
figure(8);
semilogy(SNR_range, BER, 'o-');
grid on;
xlabel('SNR (dB)');
ylabel('Bit Error Rate');
title('Probability of Error vs SNR');
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 OFDM에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!