rectangular pulse train in python

前端 未结 3 2207
后悔当初
后悔当初 2021-01-06 22:02

I\'m trying to implement a rectangular pulse train in python.

I searched scipy and there is no signal that implements. http://docs.scipy.org/doc/scipy/reference/sign

3条回答
  •  清歌不尽
    2021-01-06 22:29

    All the answers are nice but I found they are having some problems with scipy.integrate so I created 3 types specially keeping in mind scipy.integrate:

    • Uniform width of pulses and uniform time period (each argument must be a single number).

    def uniform_pulse_function(self, t, start, stop, pulsewidth, period, amplitude):
            func = amplitude * np.where((t > start and t < stop and (t % period <(pulsewidth))),
                                        1, 0)

    • Uniform Pulsewidth but different amplitudes (each argument must be a single number except amplitude which should be a tuple of same length as the number of pulses that can be accommodated within start and stop):

    func = (amplitude[int(t//period)])*np.where((t>start and t

    • Non-uniform Pulsewidth and non uniform amplitude but period should remain constant (Amplitude and Pulsewidth should be a tuple of same length as the number of pulses that can be accommodated within start and stop while period should be a single number):

    def custom_pulse_function(self, t, start, stop, pulsewidth, period, amplitude):
            func = (amplitude[int(t//period)]) * np.where((t > start and t < stop and (t % period < (pulsewidth[int(t//period)]))), 1, 0)
            return func

提交回复
热议问题