Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def d(n,n0):
- """d returns the discrete impulse function evaluated for the values in n (numpy array) with an offset n0.
- Inputs :
- * n : numpy.array of int, discrete values where the discrete impulse function will be evaluated
- * n0 : int, offset of the discrete impulse function
- Outputs :
- * y : numpy.array, discrete values of the discrete impulse signal evaluated for the input n
- Creation : 14-02-2020
- """
- index_arr = np.where(n==n0)
- n = np.zeros(len(n))
- for index in index_arr:
- n[index] = 1
- return n
- def u(n,n0):
- """u returns the step function evaluated for the values in n (numpy array) with an offset n0.
- Following the mathematic definitions:
- - u(n,n0) = 1 for every i in n such that i>=n0
- - u(n,n0) = 0 for every i in n such that i<n0
- Inputs :
- * n : numpy.array of int, discrete values where the step function will be evaluated
- * n0 : int, offset of the step function
- Outputs :
- * y : numpy.array, step function evaluated for n with offset n0
- Creation : 14-02-2020
- """
- out = np.empty(len(n))
- for i in range(0,len(n)):
- if (n[i]<n0):
- out[i] = 0
- else:
- out[i] = 1
- return out
- def r(n,n0):
- """r returns the ramp function for the discrete values in n with offset n0
- Inputs :
- * n : numpy.array of int, discrete values where the ramp function will be evaluated
- * n0 : int, offset of the ramp function
- Outputs :
- * y : numpy.array, ramp function evaluated for n with offset n0
- Creation : 14-02-2020
- """
- out = np.empty(len(n))
- for i in range(0,len(n)):
- if(n[i]-n0<=0):
- out[i] = 0
- else:
- out[i] = n[i]-n0
- return out
- def plotFig(y,n,name):
- """plotFig stem plot n for x axis and y for y axis and save the plot as an png
- Inputs :
- * y : array_like, the y axis values to be plotted
- * n : array_like, the x axis values to be plotted
- * name : string, name given to the saved png file
- Creation : 14-02-2020
- """
- # Création de la figure, de taille fixe.
- plt.figure(figsize=(6,3))
- (markerLines, stemLines, baseLines) = plt.stem(n,y,label="Signal")
- plt.setp(markerLines,color="white",markeredgecolor = 'black')
- plt.xlabel("n (seconds)")
- plt.ylabel("y[n]")
- plt.title("Signal plot {}".format(name))
- # Sauvegarde de la figure avec le bon noms.
- # Le second argument rétrécit les marges, par défaut relativement larges.
- plt.savefig(name + '.png', bbox_inches='tight')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement