在Python中绘制线性调频脉冲信号

问题描述 投票:0回答:1

维基百科定义:线性调频脉冲是频率随时间增加(向上线性调频脉冲)或减小(向下线性调频脉冲)的信号。在某些来源中,术语线性调频脉冲可与扫描信号互换使用。

我需要使用以下参数创建一个方形信号段:

  • 信号持续时间
  • 启动和停止频率
  • 开始和停止时的幅度
  • 启动和停止时的占空比

例如,信号以 10 Hz 开始,幅度为 10%,占空比为 20%,60 秒后在 20 Hz 处停止,幅度为 50%,占空比为 80 %。所有变化都是线性的。

Scipy 提供了 chirp 函数,可以构造 chirp 正弦波,您可以在其中指定 t0,f0 和 t1,f1。我想找到一个等效的方波信号,并且还可以线性改变占空比。 我正在寻找从类似的东西开始扫描信号

from matplotlib import pyplot as plt

x = numpy.linspace(0, 10, 1000)
y = numpy.array([1 if math.floor(2 * t) % 2 == 0 else 0 for t in x])
plt.plot(x,y)
plt.show()

只需要找到创建 numpy 数组的正确方程。有任何想法欢迎

python numpy matplotlib scipy signal-processing
1个回答
0
投票

我想我已经找到了解决方案:)

将线性调频函数(正弦波)转换为方波相对容易。正如 Mike 指出的那样,只需将 numpy 表中的值转换为 0 和 1 即可。

稍微复杂一点的是根据占空比变化的线性函数调制转换信号的宽度。但事实上,您所要做的就是将输出线性调频信号(基于余弦)与线性占空比函数的实例化值的余弦进行比较。

第一幅图显示了 crip 信号在 10 秒内从 6 Hz 变化到 1 Hz。 第二张图显示了该信号以占空比 = 50%(过零)进行转换。 第三张图显示了 charp 转换,占空比在 10 秒内从 10% 变化到 90%。

import numpy as np
from scipy.signal import chirp, spectrogram
import matplotlib.pyplot as plt

time_start, time_end = 0, 10
freq_start, freq_end = 6 , 1
duty_start, duty_end = 0.1, 0.9
samples = 1000
time = np.linspace(time_start, time_end, samples)
duty = np.linspace(duty_start,duty_end, samples)
cos_chirp = chirp(time, f0=freq_start, f1=freq_end, t1=time_end, method='linear')
sqr_chirp = np.array([1 if chirp(t, t1=time_end, f0=freq_start, f1=freq_end, method="linear") > 0 else -1 for t in time])
sqr_chirp_duty = np.array([1 if chirp(t, t1=time_end, f0=freq_start, f1=freq_end, method="linear") > 
                      np.cos(0 + np.pi*duty[i]) else -1 for i, t in enumerate(time)])
fig, axs = plt.subplots(3)
axs[0].plot(time, cos_chirp)
axs[1].plot(time, sqr_chirp)
axs[2].plot(time, sqr_chirp_duty)

plt.show()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.