16 频谱 psd / magnitude_spectrum
用途
频域幅值与功率分布,谐波分析、振动分析、噪声分析的核心工具。
示例(5 张)
16-1 母线电压谐波功率谱(含 3/5/7 次谐波)

16-2 变频器输出电流谐波频谱(柱状对数纵轴)

16-3 异步电机振动加速度频谱(含转频与轴承故障频率)

16-4 风电功率波动的功率谱密度

16-5 并网逆变器开关频率附近噪声频谱

代码
以下 5 个函数取自 code/第四批_信号与三维261106.py,直接调用即可出图。版式(宋体 + Times、10 磅、刻度朝内四边、图内无标题、留白自检)由 code/公共配置261106.py 的 setup_cn_style() 与 save() 统一提供。
# 摘自 code/第四批_信号与三维261106.py
def psd_01():
"""母线电压谐波功率谱(含 3/5/7 次谐波)。"""
fig, ax = new_fig()
rng = np.random.default_rng(701)
fs = 6400
t = np.arange(0, 1.0, 1 / fs)
x = (311 * np.sin(2 * np.pi * 50 * t)
+ 18 * np.sin(2 * np.pi * 150 * t + 0.4)
+ 26 * np.sin(2 * np.pi * 250 * t + 1.1)
+ 11 * np.sin(2 * np.pi * 350 * t + 2.0)
+ rng.normal(0, 2.0, t.size))
ax.psd(x, NFFT=2048, Fs=fs, color=C1, lw=0.9, label="电压信号")
ax.set_xscale("log")
ax.set_xlim(10, 3200)
ax.grid(False)
ax.set_xlabel("频率 " + IT["f"] + " / Hz")
ax.set_ylabel("功率谱密度 / dB")
legend(ax, "upper right", ncol=1)
save(fig, "16_频谱", "16_频谱_母线电压谐波功率谱")
def psd_02():
"""变频器输出电流谐波频谱(柱状对数纵轴)。"""
fig, ax = new_fig()
rng = np.random.default_rng(702)
h = np.arange(1, 31)
amp = 120 / h ** 1.1
amp[2], amp[4], amp[6] = 26, 38, 17
amp = amp + rng.uniform(0, 2.2, h.size)
ax.bar(h * 50, amp, width=14, color=C1, edgecolor="0.35", linewidth=0.4,
label="谐波幅值")
ax.set_yscale("log")
ax.set_xlabel("频率 " + IT["f"] + " / Hz")
ax.set_ylabel("电流幅值 " + IT["I"] + SUB["h"] + " / A")
ax.set_xlim(0, 1550)
ax.set_ylim(1, 200)
legend(ax, "upper right", ncol=1)
save(fig, "16_频谱", "16_频谱_变频器电流谐波")
def psd_03():
"""异步电机振动加速度频谱(含转频与轴承故障频率)。"""
fig, ax = new_fig()
rng = np.random.default_rng(703)
fs = 5000
t = np.arange(0, 2.0, 1 / fs)
x = (1.8 * np.sin(2 * np.pi * 24.7 * t)
+ 0.9 * np.sin(2 * np.pi * 49.4 * t)
+ 0.55 * np.sin(2 * np.pi * 148 * t)
+ 0.35 * np.sin(2 * np.pi * 312 * t)
+ rng.normal(0, 0.12, t.size))
ax.magnitude_spectrum(x, Fs=fs, color=C1, lw=0.8, scale="dB",
label="振动信号")
ax.grid(False)
ax.set_xlim(0, 900)
ax.set_xlabel("频率 " + IT["f"] + " / Hz")
ax.set_ylabel("幅值 / dB")
legend(ax, "upper right", ncol=1)
save(fig, "16_频谱", "16_频谱_电机振动加速度谱")
def psd_04():
"""风电功率波动的功率谱密度。"""
fig, ax = new_fig()
rng = np.random.default_rng(704)
n = 4096
f = np.fft.rfftfreq(n, d=1.0)
P = np.zeros_like(f)
P[1:] = 1e3 / f[1:] ** (5 / 3)
P[1:] *= rng.gamma(3.0, 1 / 3.0, P.size - 1)
ax.loglog(f[1:], P[1:], color=C5, lw=0.8, label="功率谱")
fk = np.array([1e-3, 5e-1])
ax.loglog(fk, 2.2e1 / fk ** (5 / 3), color=C2, lw=1.0, ls="--",
label="−5/3 参考斜率")
ax.set_xlim(1e-3, 5e-1)
ax.set_xlabel("频率 " + IT["f"] + " / Hz")
ax.set_ylabel("功率谱密度 / (kW²/Hz)")
legend(ax, "lower left", ncol=1)
save(fig, "16_频谱", "16_频谱_风电功率波动谱")
def psd_05():
"""并网逆变器开关频率附近噪声频谱。"""
fig, ax = new_fig()
rng = np.random.default_rng(705)
f = np.linspace(2000, 20000, 900)
base = 1.2e-3 * (f / 2000) ** -0.45
peak = 8e-3 * np.exp(-((f - 10000) / 420) ** 2) \
+ 3e-3 * np.exp(-((f - 20000) / 380) ** 2) \
+ 1.6e-3 * np.exp(-((f - 5000) / 300) ** 2)
y = base + peak + rng.uniform(0, 2.4e-4, f.size)
ax.semilogy(f, y, color=C1, lw=0.8, label="噪声谱")
ax.set_xlabel("频率 " + IT["f"] + " / Hz")
ax.set_ylabel("电压噪声密度 / (V/√Hz)")
ax.set_xlim(2000, 20000)
legend(ax, "upper right", ncol=1)
save(fig, "16_频谱", "16_频谱_逆变器开关噪声")
说明
- 图片 1181×944 px(100 mm × 80 mm @ 300 dpi),三维图为 1181×1122 px。
- 图内不放标题,图题由本文件的标题承担。
- 数据为 10 kV 配网、380 V 低压、50 Hz 量级的仿真算例,随机种子固定,重跑结果一致。
浙公网安备 33010602011771号