100% found this document useful (1 vote)
255 views2 pages

Ofdm

The document describes simulating a communication system in MATLAB using System objects. It modulates data using QPSK, applies OFDM, transmits over an AWGN channel, then demodulates and calculates bit errors. Key steps are constructing QPSK, OFDM, and channel objects, simulating over a range of SNRs, and comparing simulated and theoretical BER.

Uploaded by

preetik917
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
255 views2 pages

Ofdm

The document describes simulating a communication system in MATLAB using System objects. It modulates data using QPSK, applies OFDM, transmits over an AWGN channel, then demodulates and calculates bit errors. Key steps are constructing QPSK, OFDM, and channel objects, simulating over a range of SNRs, and comparing simulated and theoretical BER.

Uploaded by

preetik917
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

%% QPSK and OFDM with MATLAB System Objects

% This example shows how to simulate a basic communication system in which


% the signal is first QPSK modulated and then subjected to Orthogonal
% Frequency Division Multiplexing. The signal is then passed through an
% additive white Gaussian noise channel prior to being demultiplexed and
% demodulated. Lastly, the number of bit errors are calculated. The example
% showcases the use of MATLAB(R) System objects(TM).
%%
% Set the simulation parameters.
M = 4;
% Modulation alphabet
k = log2(M);
% Bits/symbol
numSC = 128;
% Number of OFDM subcarriers
cpLen = 32;
% OFDM cyclic prefix length
maxBitErrors = 100;
% Maximum number of bit errors
maxNumBits = 1e7;
% Maximum number of bits transmitted
%%
% Construct System objects needed for the simulation: QPSK modulator, QPSK
% demodulator, OFDM modulator, OFDM demodulator, AWGN channel, and an error
% rate calculator. Use name-value pairs to set the object properties.
%%
% Set the QPSK modulator and demodulator so that they accept binary inputs.
qpskMod = comm.QPSKModulator('BitInput',true);
qpskDemod = comm.QPSKDemodulator('BitOutput',true);
%%
% Set the OFDM modulator and demodulator pair according to the
% simulation parameters.
ofdmMod = comm.OFDMModulator('FFTLength',numSC,'CyclicPrefixLength',cpLen);
ofdmDemod = comm.OFDMDemodulator('FFTLength',numSC,'CyclicPrefixLength',cpLen);
%%
% Set the |NoiseMethod| property of the AWGN channel object to
% |Variance| and define the |VarianceSource| property so that the noise power
% can be set from an input port.
channel = comm.AWGNChannel('NoiseMethod','Variance', ...
'VarianceSource','Input port');
%%
% Set the |ResetInputPort| property to |true| to enable the error rate
% calculator to be reset during the simulation.
errorRate = comm.ErrorRate('ResetInputPort',true);
%%
% Use the |info| function of the |ofdmMod| object to determine the input
% and output dimensions of the OFDM modulator.
ofdmDims = info(ofdmMod)
%%
% Determine the number of data subcarriers from the |ofdmDims| structure
% variable.
numDC = ofdmDims.DataInputSize(1)
%%
% Determine the OFDM frame size (in bits) from the number of data
% subcarriers and the number of bits per symbol.
frameSize = [k*numDC 1];
%%
% Set the SNR vector based on the desired Eb/No range, the number of bits
% per symbol, and the ratio of the number of data subcarriers to
% the total number of subcarriers.
EbNoVec = (0:10)';
snrVec = EbNoVec + 10*log10(k) + 10*log10(numDC/numSC);

%%
% Initialize the BER and error statistics arrays.
berVec = zeros(length(EbNoVec),3);
errorStats = zeros(1,3);
%%
% Simulate the communication link over the range of Eb/No values. For each
% Eb/No value, the simulation runs until either |maxBitErrors| are recorded
% or the total number of transmitted bits exceeds |maxNumBits|.
for m = 1:length(EbNoVec)
snr = snrVec(m);
while errorStats(2) <= maxBitErrors && errorStats(3) <= maxNumBits
dataIn = randi([0,1],frameSize);
% Generate binary data
qpskTx = qpskMod(dataIn);
% Apply QPSK modulation
txSig = ofdmMod(qpskTx);
% Apply OFDM modulation
powerDB = 10*log10(var(txSig));
% Calculate Tx signal powe
r
noiseVar = 10.^(0.1*(powerDB-snr));

% Calculate the noise vari

ance
rxSig = channel(txSig,noiseVar);
a noisy channel
qpskRx = ofdmDemod(rxSig);
dataOut = qpskDemod(qpskRx);
errorStats = errorRate(dataIn,dataOut,0);
end

% Pass the signal through


% Apply OFDM demodulation
% Apply QPSK demodulation
% Collect error statistics

berVec(m,:) = errorStats;
% Save BER data
errorStats = errorRate(dataIn,dataOut,1);
% Reset the error rate cal
culator
end
%%
% Use the |berawgn| function to determine the theoretical BER for a QPSK
% system.
berTheory = berawgn(EbNoVec,'psk',M,'nondiff');
%%
% Plot the theoretical and simulated data on the same graph to compare
% results.
figure
semilogy(EbNoVec,berVec(:,1),'*')
hold on
semilogy(EbNoVec,berTheory)
legend('Simulation','Theory','Location','Best')
xlabel('Eb/No (dB)')
ylabel('Bit Error Rate')
grid on
hold off
%%
% Observe that there is good agreement between the simulated and
% theoretical data.
%%
% Copyright 2016, The MathWorks Inc.

You might also like