Generation of elementary signal in python

Nilay Paul
3 min readApr 2, 2021

We will be using matplotlib for visualization purposes .

Basics of matplotlib

…………………………………………………………………………………

plot() — Plots continuous waveform provided x,y values . Some optional arguments are color,linestyle,linewidth etc.

stem() — Plots continuous waveform provided x,y values .

legend() used to specify legends of the plot

xlabel() , ylabel() for specifying x and y axis name.

title() — used to specify plot name

grid() — Given True as parameter turns on the grid

show() — shows the plot

…………………………………………………………………………………

Delta function

from matplotlib import pyplot as pltplt.style.use('ggplot')xval = [x for x in range(-100,100)]yval=[]for t in range(-100,100):
if t==0:
yval.append(1) else: yval.append(0)plt.plot(xval,yval,label="delta function")plt.xlabel("time")plt.ylabel("Amplitude")plt.grid(True)plt.legend()plt.show()
Delta function

Step function

from matplotlib import pyplot as pltplt.style.use('ggplot')x_val = [x for x in range(-100,100)]y_val =[]for x in x_val:      if x>=0:         y_val.append(1)      else:         y_val.append(0)plt.plot(x_val,y_val,color='g',label="Step signal")plt.legend()plt.title("step signal")plt.xlabel('time')plt.ylabel('amp')plt.show()
Step Function

Signum Function

from matplotlib import pyplot as pltplt.style.use('ggplot')x_val = [x for x in range(-50,50)]y_val=[]for x in x_val:      if x>=0:         y_val.append(1)      else:         y_val.append(-1)plt.stem(x_val,y_val,label="signum function")plt.legend()plt.title("Signum Function")plt.xlabel("Time")plt.ylabel("Amplitude")plt.show()
Signum Function

Sine Function

from matplotlib import pyplot as pltimport numpy as npplt.style.use('ggplot')x_val = np.arange(-np.pi,np.pi,0.5)y_val = [np.sin(x) for x in x_val]plt.plot(x_val,y_val,color='g',label="sine wave")plt.legend()plt.title("Sine wave")plt.xlabel("Time")plt.ylabel("Amplitude")plt.show()
Sine wave

Cos Function

from matplotlib import pyplot as pltimport numpy as npplt.style.use('ggplot')x_val = np.arange(0,4*np.pi,0.5)y_val = [np.cos(i) for i in x_val]plt.plot(x_val,y_val,label="cos wave")plt.legend()plt.title("Cos wave")plt.xlabel("Time")plt.ylabel("Amplitude")plt.grid(True)plt.tight_layout()plt.show()
cosine

Ramp Function

from matplotlib import pyplot as pltplt.style.use('ggplot')x_val = [x for x in range(-10,100)]y_val=[]t=0for x in x_val:      if x>=0:         y_val.append(t*1)         t+=1     else:         y_val.append(0)plt.plot(x_val,y_val,label="Ramp signal")plt.legend()plt.xlabel("Amplitude")plt.ylabel("Time")plt.title("Ramp signal")plt.show()

--

--