This page shows different modulation methods (AM and FM). A page which outlines a range of waverforms is here.
AM and FM |
Source code
The following outlines the Python code used:
import matplotlib.pyplot as plot import numpy as np import sys file ='1111' m=0.2 type='am' freq=10 freqs=2 if (len(sys.argv)>1): file=str(sys.argv[1]) if (len(sys.argv)>2): m=float(sys.argv[2]) if (len(sys.argv)>3): type=(sys.argv[3]) if (len(sys.argv)>4): freq=int(sys.argv[4]) if (len(sys.argv)>5): freqs=int(sys.argv[5]) Fs = 150.0; # sampling rate Ts = 1.0/Fs; # sampling interval t = np.arange(0,2,Ts) if (type=='fm'): y= np.sin(2 * np.pi * freq * t + m*np.sin(2 * np.pi * freqs * t)) else: y= (1+m*np.sin(2 * np.pi * freqs * t))* np.sin(2 * np.pi * freq * t) n = len(y) # length of the signal k = np.arange(n) T = n/Fs frq = k/T # two sides frequency range frq = frq[range(n//2)] # one side frequency range Y = np.fft.fft(y)/n # fft computing and normalization Y = Y[range(n//2)] fig,myplot = plot.subplots(2, 1) myplot[0].plot(t,y) myplot[0].set_xlabel('Time') myplot[0].set_ylabel('Amplitude') myplot[1].plot(frq,abs(Y),'r') # plotting the spectrum myplot[1].set_xlabel('Freq (Hz)') myplot[1].set_ylabel('|Y(freq)|') plot.savefig(file) plot.show() print ("Saved to ",file)