在Python中绘制频率扫描

时间:2014-09-23 16:05:05

标签: python matplotlib

我希望随着时间的推移,[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()

1 个答案:

答案 0 :(得分:3)

 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
因此,感知最大频率加倍