python正三角形_Python中的正三角形脉冲

I want to create a positive triangle pulse. I want to be able to define the amplitude, rise and fall time as well as the number points in them.

From the documentation of scipy (https://docs.scipy.org/doc/scipy/reference/signal.html), I found the 'sawtooth' wave form and I am trying to utilize it.

The problem I face is that, the said waveform, oscillates between 1,-1, but I want it to go from 0 till a specified positive limit. Here is an example of what I want to make:

This pulse will be use to correlate data from a detector, so it is important to be able to specify rise/fall time and the points in them, in order to experiment and get the best possible clarity out of it.

Can I manipulate the 'sawtooth' signal to get what I want? Or do I have to create the signal myself? If the only option is to create it, could I have some help as to how I could define it in python?

Thank you for your time!

解决方案

A solution could be to use linear interpolation to build the wanted function. If you want a periodic pulse function, numpy.interp has a period option in order to wrap the x-axis periodically. Otherwise, remove the argument, the function will remains 0 after the first pulse.

rise_duration = 1

fall_duration = 3

period = 6

control_points_x = [0, rise_duration, rise_duration+fall_duration]

control_points_y = [0, 1, 0]

x = np.linspace(0, 14, 123)

triangular_pulses = np.interp(x, control_points_x, control_points_y, period=period)

# Graph

plt.plot(x, triangular_pulses, label='interpolation');

plt.plot(control_points_x, control_points_y, 'ok', label='control points')

plt.xlabel('x'); plt.ylabel('y'); plt.legend();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值