Processor Intel(R) Core(TM) i7-5500U CPU @ 2.4GHz
Installed Memory 8.00 GB
System Type 64 Bit Operating System, x64 Based Processor
Integrated Development Environment (IDE)
Version 220.127.116.1142 (32 bit)
Time in sec (MATLAB)
Time in sec (PYTHON)
10 million uniform random variable generation
10 million normal random variable generation
for loop counting up to 100 million
Comparing two vectors of length 10 million each
Plotting a histogram of 10 million values
Plotting a scatter plot of 1 million values
Bit error rate calculation of BPSK for 10 values of SNR
Although Python is a bit slower than MATLAB for most of the cases but the real difference is in implementation of “for loop” where the speed of MATLAB is 29x that of Python. Another surprising result was that the plot functions for Python were somewhat faster than MATLAB.
Most of us have used the FFT routine in MATLAB. This routine has become increasingly important in simulation of communication systems as it is being used in Orthogonal Frequency Division Multiplexing (OFDM) which is employed in 4G technologies like LTE and WiMAX. We would not go into the theoretical details of the FFT, rather, we would produce the MATLAB code for it and leave the theoretical discussion for a later time.
The underlying technique of the FFT algorithm is to divide a big problem into several smaller problems which are much easier to solve and then combine the results in the end.
%%%%% INITIALIZATION %%%%%
%%%%% BIT REVERSAL %%%%%
while (m >= 2 && j > m)
%%%%% DANIELSON-LANCZOS ALGO %%%%%
while (n > mmax)
In the above example we have calculated an ‘nn’ point complex FFT of an ‘nn’ point complex time domain signal. The algorithm takes the input in a special arrangement where the ‘nn’ point complex input signal is converted into ‘2*nn’ real sequence where the imaginary components are placed in odd elements and real components are placed in even elements of the input sequence. A similar arrangement works for the output sequence.
Shown below is the FFT of a complex exponential with a frequency of 100 Hz. The plot is shown from 0Hz to 1000 Hz which is the sampling frequency. A signal with multiple frequencies would have to be passed through a Low Pass Filter (LPF) so that the signal components above 500 Hz (fs/2) are filtered out. When the FFT of a real signal is performed an image frequency is produced between 500 Hz to 1000 Hz.
Here we have discussed the case of complex input sequence. Simplifications can be made for a real sequence or for special signals such as pure sine and cosine waves. We will discuss these in later posts.
 Numerical Recipes in C, The Art of Scientific Computing, Cambridge University Press.