# Simulation of OFDM system in Matlab – BER Vs Eb/N0 for OFDM in AWGN channel

To simulate an OFDM system, following design parameters are essential. Lets consider the OFDM system parameters as defined in IEEE 802.11^{[1]} specifications

**Given parameters in the spec:**

N=64; **%FFT size or total number of subcarriers (used + unused) 64**

Nsd = 48; **%Number of data subcarriers 48**

Nsp = 4 ; ** %Number of pilot subcarriers 4**

ofdmBW = 20 * 10^6 ; **% OFDM bandwidth**

**Derived Parameters:**

deltaF = ofdmBW/N; ** % Bandwidth for each subcarrier – include all used and unused subcarries**

Tfft = 1/deltaF; **% IFFT or FFT period = 3.2us **

Tgi = Tfft/4; ** % Guard interval duration – duration of cyclic prefix – 1/4th portion of OFDM **symbols

Tsignal = Tgi+Tfft; ** % Total duration of BPSK-OFDM symbol = Guard time + FFT period**

Ncp = N*Tgi/Tfft; ** %Number of symbols allocated to cyclic prefix**

Nst = Nsd + Nsp; ** % Number of total used subcarriers**

nBitsPerSym=Nst; **%For BPSK the number of Bits per Symbol is same as number of subcarriers**

We will use the following model for simulating the OFDM system.

The channel in this case is modeled as a simple AWGN channel. Since the channel is considered to be an AWGN channel, there is no need for the frequency domain equalizer in the OFDM receiver ( Frequency domain equalizer will be helpful only if the channel introduces multipath fading). Since our channel is an AWGN channel, the frequency domain equalizer block in the above diagram can be removed.

### Calculating Es/N0 or Eb/N0 for OFDM system:

In order to do a Monte Carlo simulation of an OFDM system, required amount of channel noise has to be generated that is representative of required Eb/N0. In Matlab it is easier to generate a Gaussian noise with zero mean and unit variance. The generated zero-mean-unit-variance noise has to be scaled accordingly to represent the required Eb/N0 or Es/N0. If we have Es/N0, the required noise can be generated from zero-mean-unit-variance-noise by,

Since the OFDM system transmits and received the data in symbols, it is appropriate/easier to generate required noise based on Es/N0 instead of Eb/N0 (as given above). But we are interested in plotting BER against Eb/N0. Ok!!! Then… how do we convert given Eb/N0 to Es/N0 for an OFDM system ?

Normally for a simple BPSK system, bit energy and symbol energy are same. So Eb/N0 and Es/N0 are same for a BPSK system. But for a OFDM BPSK system, they are not the same. This is because, each OFDM symbol contains additional overhead in both time domain and frequency domain. In the time domain, the cyclic prefix is an additional overhead added to each OFDM symbol that is being transmitted. In the frequency domain, not all the subcarriers are utilized for transmitted the actual data bits, rather a few subcarriers are unused and are reserved as guard bands.

### Effect of Cyclic Prefix on Es/N0:

The following diagram illustrates the concept of cyclic prefix. Each OFDM symbol contains both useful data and overhead (in the form of cyclic prefix). The bit energy represents the energy contained in the useful bits. In this case, the bit energy is spread over N bits (where N is the FFT size). On top of the useful data, additional Ncp bits are added as cyclic prefix, which forms the overhead. So if the entire OFDM symbol is considered, the symbol energy is spread across N+Ncp bits.

This relationship is given as

which translates to,

### Effect of unused subcarriers on Es/N0:

As mentioned earlier, not all the subcarriers are used for transmission. Out of the total N subcarriers, only Nst carriers are used for OFDM symbols transmission (this includes both data and pilot subcarriers). Again, in the frequency domain, the useful bit energy is spread across Nst subcarriers, whereas the symbol energy is spread across N subcarriers. This gives us another relationship between Es and Eb as given below

which translates to,

From (1) and (2), the overall effect of both cyclic prefix and unused subcarriers on Es/N0 is given by

which, when converted to dB yields the following relationship.

Since Ncp cylic prefix are added to the OFDM symbol, the output signal from the parallel to serial converter has to be boosted to compensate for the wastage of energy associated with the addition of cyclic prefix. To properly generate the required SNR in Matlab, the signal term at the output of the parallel to serial converter has to be scaled as follows

The received signal is represented as (for the given Eb/N0)

### Arrangement of subcarriers:

The IEEE 802.11 specification, specifies how to arrange the given subcarriers. The 52 used subcarriers (data + pilot) are assigned numbers from -26,-25,…-2,,-1 and 1,2,…,25,26. The following figure illustrates the scheme of assigning these subcarriers to the IFFT inputs.

### Simulation:

Check this book for full Matlab code.

Simulation of Digital Communication Systems Using Matlab – by Mathuranathan Viswanathan

### Simulated Result:

From the simulated result, it can be ascertained that the OFDM- BPSK modulation has no advantage over a normal BPSK system in AWGN. OFDM proves to be effective in multipath environments.

### References

### Books on OFDM

### See Also:

(1) Introduction to OFDM – Orthogonal Frequency Division Multiplexing

(2) An OFDM Communication System – Implementation Details

(3) Role of Cyclic Prefix in OFDM

### Your Thoughts ?

#### 29 Comments Already

#### 2 pingbacks/trackbacks

- An OFDM Communication System | GaussianWaves
- Introduction to OFDM – orthogonal Frequency division multiplexing – part 4 – Cyclic Prefix | GaussianWaves

You used ” .’ ” in the end of RESHAPE command as well as many others.

What is this for?

Hi, Can you please explain.

Equation (3), can you please explain why it’s a product of equation(1) and (2). Shouldn’t it be (1)+(2)? I don’t understand.

Equation(4), can you please explain how to convert it to dB to be able to get this equation(4). I am confused.

Thank you so much.

You used ” .’ ” in the end of RESHAPE command as well as many others.What is this for?

The .’ operator in matlab is to transpose a matrix. It is used at the end of reshape command to convert a matrix from mxn form to nxm form.

Hi, Can you please explain.Equation (3), can you please explain why it’s a product of equation(1) and (2). Shouldn’t it be (1)+(2)? I don’t understand.

Equation(4), can you please explain how to convert it to dB to be able to get this equation(4). I am confused.

Thank you so much.Es is the symbol energy for one OFDM symbol. The symbol energy is calculated from the contribution of cyclic prefix and unused carriers. The effect of cyclix prefix (1) is in time domain and the effect of unused subcarriers (2) is in frequency domain.

i.e. In the time domain, the Es is affected by cyclic prefix. In the frequency domain (“Subcarriers” are always discussed in terms of frequency) the Es is affect by unused carriers. So the overall effect on Es is the product of time domain effect and frequency domain effect. (You cannot add (1) and (2) since their effect is on different domain).

In short,

Total Symbol energy is not the sum of equation (1) and (2) it is the product of (1) and (2)

Converting to dB is taking log either side.

To convert a quantity to dB (if the quantity measured is expressed as Power),

dB = 10*log10(quantity)—> (A)

Applying this to equation (3)

(Es/N0)in dB = 10log10(Es/N0)

The right hand side becomes

(Es/N0) in dB = 10 log10(XYZ)

Where X = (N/(Ncp+N))

Y = Nst/N

Z = Eb/N0

From logarithm rule

log(XYZ) = log(X) + log(Y) + log(Z)

So 10log10(XYZ) = 10log10(X)+10log10(Y)+10log10(Z)

From (A), this can be written as

10log10(XYZ) = X in dB + Y in dB + Z in dB

This explains the conversion.

Thank you so much. Very well explanation! I understand it now.

However I am confused about something below. Please again explain to me.

1) IFFT block: why null at 0, 27-37, any rule about where to do zero padding? why don’t you do null at front 0-5, then in the middle 32, then the end at 59-63?

2) Regarding using transpose at reshape. Is this why in IFFT process you have to transpose the data back again? (X_Freq.’) as below

x_Time=N/sqrt(Nst)*ifft((X_Freq.’)).’;

If so, why do you do transpose at first? why don’t you just leave the data in the matrix m*n as the beginning? or is it easier do it in that dimension?

Thank you so much again. I will have more questions to ask but will post in the next message

From my previous message in second question(2). I forgot to ask you what is “N/sqrt(Nst)” for? I guess it’s to scale the signal to unit? please explain to me what it is for. I original wasn’t clear about “scaling” as well. why do we need it. I see they use a lot in matlab on many simulations. I am a bit confused.

And please also explain where N/sqrt(Nst) come from. I don’t understand. e.g. to scale “a+bj”, you will divide by sqrt(a^2+b^2). But in this case I don’t really get it why using this term to scale.

Thank you so much again. I have a few more questions. But please let me organize them how I should ask. Then I will post in the next message

OK, here is my question. It’s about Es/N0 again.(considering we use BPSK)

CP

Q1)We have 64 sub-carriers but we have Null in some sub-carriers too. So shouldn’t the useful bits be 52 instead of FFT size which is 64? because you had to assign 0 in 12 subcarriers to make it fullfil 64 sub-carriers. So when you consider bit energy, why do you consider those 0 you added to IFFT input too?

Or you consider the useful bits after IFFT block?

2) I am confused about OFDM symbol you mentioned.

The FFT size is 64 (number of used sub-carrier is 52). Number of OFDM symbols is 10^4. Is it per 1 sub-carrier?

If it’s per 1 carrier so it’s gonna be 52*10^4 bits to be transmitted?(in case it’s BPSK)

Then why number of useful bits to use to calculate Es/N0 is not equal to 52*10^54? why it’s equal to just the number of FFT size?

is it because we consider only 1 OFDM?

Please see my example below.

Assume we transmit 1 2 3 4 5….15

When we do serial to parallel it’s gonna be

11 6 1

12 7 2

13 8 3

14 9 4

15 10 5

First 1,2,3,4,5 will be assigned into IFFT input. Do we consider 1,2,3,4,5 as 1 ofdm symbol. 6,7,8,9,10 as another OFDM symbol? and when we calculate Eb/No we consider only one by one OFDM symbol? not whole data information?

When you say OFDM symbol (below “Effect of Cyclic Prefix on Es/N0″) do you mean like each OFDM symbol above?

I am confused with BPSK, 0 is one symbol, 1 is another symbol. Or QPSK has 00 as 1 symbol, 01 as another symbol.

I am sorry for many question. I am just learning so I might ask you really basic question

Thank you so much for your reply in advance.

Could you please explain what is this term “sqrt((N+Ncp)/N)” in

r= sqrt((N+Ncp)/N)*ofdm_signal + 10^(-EsN0dB(i)/20)*noise;

———————————

For AWGN

Y=X+n ; X is transmitted signal

———————————

So why do you need to multiply OFDM signal with something again?

and why n term is 10^(-EsN0dB(i)/20)*noise

Why don’t you use “noise” straight away? or you have to convert to dB? Again if you convert to dB, it shouldn’t be this term.

Please explain to me. Thank you so much.

Can’t we just use

s=reshape(data,nSym,nBitsPerSym);

instead of

s=reshape(data,nBitsPerSym,nSym).’ ;

doesn’t it do the same?

1) IFFT block: why null at 0, 27-37, any rule about where to do zero padding? why don’t you do null at front 0-5, then in the middle 32, then the end at 59-63?

There is no hard and fast rule on inserting null or zero padding. But to standardize things, there need to be some uniformity across implementations. IEEE 802.11 standard is one of the standards that is usually followed in industries for WLAN implementation. IEEE 802.11 standard is followed in the post. It specifies the particular way in which the nulls have to be inserted.

2) Regarding using transpose at reshape. Is this why in IFFT process you have to transpose the data back again? (X_Freq.’) as below

x_Time=N/sqrt(Nst)*ifft((X_Freq.’)).’;

If so, why do you do transpose at first? why don’t you just leave the data in the matrix m*n as the beginning? or is it easier do it in that dimension?It is just for programming convenience. As long as you understood the code you can use mxn or nxm format for all the matrices in your code.

Can’t we just uses=reshape(data,nSym,nBitsPerSym);

instead of

s=reshape(data,nBitsPerSym,nSym).’ ;

doesn’t it do the same?reshape(A,m,n) returns the m-by-n matrix where as reshape(A,n,m) returns n-by-m matrix. So the commands are not the same

Could you please explain what is this term “sqrt((N+Ncp)/N)” inr= sqrt((N+Ncp)/N)*ofdm_signal + 10^(-EsN0dB(i)/20)*noise;

———————————

For AWGN

Y=X+n ; X is transmitted signal

———————————

So why do you need to multiply OFDM signal with something again?

and why n term is 10^(-EsN0dB(i)/20)*noise

Why don’t you use “noise” straight away? or you have to convert to dB? Again if you convert to dB, it shouldn’t be this term.

The term sqrt((N+Ncp)/N) is used for normalization which is used to normalize the energy of OFDM signal with respect to unity It is similar to the term sqrt(1/2) term found in the transmitter equation for BPSK (refer some text book on this part)The noise generated by rand function in matlab is zero mean unit variance noise. The purpose of the simulation is to plot Eb/No vs BER, otherwise, plotting BER for various signal to noise ratio. Eb/N0 or Es/N0 is always specified in dB. So we need to convert it from dB to linear scale. Remember that we need to generate noise that gives us required Eb/N0, i.e. need to generate noise with required variance. As mentioned earlier, the noise generated by rand function is zero mean unit variance noise. So it need to be scaled appropriately to give noise with required variance (or equivalently noise power)Hi Mathuranathan,

Thank you for your reply.

I posted a question on your facebook because it didn’t show up here. May be it’s too long. could you please reply those questions as well. Thank you.

Hi, Thank you so much for your reply on the facebook. However you skipped many parts. I mean you didn’t complete it because you forgot to view whole comment.

In each of my comments in facebook, please also click “See More” below my comments (and above the date and time). Then you will see the whole question. Because facebook will only show a few lines of the comment. you have to click “See More” to view whole message.

OK, please find my whole query (from facebook) here.

1)It’s about “Simulation of OFDM system in Matlab – BER Vs Eb/N0 for OFDM in AWGN channel”

OK, here is my question. It’s about finding Es/N0.(considering we use BPSK)

——-

CP

——

1)We have 64 sub-carriers but we have Null in some sub-carriers too. So shouldn’t the useful bits be 52 instead of FFT size which is 64? because you had to assign 0 in 12 subcarriers to make it fullfil 64 sub-carriers. So when you consider bit energy, why do you consider those 0 you added to IFFT input too?

Or you consider the useful bits after IFFT block?

2) I am confused about OFDM symbol you mentioned.

The FFT size is 64 (number of used sub-carrier is 52). So itâ€™s gonna be 52*10^4 bits to be transmitted?(in case itâ€™s BPSK)

Then why number of useful bits to use to calculate Es/N0 is not equal to 52*10^54? but itâ€™s equal to just the number of FFT size?

is it because we consider only 1 OFDM?

Please see my example below.

Assume we transmit 1 2 3 4 5â€¦.15

When we do serial to parallel itâ€™s gonna be

11 6 1

12 7 2

13 8 3

14 9 4

15 10 5

3) First 1,2,3,4,5 will be assigned into IFFT input. Do we consider 1,2,3,4,5 as 1 ofdm symbol. 6,7,8,9,10 as another OFDM symbol? and when we calculate Eb/No we consider only one by one OFDM symbol? not whole information data?

When you say OFDM symbol (below â€œEffect of Cyclic Prefix on Es/N0â€³) do you mean like each OFDM symbol above?

I am confused with BPSK, 0 is one symbol, 1 is another symbol. Or QPSK has 00 as 1 symbol, 01 as another symbol.

In matlab simulation, why channel h is multiplied by transmitted signal Xt in BPSK over rayleigh –> h*Xt

but in “OFDM over rayleigh”, channel will be convolved with transmitted signal –> conv(h,Ht)

why?

why we don’t do convolution in BPSK over rayleigh too…or may be just do normal multiply in OFDM?

We have 64 sub-carriers but we have Null in some sub-carriers too. So shouldn’t the useful bits be 52 instead of FFT size which is 64? because you had to assign 0 in 12 subcarriers to make it fullfil 64 sub-carriers. So when you consider bit energy, why do you consider those 0 you added to IFFT input too?

Or you consider the useful bits after IFFT block?

1) We have 64 subcarriers in total – So 1 OFDM symbol (with BPSK) has 64 bits

2) Lets call the energy possessed by 1 OFDM symbol be Es

3) Out of 64 subcarriers only 52 are used (remaining being set to null)

4) So the ratio of useful subcarriers to total subcarriers is 52/64

5) Lets call the energy per bit be Eb

6) 1 OFDM symbol has 52/64 useful information and 12/64 zero information (since the input is zero for these 12 unused subcarriers)

7) So the OFDM symbol energy is 52/64*Eb

Lets consider there are 4 subcarriers in our OFDM system. I wish to transmit 12 bits of information 1,0,1,1,0,0,1,1,1,0,0,0

Converting serial to parallel (fill row by row from left to right)

C1 C2 C3 C4

1 0 1 1

0 0 1 1

1 0 0 0

In BPSK system 1-> 1, 0->-1

So the actual matrix is

C1 C2 C3 C4

1 -1 1 1

-1 -1 1 1

1 -1 -1 -1

In carrier 1 we transmit 1,-1,1 (read column-wise)

In carrier 2 we transmit -1,-1,-1

In carrier 3 we transmit 1,1,-1

In carrier 4 we transmit 1,1,-1

But we cannot transmit the bits as it is. Each carrier has to be operated on some orthogonal frequencies.

The final output will be the combination (summation) of all these frequencies.

This is where we use IFFT block. The IFFT block takes each row one by one, assuming them to be at different frequencies and produces the output

by performing IFFT on each row and converting them to time domain.

Here 1 OFDM symbol is 4 bits (four carriers). So we transmit 3 OFDM symbols in total

For QPSK instead of single elements in the matrix we will have double elements

Example:

C1 C2 C3 C4

00 01 11 11

10 10 00 11

10 00 11 00

Here also 1 OFDM symbol has 4 subcarriers but 8 bits in total and 3 such OFDM symbols are transmitted

In matlab simulation, why channel h is multiplied by transmitted signal Xt in BPSK over rayleigh –> h*Xt

but in “OFDM over rayleigh”, channel will be convolved with transmitted signal –> conv(h,Ht)

why?

why we don’t do convolution in BPSK over rayleigh too…or may be just do normal multiply in OFDM?

Convolution in time domain is equivalent to multiplication in frequency domain.

Following statements are equivalent

y(t) = h(t)*x(t)

Y(F) = H(F)X(F)

Check which method is used in the matlab script and cross verify this dualityThank you so much. Everything is clear to me apart from the one below.

(I really respect you. You are my best teacher. As I told you before, your explanation is the best, simply to understand.Thank you so so much for all the work.)

Anyway, here is what I am unclear.

In question one, you seem to explain to me on “Effect of unused subcarriers on Es/N0″. but my question is about “Effect of Cyclic Prefix on Es/N0″. My question is confusing you with the word “sub carrier”. Sorry about that.Could you please re-read my first query again for me with additional information below.

from your information on “Effect of Cyclic Prefix on Es/N0″, The bit energy represents the energy contained in the “useful bits”.

And from equation

Es(N+Ncp)=N*Eb

What I meant in my first question is that. Shouldn’t the right term be 52*Eb instead of N*Eb or 64*Eb. because the useful bits are only 52, not 64.

but if the right term is 64*Eb, that means you consider “added zero” as a useful bit too? why?

I have more queries here.

(1)–> For OFDM over AWGN, you compare the result with BPSK over AWGN. The results are the same. And the reason is…OFDM doesn’t do anything in AWGN.

(2)–> However in OFDM over rayleigh(using n tap), you compare the result with BPSK over rayleigh. The results are the same as well.

2.1 ->But why this time the reason is not “because OFDM doesn’t do anything in rayleigh”. as (1)

2.2 ->and why the results are the same if OFDM is doing something? and what is OFDM doing? what can you tell from the graph that the result is the same as BPSK over rayleigh?

3) OFDM over rayleigh.

if rayleigh channel has 10 taps

nTap = 10;

ht = 1/sqrt(2)*1/sqrt(nTap)*(randn(nSym,nTap) + j*randn(nSym,nTap));

How can we know that we have to use this term “1/sqrt(2)*1/sqrt(nTap)” to normalise. Is it the theory from the book? where can I find those sources to check what term I should use to normalise channel, noise in matlab.Could you please recommend me the book that contain such information (if it’s from the theory).

I really don’t understand what number I should use to normalise things in matlab. and why do we need to normalise it.

ps: I am still looking forward to reading your articles of OFDM over rayleigh+matlab code.

———————-

Also would be useful if you could post the articles about DFT, FFT and something about OFDMA

Hi Mazda,

3) OFDM over rayleigh.

if rayleigh channel has 10 taps

nTap = 10;

ht = 1/sqrt(2)*1/sqrt(nTap)*(randn(nSym,nTap) + j*randn(nSym,nTap));

How can we know that we have to use this term “1/sqrt(2)*1/sqrt(nTap)” to normalise. Is it the theory from the book? where can I find those sources to check what term I should use to normalise channel, noise in matlab.

Consider the following equation for generating a complex gaussian noise

n = rand(1,10) + j rand(1,10)

The rand function in matlab generates noise with zero mean and unit variance. Since we are using two independent noise sources to generate a complex noise, the variance will double. So in this case the variance is 2x ( where x=1)

To generate a complex noise with zero mean and unit variance, the output has to be normalized by 1/sqrt(2). So the code becomes

n = 1/sqrt(2) * (rand(1,10)+j rand(1,10)

Why should we require the noise variance to be 1 ? Because, when the variance is 1, the noise power becomes unity. The noise power is scaled to become unity indirectly.

For an n Tap channel the equation to generate the multipath is

ht = 1/sqrt(2)*1/sqrt(nTap)*(randn(nSym,nTap) + j*randn(nSym,nTap));

the term 1/sqrt(nTap) is used in the similar way to normalize the noise power to unity.

(1)–> For OFDM over AWGN, you compare the result with BPSK over AWGN. The results are the same. And the reason is…OFDM doesn’t do anything in AWGN.

(2)–> However in OFDM over rayleigh(using n tap), you compare the result with BPSK over rayleigh. The results are the same as well.

2.1 ->But why this time the reason is not “because OFDM doesn’t do anything in rayleigh”. as (1)

2.2 ->and why the results are the same if OFDM is doing something? and what is OFDM doing? what can you tell from the graph that the result is the same as BPSK over rayleigh?

I think u are refering to Rayleigh Fading Simulation with nTap multipath. OFDM will improve the performace of a system if the multipath channel incorporates both delay spread and doppler effect. I think that the simulation that you are refering to is incorporating only the variation of tap weights. In that case, both BPSK and OFDM with BPSK will perform similar.

Introduce doppler spread in the Rayleigh channel and you can observe the difference in performance improvement with and without OFDM

Hi,

I want to know why OFDM with BPSk has high bit error rate than OFDM with QPSK and 64 QAM?

And why 16-QAM has best performance among all?

Do you have any reference graphs or curves about the scenario you are talking about ?