python 数字信号产生并求其FFT
本文写了一篇关于数字信号发生和做FFT处理的文章。
信号产生模块
这个模块用于产生单位阶跃信号、单位脉冲信号、简单的锯齿波信号。
也就是常用的数字信号处理中常用的序列。
话不多说,直接上代码:
signal_module.py:
import numpy as np
def saw_tooth(n0,n1,n2):
# Generates x(n)=saw_tooth
# -----------------------------------------
# n,x = saw_tooth(n0, n1, n2) n1 <= n0, n0 <= n2
num=0
if (n0<n1 or n2<n1 or n2<n0):
raise Exception('arguments must satisfy n1<=n0<=n2')
else:
n=np.arange(n1,n2+1)
x=np.zeros(len(n))
no = np.arange(len(n))
for a in no:
if a < n0-n1:
x[a]=0
else:
x[a]=num
num+=1
return n,x
def step_seq(n0,n1,n2):
# Generates
# x(n) = u(n - n0);
# n1 <= n0, n0 <= n2
if (n0<n1) or (n2<n1) or (n2<n0):
raise Exception('arguments must satisfy n1<&