Simulating Amplitude Modulation using Python

In communication labs in our colleges we all generate amplitude modulated signals using CROs. But the same can be performed by using Python and few of its additional libraries and the end result can be equally dope.

At first let’s revise the formulas needed to generate amplitude modulated signal

Message Signal
Carrier Signal
Amplitude Modulated Signal

Now to simulate the signals in python first we have to import 2 python libraries: numpy and matplotlib

Then we have to take carrier amplitude, carrier frequency, message amplitude, message frequency and modulation index as inputs.

The built-in function in python returns string value. So we have to convert them to integer or float. Now float is preferred because amplitude or frequency can be in decimal too.

The time function in analog communication is continuous function. To replicate its behavior we will use function which will provide large number of discrete points which will act almost similar to continuous function. The function will generate evenly spaced numbers within a given interval. The first argument of is starting point, second argument is ending point and third argument is number of breakpoints between the given interval.

Now we will create our carrier, modulator(message), and product function. Here we will use , and from numpy.

Here comes the plotting part. We will utilize matplotlib library functions. The function creates more than one plot in the canvas. The function plots the given function. In function we can pass color names or their acronyms to plot the graph in any color we wish. The ‘g’ , ‘r’ stands for green and red respectively. The and prints the x-axis and y-axis variable names. And the function prints the title of the over all plot.

Now we can customize the plot as much we want. We can change the space between plots, font, size etc. And if we want to save the picture we can easily do so by function where dpi means dots per inch which in today’s world, can be inter-changeably used with ppi(pixel per inch). More of such functions can be found in official matplotlib documentation.

Thus we can create simple amplitude modulation plot in python just using two external libraries only.

The full code is here: