# AM Modulator Demodulator in Python

I am trying to make a AM modem using Python Numpy and Matplotlib. I am successful in generating the AM Signal but I cannot demodulate it using a lowpass filter function that I made. The demodulation equation that I am using is;

$$A_{c}m(t)\cos(\omega_{c}t)\cdot 2\cos(\omega_{c}t)$$

My modulated output is this;

The demodulated signal is however this;

When it should have been this;

The lowpass filter that I am using is; $$h(t) = \frac{\sin(2\pi Bt)}{\pi t}$$

Finally, this is my code;

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0, 100, 0.1)

message_freq = 50
message = np.sin(6.28*message_freq*t)
carrier_freq = 1000

class Filters():
def LowPassFilter(self, cutoff):
f = np.sin(6.28*cutoff*t)/(3.14*t)
return f

class AmplitudeModem:
def modulate(self, message, fc):
c = np.cos(6.28*fc*t)

mod = message*c
return mod

c = np.cos(6.28*fc*t)

baseband = demod #- self.modulate(Ac, received_array, 2*fc)
return np.convolve(Filters().LowPassFilter(message_freq), baseband)

modulated = AmplitudeModem().modulate(message, carrier_freq)
demodulated = AmplitudeModem().demodulate(modulated, carrier_freq, message_freq)


Another problem that I am facing is that, I cannot plot the convolution (used in demodulate() function) with respect to time, due to their different dimensions.

• (1) Make sure your sampling frequency is large enough (it looks like it is 10 Hz right now, but I could be reading your code wrong) and (2) you're missing a rectifier in the receiver.
– MBaz
Mar 22, 2018 at 18:19
• but do i need a rectifier at all in this demodulation. As far as I know, a lowpass filter is enough to remove high frequency content from the spectrum of DSB-SC. Mar 22, 2018 at 22:44
• You do need it for DSB-LC: I misread your first equation and didn't realize you're doing DSB-SC with coherent detection. What about your sampling rate, is it high enough? Also, double-check your filter impulse response; I think you're missing a $B$ in the denominator.
– MBaz
Mar 22, 2018 at 23:14
• The problem is solved now. Mar 27, 2018 at 13:34