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();