In [12]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
fig = plt.gcf()
fig.set_size_inches(8,8)
# set signal and transform constants
samples = 10000
t = np.arange(samples)
cf = 1000 # carrier frequency Hz
mf = 60 # modulation frequency Hz
# signal is a classic AM waveform
signal = lambda t: np.sin(2 * np.pi * cf * t / samples) \
* (1+(np.sin(2 * np.pi * mf * t / samples))) 
sp1 = plt.subplot(211)
sp1.set_xlim(0,512)
sp1.grid(True)
sp1.set_ylabel('Amplitude')
sp1.set_title('Time Domain')
sp1.plot(t,signal(t),color='#008000')
sp2 = plt.subplot(212)
sp2.set_xlabel('Frequency Hz')
sp2.set_ylabel('Amplitude')
sp2.set_title('Frequency Domain')
sp2.set_xlim(500,1500)
sp2.grid(True)
fi = np.arange(2000)
fs = np.fft.rfft(signal(t))[:2000]
sp2.plot(fi ,abs(fs) * 2 / samples,color='#008000')
plt.show()