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; enter image description here

The demodulated signal is however this; enter image description here

When it should have been this; enter image description here

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.

  • 1
    (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 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. – Himanshu Sharma Mar 22 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 at 23:14
  • The problem is solved now. – Himanshu Sharma Mar 27 at 13:34
  • 1
    Himanshu, please consider adding an answer explaining what the problem was and how you solved it. You can even accept your own answer. – MBaz Mar 27 at 13:57

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.