-1

I have a homework assignment where I have to make some functions, and autocorrelate, correlate and convolve them. I have to make a single sawtooth function/impulse with edges. I mean that from below x=0 every y=0 then from x€[0;5] a single sawtooth, and after that again, every y=0. And the same thing with a triangle function.

def saw(T, A = 1):
    return A*signal.sawtooth(-2*T/pi)

def tri(T, A = 1):
    return A*signal.triang(len(T))
Erik Gebhard
  • 23
  • 1
  • 9
  • 3
    Possible duplicate of [Creating an irregular sawtooth function in python](https://stackoverflow.com/questions/52405327/creating-an-irregular-sawtooth-function-in-python) – Duck Dodgers May 02 '19 at 08:47

1 Answers1

0

What about

fun*(T < limit)

or using the numpy.heaviside function?

Christian B.
  • 816
  • 6
  • 11
  • thats almost okay, the negative side is now zero, but when the sawtooth ends, the function too. – Erik Gebhard May 02 '19 at 09:07
  • Could you please elaborate? I though you want a single sawtooth from 0 to 5 and y=0 for x>5. Which means with signal.sawtooth(T*right_scale)*(T<5) it should work for T >= 0. In the end its a simple masking. You multiply your result array with a boolean array to zero out everything which is "not true" in the later array. – Christian B. May 02 '19 at 09:44
  • Got it working already, but your answer was the key. I just multiplied by *(T > -5)*(T<5). Thanks. – Erik Gebhard May 02 '19 at 09:53