Triangle wave shaped array in Python

前端 未结 6 1194
生来不讨喜
生来不讨喜 2021-02-08 04:22

What is the most efficient way to produce an array of 100 numbers that form the shape of the triangle wave below, with a max/min amplitude of 0.5?

Triangle waveform in m

6条回答
  •  我在风中等你
    2021-02-08 04:38

    Triangle is absolute value of sawtooth.

    from scipy import signal
    time=np.arange(0,1,0.001)
    freq=3
    tri=np.abs(signal.sawtooth(2 * np.pi * freq * time)) 
    

提交回复
热议问题