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)$$
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
def demodulate(self, received_array, fc, fm):
c = np.cos(6.28*fc*t)
demod = 2*c*received_array
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.