【问题标题】:Plot Frequency Sweep In Python在 Python 中绘制频率扫描
【发布时间】:2026-01-13 21:55:02
【问题描述】:

我想要一个频率随时间在[f_start : f_stop] 范围内线性增加的窦。

但是,在 Python 中创建适当的信号时,最后一个周期的频率大约是预期的两倍,2*f_stop

为什么?

这里有一些说明问题的最小 Python 代码:

import numpy
import matplotlib.pyplot as plt

Delta_t = 1     # Unit: Seconds
samples = 1000

total_time = samples*Delta_t
t = numpy.linspace(0,total_time,num=samples)

f_start = 1.0/total_time             # slow frequency (Period T = 1/f_start = 1000 samples)
f_stop = 100.0/total_time           # high frequency (Period T = 1/f_stop = 10 samples)
f_sweep = numpy.linspace(f_start,f_stop,num=samples) # Sweep from slow to high frequency


# Create Sinusoids
sinus_f_start = numpy.sin(2*numpy.pi*f_start*t)
sinus_f_stop = numpy.sin(2*numpy.pi*f_stop*t)
sinus_f_sweep = numpy.sin(2*numpy.pi*f_sweep*t)


# Plot all sinusoids
fig = plt.figure()

fig.add_subplot(311)
plt.plot(t,sinus_f_start)# Perfect! 1000 Samples per period.

fig.add_subplot(312)
plt.plot(t,sinus_f_stop) # Perfect! 10 Samples per period.

fig.add_subplot(313)
plt.plot(t,sinus_f_sweep)# Fail! Last period has 5 samples.

plt.show()

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:
     sin(w*t)  => the angular velocity is   d(w*t)/dt =   w
    
    sin(w*t*t) => the angular velocity is d(w*t*t)/dt = 2*w*t
    

    因此感知到的最大频率翻倍

    【讨论】:

    • 谢谢!为了实现线性扫描,频率为 w = 2*PI*(f_start+k/2*t),k 为斜率参数。
    • @Jack 如果我们说正弦函数的参数是一个角度 \theta 并且我们将角速度指定为时间的函数(无论时间依赖性如何),我们将不得不将角速度与关于时间,即 \theta = \theta_0 + \int_{t_0}^{t}\omega(\tau) d\tau。您为角速度的线性变化给出的表达式是可以的。咻