📜  生成基本离散时间信号

📅  最后修改于: 2022-05-13 01:55:38.040000             🧑  作者: Mango

生成基本离散时间信号

为离散时间信号处理生成基本离散时间信号单位步长、单位脉冲、单位斜坡、指数信号是信号处理中非常常用的信号,用于执行各种操作。

  • 单位阶跃信号由下式给出
  • 单位脉冲信号由下式给出
  • 单位斜坡信号由下式给出
  • 指数信号由下式给出
例子:
Input :
Unit Step Signal u[n-2]
 
Output :

Input :
Unit Impulse Signal d(4)

Output :

Input :
Unit Ramp Signal

Output: 

Input:
Exponential signal for a=2

Output: 

代码:生成基本离散时间信号的Python代码实现

# importing libraries
import numpy as np
import matplotlib.pyplot as plt
  
# function to generate unit step u[n-a]
# LL and UL are lower and upper limits of discrete time line
def unit_step(a, n):
    unit =[]
    for sample in n:
        if sample= 0, r(n)= 0 otherwise
def unit_ramp(n):
    ramp =[]
    for sample in n:
        if sample<0:
            ramp.append(0)
        else:
            ramp.append(sample)
    return ramp
  
UL = 10
LL = -10
n = np.arange(LL, UL, 1)
r = unit_ramp(n)
plt.stem(n, r)
plt.xlabel('n')
plt.xticks(np.arange(LL, UL, 1))
plt.yticks([0, UL, 1])
plt.ylabel('r[n]')
plt.title('Unit Ramp r[n]')
plt.savefig("UnitRamp.png")
  
# Function to generate exponential signals e**(at)
def exponential(a, n):
    expo =[]
    for sample in n:
        expo.append(np.exp(a * sample))
    return (expo)
         
a = 2
UL = 1
LL = -1
n = np.arange(LL, UL, 0.1)
x = exponential(a, n)
plt.stem(n, x)
plt.xlabel('n')
plt.xticks(np.arange(LL, UL, 0.2))
# plt.yticks([0, UL, 1])
plt.ylabel('x[n]')
plt.title('Exponential Signal e**(an)')
plt.savefig("Exponential.png")