Professional Documents
Culture Documents
11
Analyze BER versus SNR performance for OFDM with BPSK in AWGN
channel.
MATLAB Program:
% Script for computing the Bit Error probability using OFDM with BPSK modulation.
clc; clear all; close all;
format long;
nFFT = 64; % fft size
nDSC = 64; % number of data subcarriers
nBitPerSym = 64; % number of bits per OFDM symbol
% (same as the number of subcarriers for BPSK)
nSym = 10^4; % number of OFDM symbols
EbN0dB =[0:10]; % bit to noise ratio
theoryBer = (1/2)*erfc(sqrt(10.^(EbN0dB/10)));
for k = 1:length(EbN0dB)
% Transmitter
ipBit=randi([0 1],1,nBitPerSym*nSym);
ipMod = 2*ipBit-1; % BPSK modulation 0 --> -1, 1 --> +1
ipMod = reshape(ipMod,nBitPerSym,nSym).'; % grouping into multiple symbols
% Assigning modulated symbols to subcarriers
xF =ipMod;
% Taking FFT, the term (nFFT/sqrt(nDSC)) is for
% normalizing the power of transmit symbol to 1
xt = (nFFT/sqrt(nDSC))*ifft(fftshift(xF.')).';
% Parallel to serial
xt = reshape(xt.',1,nSym*nFFT);
% Gaussian noise of unit variance, 0 mean
nt = 1/sqrt(2)*[randn(1,nSym* nFFT) + j*randn(1,nSym* nFFT)];
% Adding noise
yt = xt + 10^(-EbN0dB(k)/20)*nt;
% Receiver serial to parallel
yt = reshape(yt.', nFFT,nSym).';
% converting to frequency domain
yF = fftshift(fft(yt.')).';
%Parallel to serial
yMod = reshape(yF.',1,nSym* nFFT);
%Hard decision decoding for BPSK demodulation
ipBitHat = (sign(real(yMod))+1)/2;
% counting the errors
nErr = sum(xor(ipBitHat,ipBit));
simBer(k) = nErr/(nSym*nBitPerSym);
[EbN0dB(k) theoryBer(k) simBer(k)];
end
figure(1);
semilogy(EbN0dB,theoryBer,'bd',EbN0dB,simBer);
1
legend('Analytical','Simulation results for OFDM');
xlabel('SNR(Eb/No)dB');
ylabel('Bit Error Rate (BER)');
title('Bit Error probability using OFDM with BPSK modulation');
Interpretation: The above plot shows the BER vs SNR curve using OFDM with BPSK modulation.
Questions:
(1) Draw the block diagram of transmitter and receiver with OFDM.
A. 1
2
(2) What is the advantage of OFDM compared to FDM.
A. 2
A. 3
3
(4) Use MPSK and MQAM in the system and plot BER versus SNR.
A.4
nberr=0;
numErrs = 0; numBits = 0; results=zeros(3,1);
4
AWGN.EbNo=SNR(k);
while ((numErrs < maxNumErrs) && (numBits < maxNumBits))
% Transmitter
u = randi([0 1], FRM,1); % Random bits generator
mod_sig = Modulator.step(u); % QPSK Modulator
% Channel
ipMod = reshape(mod_sig',nBitPerSym,nSym).'; % grouping
% into multiple symbols
% Assigning modulated symbols to subcarriers
xF =ipMod;
% Taking FFT, the term (nFFT/sqrt(nDSC)) is for
% normalizing the power of transmit symbol to 1
xt = (nFFT/sqrt(nDSC))*ifft(fftshift(xF.')).';
% Parallel to serial
xt = reshape(xt.',1,nSym*nFFT);
% Gaussian noise of unit variance, 0 mean
nt = 1/sqrt(2)*[randn(1,nSym* nFFT) + j*randn(1,nSym*nFFT)];
% Adding noise
yt = xt + 10^(-EbN0dB(k)/20)*nt;
% Receiver serial to parallel
yt = reshape(yt.', nFFT,nSym).';
% converting to frequency domain
yF = fftshift(fft(yt.')).';
%Parallel to serial
yMod = reshape(yF.',1,nSym* nFFT);
%Hard decision decoding for BPSK demodulation
rx_sig = AWGN.step(mod_sig); % AWGN channel
% Receiver
demod = DeModulator.step(rx_sig); % QPSK Demodulator
ipBitHat = demod(1:FRM); % Compute output bits
results = BitError.step(u, ipBitHat); % Update BER
numErrs = results(2);
numBits = results(3);
end
%% Clean up & collect results
ber(k) = results(1);
reset(BitError);
[EbN0dB(k) ber(k)];
end
figure(1);
semilogy(EbN0dB,ber,'b');
legend('Simulation');
xlabel('SNR(Eb/No)dB');
ylabel('Bit Error Rate (BER)');
title('OFDM using MPSK');
5
% OFDM using MQAM:
clc; clear all; close all;
format long;
nFFT = 64; % fft size
nDSC = 64; % number of data subcarriers
Warning: COMM.RECTANGULARQAMMODULATOR will be removed in a future release. Use QAMMOD instead. See
this release note for more information.
AWGN = comm.AWGNChannel;
DeModulator = comm.RectangularQAMDemodulator(M,'BitOutput',true);
BitError = comm.ErrorRate;
6
SNR = EbN0dB + 10*log10(K);
for k = 1:length(EbN0dB)
% Transmitter
ipBit=randi([0 1],1,nBitPerSym*nSym);
nberr=0;
numErrs = 0; numBits = 0; results=zeros(3,1);
AWGN.EbNo=SNR(k);
while ((numErrs < maxNumErrs) && (numBits < maxNumBits))
% Transmitter
u = randi([0 1], FRM,1); % Random bits generator
mod_sig = Modulator.step(u); % QPSK Modulator
% Channel
ipMod = reshape(mod_sig',nBitPerSym,nSym).'; % grouping
% into multiple symbols
% Assigning modulated symbols to subcarriers
xF =ipMod;
% Taking FFT, the term (nFFT/sqrt(nDSC)) is for normalizing
% the power of transmit symbol to 1
xt = (nFFT/sqrt(nDSC))*ifft(fftshift(xF.')).';
% Parallel to serial
xt = reshape(xt.',1,nSym*nFFT);
% Gaussian noise of unit variance, 0 mean
nt = 1/sqrt(2)*[randn(1,nSym* nFFT) + j*randn(1,nSym* nFFT)];
% Adding noise
yt = xt + 10^(-EbN0dB(k)/20)*nt;
% Receiver serial to parallel
yt = reshape(yt.', nFFT,nSym).';
% converting to frequency domain
yF = fftshift(fft(yt.')).';
%Parallel to serial
yMod = reshape(yF.',1,nSym* nFFT);
%Hard decision decoding for BPSK demodulation
rx_sig = AWGN.step(mod_sig); % AWGN channel
% Receiver
demod = DeModulator.step(rx_sig); % QPSK Demodulator
ipBitHat = demod(1:FRM); % Compute output bits
results = BitError.step(u, ipBitHat); % Update BER
numErrs = results(2);
numBits = results(3);
end
%% Clean up & collect results
ber(k) = results(1);
reset(BitError);
[EbN0dB(k) ber(k)];
end
figure(1);
semilogy(EbN0dB,ber,'b');
legend('For M=16');
xlabel('SNR(Eb/No)dB');
ylabel('Bit Error Rate (BER)');
title('OFDM using MQAM');
7
(5) Use (7,4) block code and convolutional code and respective decoder. Plot BER versus SNR in AWGN with
OFDM.
8
while ((numErrs < maxNumErrs) && (numBits < maxNumBits))
% Transmitter
ipBit=randi([0 1],1,nBitPerSym*nSym);
x_cod = encode(ipBit,n,K,'linear/binary',genmat);
ipMod1 = 2*x_cod-1; % BPSK modulation 0 --> -1, 1 --> +1
ipMod = reshape(ipMod1,nBitPerSym*1.75,nSym).'; % grouping
% into multiple symbols
% Assigning modulated symbols to subcarriers
xF =ipMod;
% Taking FFT, the term (nFFT/sqrt(nDSC)) is for normalizing the
% power of transmit symbol to 1
xt1 = (nFFT/sqrt(nDSC))*ifft(fftshift(xF.')).';
% Parallel to serial
xt = reshape(xt1.',1,nSym*nFFT*1.75);
% Gaussian noise of unit variance, 0 mean
nt = 1/sqrt(2)*[randn(1,nSym* nFFT*1.75) + j*randn(1,nSym*nFFT*1.75)];
% Adding noise
yt = xt + 10^(-EbNo(k)/20)*nt;
% Receiver serial to parallel
yt = reshape(yt.', 1.75*nFFT,nSym).';
% converting to frequency domain
yF = fftshift(fft(yt.')).';
%Parallel to serial
yMod = reshape(yF.',1,nSym* nFFT*1.75);
%Hard decision decoding for BPSK demodulation
ipBitHat = (sign(real(yMod))+1)/2;
x_recov= decode(ipBitHat,n,K,'linear/binary',genmat);
berr=xor(ipBit,x_recov);
sberr=sum(sum(berr));
numErrs=numErrs+sberr;
numBits=numBits+Frame;
end
bep(k)=numErrs/numBits;
[EbNo(k) bep(k)];
end
figure(1);
semilogy(EbNo,bep);
legend('(7,4) Block Code');
xlabel('SNR(Eb/No)dB');
ylabel('Bit Error Rate (BER)');
title(' BER versus SNR in AWGN with OFDM');
9
Conclusions: The critical learnings and findings of this experiment are:
10