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 input 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 linspace function which will provide large number of discrete points which will act almost similar to continuous function. The linspace function will generate evenly spaced numbers within a given interval. The first argument of linspace 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 sin , cos and pi from numpy.

Here comes the plotting part. We will utilize matplotlib library functions. The subplot function creates more than one plot in the canvas. The plot function plots the given function. In plot 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 xlabel and ylabel prints the x-axis and y-axis variable names. And the title 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 savefig 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:

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nabanita Sarkar

Nabanita Sarkar

More from Medium

Dynamically Update the HTML Code in Flask Using Htmx Library.

Create a Simple API in Flask

How to Debug Dockerized Flask in VSCode Real Quick

Generating Requirements the easy way with Pipreqs