Theoretical BER using Matlab – BERTOOL

Note: There is a rating embedded within this post, please visit this post to rate it.
When simulating digital modulations in Matlab, it is useful to verify the simulated BER performance curves against theoretical BER curves.Matlab has an inbuilt visualization tool, ‘BERTOOL’, for this purpose.

Matlab’s BERTOOL supports 6 types of digital modulations over 3 types of channel for plotting theoretical BER. The six supported modulations are PSK,DPSK,OQPSK,PAM,QAM,FSK and the three channel types are : AWGN,Rayleigh,Rician. It also has options to set diversity order, channel coding, synchronization method and demodulation type(coherent/non-coherent).

A brief intro to the tool is given here. You might need to install communication toolbox for invoking this tool.

Invoke the BERTOOL GUI using the command (tested with R2012b)
>>bertool

Set the desired configuration and click plot.

You can export the data from BERTOOL to the workspace. After you have exported it to the workspace, you can plot it against your simulation curve for verification.

For a detailed documentation: Matlab documentation on BERTOOL

Recommended Books:

Tips & Tricks : Indexing in Matlab

Let’s review indexing techniques in Matlab: Indexing one dimensional array, two dimensional array, logical indexing, reversiong a vector – are covered.

Consider a sample vector in Matlab.

>> x=[9  21  6  8  7  3  18  -1  0  4]
ans=
   9  21  6  8  7  3  18  -1  0  4

Index with single value

>> x(2)
ans =
  21

Index with range of values

>> x([1 4 6])
ans =
    9  8  3

Select a range of elements using ‘:’ operator.

Example: Select elements with index ranging from 1 to 5.

>> x(1:5)
ans =
     9  21  6  8  7

Making a new vector by swapping two halves of the vector x

>> x([6:10 1:5])
ans =
    3  18  -1  0  4  9  21  6  8  7

To refer the last element of the matrix x use ‘end’ operator

>> x(end)
ans =
4

You can do arithmetic on the ‘end’ operator. Selecting all elements except the last element

>> x(1:end-1)
ans =
   9   21   6   8  7  3  18  -1  0

Reversing the vector

>> x(end:-1:1)
ans =
     4  0  -1  18  3  7  8  6  21  9

Using the end operator in a range. Selecting from fifth element to the end

>> x(5:end)
ans =
   7  3  18  -1  0  4

Replacing specific elements in the array by placing the new values on the right side of the expression. Replacing the values of ‘x’ at positions [2,5,8] with new values

>> x([2 5 8])=[11 14 -6]
x =
   9  11  6  8  14  3  18  -6  0  4

Replacing specific elements with a same value. Replacing the values of ‘x’ at position [1 and 10] with 40

>> x([1 10]) = 40
x =
   40  11  6  8  14  3  18  -6  0  40

Two dimensional Arrays:

>> x=magic(4) %Create a magic array with 4x4 elements
x =
   16  2  3 13
    5 11 10  8
    9  7  6 12
    4 14 15  1

The two dimensional array elements are accessed with two subscript indices like x(i,j) – where ‘i’ represents row and ‘j’ represents column. Accessing the element located at second row and third column

>> x(2,3)
ans =
   10

The subscript indices can also be vectors. Selecting the elements in the first row – 4th,2nd and 1st column & third row – 4th,2nd and 1st column

>> x([1 3],[4 2 1])
ans =
    13   2   16
    12   7    9

The ‘:’ operator is the short form for 1:end. It is usually used to select all the elements in a specific column of row. Accessing all elements on the third row

>> x(3,:)
ans =
   9  7  6  12

Extracting the last row using the “end” operator and the “:” operator

>> x(end,:)
ans =
   4  14  15  1

Logical Indexing:

Used to select the elements of a matrix that satisfy some criteria given by an expression

>> x=magic(4) %Create a magic array with 4x4 elements
x =
  16   2   3  13
   5  11  10   8
   9   7   6  12
   4  14  15   1

Getting all elements of the matrix whose value is above 10

>> x(x>10)
ans =
    16
    11
    14
    15
    13
    12

Getting the row and column subscripts of those elements using the “find” function.

>> [i,j]=find(x>10)
i =
     1
     2
     4
     4
     1
     3
j =
     1
     2
     2
     3
     4
     4

Sometimes, when you run your script you might encounter ‘Inf’ (IEEE arithmetic representation for positive infinity) or -Inf( representation for negative infinity) values sitting in a matrix. See the following example

>> k=[1 4 5 0 6 7 0 -1]
x=1./k %Finding the reciprocal of each element and storing it as a vector
k =
     1     4     5     0     6     7     0    -1
x =
    1.0000    0.2500    0.2000       Inf    0.1667    0.1429       Inf   -1.0000

Your rest of the script may need you to fix this by replacing the Inf with 0. This can be achieved by using “isinf” function in Matlab. The “isinf” function returns a logical array which will specify whether an element is Inf (It also compares -Inf).

>> x(isinf(x))=0
x =
    1.0000    0.2500    0.2000         0    0.1667    0.1429         0   -1.0000

There are other functions similar to “isinf” like “isspace”,”isnan” etc.., that look for the specific condition to satisfy and returns a logical array depending on the result.

Browse articles tagged for Matlab code…

Rate this article: Note: There is a rating embedded within this post, please visit this post to rate it.

Other Resources on Matlab’s Matrix Indexing:

[1] Matlab documentation on Matrix indexing↗
[2]A Book detailing how MATLAB code can be written in order to maximize its effectiveness.
Richard K Johnson, “The Elements of MATLAB Style “, Cambridge University Press,ISBN-13: 978-0521732581↗

FFT and Spectral Leakage

Spectral leakage due to FFT is caused by: mismatch between desired tone and chosen frequency resolution, time limiting an observation. Understand the concept using hands-on examples.

Limits of frequency domain studies

Frequency Transform is used to study a signal’s frequency domain characteristics. When using FFT to study the frequency domain characteristics of a signal, there are two limits : 1) The detect-ability of a small signal in the presence of a larger one; 2) frequency resolution – which distinguishes two different frequencies.

In practice, the measured signals are limited in time and the FFT calculates the frequency transform over a certain number of discrete frequencies called bins.

Spectral Leakage:

In reality, signals are of time-limited nature and nothing can be known about the signal beyond the measured interval. For example, if the measurement of a never ending continuous train of sinusoidal wave is of interest, at some point of time we need to terminate our observation to do further analysis. The limit on the time is also posed by limitations of the measurement system itself (example: buffer size), besides other factors.

It is often said that the FFT implicitly assumes that the signal essentially repeats itself after the measured interval and hence the FFT assumes the signal to be continuous (conceptually, juxtapose the measured signal repetitively). This lead to glitches in the assumed signal (see Figure 1). When the measurement time is purposefully made to be a non-integral multiple of the actual signal rate, these sharp discontinuities will spread out in the frequency domain leading to spectral leakage. This explanation for spectral leakage need to be carefully investigated.

Figure 1:Impact of observation interval on FFT

Experiment 1: Effect of FFT length and frequency resolution

Consider a pure sinusoidal signal of frequency \(f_x = 10 \;Hz\) and to represent in computer memory, the signal is observed for 1 second and sampled at frequency \(F_s=100 \; Hz\). Now, there will be 100 samples in the buffer and the buffer will contain integral number of waveform cycles (10 cycles in this case). The signal samples are analyzed using N-point DFT. Two cases are considered here for investigation : 1) The FFT size \(N\) is same as the length of the signal samples, i.e, N=100 and 2) FFT size set to next power of 2 that fits the signal samples i.e, N=128. The result are plotted next.

Fx=10; %Frequency of the sinusoid
Fs=100; %Sampling Frequency
observationTime = 1; %observation time in seconds
t=0:1/Fs:observationTime-1/Fs; %time base
x=sin(2*pi*Fx*t);%sampled sine wave

N=100; %DFT length same as signal length
X1 = 1/N*fftshift(fft(x,N));%N-point complex DFT of x
f1=(-N/2:1:N/2-1)*Fs/N; %frequencies on x-axis, Fs/N is the frequency resolution

N=128; %DFT length
X2 = 1/N*fftshift(fft(x,N));%N-point complex DFT of x
f2=(-N/2:1:N/2-1)*Fs/N; %frequencies on x-axis, Fs/N is the frequency resolution

figure;
subplot(3,1,1);stem(x,'r')
title('Time domain');xlabel('Sample index (n)');ylabel('x[n]');
subplot(3,1,2);stem(f1,abs(X1)); %magnitudes vs frequencies
xlim([-16,16]);title(['FFT, N=100, \Delta f=',num2str(Fs/100)]);xlabel('f (Hz)'); ylabel('|X(k)|');
subplot(3,1,3);stem(f2,abs(X2)); %magnitudes vs frequencies
xlim([-16,16]);title(['FFT, N=128, \Delta f=',num2str(Fs/128)]);xlabel('f (Hz)'); ylabel('|X(k)|');
Figure 2: Effect of FFT length and frequency resolution

One might wonder, even though the buffered samples contain integral number of waveform cycles, why the frequency spectrum registered a distinct spike at \(10 \; Hz\) when \(N=100\) and not when \(N=128\). This is due to the different frequency resolution, the measure of ability to resolve two different adjacent frequencies

For case 1, the frequency resolution is \(\Delta f = f_s/N = 100/10 = 1 Hz\). This means that the frequency bins are spaced 1 Hz apart and that is why it is able to hit the bull’s eye at 10 Hz peak.

For case 2, the frequency resolution is \(\Delta f = f_s/128 = 100/128 = 0.7813 Hz\). With this frequency resolution, the x-axis of the frequency plot cannot have exact value of 10 Hz. Instead, the nearest adjacent frequency bins are 9.375 Hz and 10.1563 Hz respectively. Therefore, the frequency spectrum cannot represent 10 Hz and the energy of the signal gets leaked to adjacent bins, leading to spectral leakage.

Experiment 2: Effect of time-limited observation

In the previous experiment, the signal wave observed for 1 second duration and that fetched whole 10 cycles in the signal buffer. Now, reduce the observation time to 0.91 second and re-run the same code, results below. In this case, the signal buffer will have 9.1 cycles of the sinewave, which is not a whole number. For case 1, the frequency resolution is 1 Hz and the FFT plot has registered a distinct peak at 10 Hz. Careful investigation of the plot will reveal very low spectral leakage even in case 1 (observe the non-zero amplitude values for the rest of the bins). This is primarily due to the change in the observation interval leading to non-integral number of cycles within the observed window. The spectral leakage in case 2, when N=128, is predominantly due to mismatch in the frequency resolution.

Figure 3: Effect of limited time observation on spectral leakage in time domain

From these two experiments, we can say that
1) The mismatch between the tone of the signal and the chosen frequency resolution (result of sampling frequency and the FFT length) leads to spectral leakage (experiment 1).
2) Time-limiting an observation (at inappropriate times), may lead to spectral leakage (experiment 2).
3) Hence, the spectral leakage from a larger signal component, if present, may significantly overshadow other smaller signals making them difficult to identify or detect.

Rate this article: Note: There is a rating embedded within this post, please visit this post to rate it.

\[\]

Reference

[1] Fredric J Harris, “On the use of windows for Harmonic Analysis with the Discrete Wavelet Transform”, Proceedings of IEEE, Vol 66,No 1, January 1978.↗

Similar articles

[1] Understanding Fourier Series
[2] Introduction to digital filter design
[3] Design FIR filter to reject unwanted frequencies
[4] FIR or IIR ? Understand the design perspective
[5] How to Interpret FFT results – complex DFT, frequency bins and FFTShift
[6] How to interpret FFT results – obtaining magnitude and phase information
[7] Analytic signal, Hilbert Transform and FFT
[8] FFT and spectral leakage
[9] Moving average filter in Python and Matlab
[10] Window function – figure of merits
[11] Equivalent noise bandwidth of window functions

Books by the author


Wireless Communication Systems in Matlab
Second Edition(PDF)

Note: There is a rating embedded within this post, please visit this post to rate it.
Checkout Added to cart

Digital Modulations using Python
(PDF ebook)

Note: There is a rating embedded within this post, please visit this post to rate it.
Checkout Added to cart

Digital Modulations using Matlab
(PDF ebook)

Note: There is a rating embedded within this post, please visit this post to rate it.
Checkout Added to cart
Hand-picked Best books on Communication Engineering
Best books on Signal Processing