This page shows a plot a range of waveforms, and where we can add noise. A page which outlines AM and FM is here.
Signals and Noise |
Source code
The following outlines the Python code used:
import matplotlib.pyplot as plot import numpy as np import sys from scipy import signal file ='1111' noise=0.1 type='sawtooth' if (len(sys.argv)>1): file=str(sys.argv[1]) if (len(sys.argv)>2): noise=float(sys.argv[2]) if (len(sys.argv)>3): type=(sys.argv[3]) Fs = 150.0; # sampling rate Ts = 1.0/Fs; # sampling interval t = np.arange(0,2,Ts) if (type=='sin'): y= np.sin(2 * np.pi * 5 * t) elif (type=='square'): y= signal.square(2 * np.pi * 5 * t) elif (type=='triangle'): y= signal.sawtooth(2 * np.pi * 5 * t,width=0.5) elif (type=='gausspulse'): y= signal.gausspulse(t,fc=5,bw=0.5,bwr=-6,retquad=0) elif (type=='chirp'): y= signal.chirp(t, f0=0, t1=1, f1=5, method='linear', phi=0) else: y= signal.sawtooth(2 * np.pi * 5 * t) noise = noise*np.random.normal(0, 1, len(t)) y = y + noise 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.show() plot.savefig(file)