一、连续函数的取样
连续函数必须经过取样和量化转换为离散函数,才能用计算机进行处理。
-
考虑一个连续函数 f(t),以自变量 t 的均匀间隔 ΔT 对函数取样,取样序列中的任意取样值为:
取样后的函数的傅里叶变换为:
香农(Shannon)取样定理指出,对于一个连续信号,用大于信号最高频率 2倍的取样率来取样,则不会丢失信号的有效信息。
或者说,以 1 / Δ T 1/\Delta T1/ΔT 的取样率对信号取样点的的最大频率是。
二、例程
- 8.4:连续函数的取样
# 8.4:连续函数的取样
import numpy as np
from matplotlib import pyplot as plt
# 定义函数,用于计算所有基矢的频率
def gen_freq(N, fs):
k = np.arange(0, np.floor(N/2) + 1, 1)
return (k * fs) / N
T = 100
# 定义多个不同频率的基频信号
fk = [2/T, 5/T, 12/T] # 频率
A = [7, 3, 2] # 振幅
phi = [np.pi, 2, 2*np.pi] # 初始相位
n = np.arange(T)
s0 = A[0] * np.sin(2 * np.pi * fk[0] * n + phi[0])
s1 = A[1] * np.sin(2 * np.pi * fk[1] * n + phi[1])
s2 = A[2] * np.sin(2 * np.pi * fk[2] * n + phi[2])
s = s0 + s1 + s2 # 叠加生成混合信号
g = np.fft.rfft(s) # 傅里叶变换
plt.figure(figsize=(8, 6))
plt.subplot(311)
plt.plot(n, s0, n, s1, n, s2, ':', marker='+', alpha=0.5)
plt.plot(n, s, 'r-', lw=2)
plt.title("Sampling of continuous functions")
plt.subplot(312)
fs = 1 # 采样间隔为 1
freq = gen_freq(T, fs=fs) # 计算频率序列
ck = np.abs(g) / T # 计算振幅
plt.plot(freq, ck, '.') # 频率-振幅图
for f in fk:
ck0 = round(ck[np.where(freq==f*fs)][0], 1)
plt.annotate('$({},{})$'.format(f*fs, ck0), xy=(f*fs, ck0), xytext=(5, -10), textcoords='offset points')
plt.subplot(313)
fs = 10 # 采样间隔为 10
freq = gen_freq(T, fs=fs) # 计算频率序列
ck = np.abs(g) / T # 计算振幅
plt.plot(freq, ck, '.') # 频率-振幅图
for f in fk:
ck0 = round(ck[np.where(freq==f*fs)][0], 1)
plt.annotate('$({},{})$'.format(f*fs, ck0), xy=(f*fs, ck0), xytext=(5, -10), textcoords='offset points')
plt.show()
三、资料
youcans_的博客:
https://blog.csdn.net/youcans/article/details/122519452