OFDM Transmitter and Receiver using QPSK Modulation

조회 수: 11 (최근 30일)
Lincoln
Lincoln 2023년 12월 9일
편집: vidyesh 2023년 12월 26일
I am trying to build a simple OFDM Transmitter and Receiver using QPSK modulation.
The steps I am taking:
Transmitter:
  1. Generating random bits
  2. QPSK Modulation
  3. Reshaping from Serial to Parallel
  4. Matching to OFDM subcarriers
  5. Performing IFFT
  6. Append Cyclic Prefix
  7. Reshape from Parallel to Serial
AWGN:
1. Add AWGN to (7)
Receiver:
  1. Reshape from Serial to Parallel
  2. Remove Cyclic Prefix
  3. Performing FFT
  4. QPSK Demodulation
  5. Compare number of errors
Using (5), I divide by the total length of generated bits to obtain my BER. I hope to compare theoretical BER with my simulation but unfortunately, they are not matching and I am unsure why.
Any help will be greatly appreciated
% Script for computing the Bit Error probability using OFDM modulation
clear all
nFFT = 64; % fft size
t1=26; % number of data subcarriers (should be even)
cp1=16; % number of cylic prefix
nDSC = t1; % number of data subcarriers
nBitPerSym = t1 * 2; % number of bits per OFDM symbol
nSym = 10^2; % number of symbols
t2=nFFT+cp1;
EbN0dB = [0:2:10]; % bit to noise ratio
EsN0dB = EbN0dB + 10*log10(nDSC/nFFT) + 10*log10(nFFT/t2); % converting to symbol to noise ratio
nErr = zeros(1, length(EbN0dB));
for ii = 1:length(EbN0dB)
% Transmitter
% Generate random binary data (2 bits per symbol for QPSK)
ipBit = randn(1, nBitPerSym*nSym * 2) >= 0;
oddData = ipBit(1:2:end);
evenData = ipBit(2:2:end);
qpskModulated = sqrt(1/2) * (1i * (2 * oddData - 1) + (2 * evenData - 1));
% Reshape the binary data into pairs of bits
ipMod = reshape(qpskModulated, nBitPerSym, nSym).';
sz1=nFFT-nBitPerSym;
% Assigning modulated symbols to subcarriers from [-26 to -1, +1 to +26]
xF = [zeros(nSym,sz1/2) ipMod(:,[1:nBitPerSym/2]) zeros(nSym,1) ipMod(:,[nBitPerSym/2+1:nBitPerSym]) zeros(nSym,sz1/2-1)] ;
% Taking FFT, the term (nFFT/sqrt(nDSC)) is for normalizing the power of transmit symbol to 1
xt = (nFFT/sqrt(nDSC))*ifft((xF.')).';
% Appending cylic prefix
xt = [xt(:,[nFFT-cp1+1:nFFT]) xt];
[R_xt,col_xt] = size(xt);
% Concatenating multiple symbols to form a long vector (parallel to serial)
xt = reshape(xt.',1,nSym*col_xt);
% Gaussian noise of unit variance, 0 mean
nt = 1/sqrt(2)*[randn(1,nSym*col_xt) + 1i * randn(1,nSym*col_xt)];
% Adding noise, the term sqrt(80/64) is to account for the wasted energy due to cyclic prefix
yt = sqrt(col_xt/nFFT)*xt + 10^(-EsN0dB(ii)/20)*nt;
% Receiver
yt = reshape(yt.',col_xt,nSym).'; % formatting the received vector into symbols (serial to parallel)
yt = yt(:,[cp1+1:col_xt]); % removing cyclic prefix
% converting to frequency domain
yF = (sqrt(nDSC)/nFFT)*(fft(yt.')).';
%yMod = reshape(yF.', 1, []);
yMod = yF(:,[sz1/2+[1:nBitPerSym/2] sz1/2+1+[nBitPerSym/2+1:nBitPerSym] ]);
% QPSK demodulation
detected_real = real(yMod) >= 0;
detected_img = imag(yMod) >= 0;
estimatedBits = reshape([detected_img;detected_real], 1, []);
nErr(ii) = sum(xor(ipBit, estimatedBits));
end
theoryBer = 0.5*erfc(sqrt(10.^(EbN0dB/10)));
simBer = nErr/length(ipBit);
%theoryBer = (1/2)*erfc(sqrt(10.^(EbN0dB/10)));
L_N=(cp1/nFFT)*10.^(EbN0dB/10);
% theoryBer_OFDM=(1/2)*erfc(1-sqrt(L_N./(2+L_N)));
%close all; figure
semilogy(EbN0dB,theoryBer,'bs-','LineWidth',2);
hold on
% semilogy(EbN0dB,theoryBer_OFDM,'kd','LineWidth',2);
semilogy(EbN0dB,simBer,'mx-','LineWidth',2);
axis([0 10 10^-5 1])
grid on
legend('theory', 'simulation');
xlabel('Eb/No, dB')
ylabel('Bit Error Rate')
title('Bit error probability curve for QPSK using OFDM'

답변 (1개)

vidyesh
vidyesh 2023년 12월 26일
편집: vidyesh 2023년 12월 26일
Hi Lincoln,
I understand that you're facing an issue where the Bit Error Rate (BER) in your simulation does not decrease with increasing Signal-to-Noise Ratio (SNR), and you're seeking clarification on this behaviour.
The procedure followed is correct; however, a discrepancy exists in the final step before calculating the error, where the 'detected_real' and 'detected_imaginary' arrays are combined to form the 'estimatedBits' matrix. This step needs to be revised to rectify the issue. Alternatively, the code below can be employed to compute the number of errors
det_real = reshape(detected_real', 1, 5200);
det_img = reshape(detected_img', 1, 5200);
nErr(ii) = sum(xor(evenData, det_real)) + sum(xor(oddData, det_img));
For a deeper understanding of matrix manipulation, specifically the use of the 'reshape' function, the MATLAB documentation can be consulted:
Hope this answer helps

카테고리

Help CenterFile Exchange에서 Test and Measurement에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by