0
$\begingroup$

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.

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

enter image description hereThis is wrong Because if your carrier frequency is less than your message frequency, then you will have trouble in filtering .

$\endgroup$
1
  • 1
    $\begingroup$ Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 4.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, consider taking a look at: How does deleting work? $\endgroup$ – Glorfindel Nov 3 '20 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.