Heaviside Function

I'm not sure if this already exists, but here it is. Incredibly useful!
Note: It's not the "true" Heaviside function, ie. the derivatives and integrals are not what you might expect, but it gets the job done.

Function Heaviside(xo)
//+
     Variable xo
     return p < xo ? 0 : 1
//+
End

//Usage example:
//
// Make test_wave = Heaviside(0)
//
//or for a function that "switches off" at a given point:
//
// Variable cutoff_point = 5
// Make test_wave2 = x - x*Heaviside(cutoff_point)
//
I would like to add a caution: you have used the p function inside your function, so this function will only work correctly on the right side of a wave assignment. It is more usual to write such things this way:

Function Heaviside(x, xo)
//+
     Variable x, xo
     return x < xo ? 0 : 1
//+
End


Then you would write your wave assignment like this:

Make test_wave = Heaviside(x, 0)
Make test_wave2 = x - x*Heaviside(x, cutoff_point)

A couple extra keystrokes, with the advantage that there are fewer surprises.

For instance, your function used like this:

print Heaviside(0)

will always return 1 because p returns 0 when there is no wave on the left side.

In fact, it's not hard to get the same functionality in an easy one-liner:

Make test_wave = x < 5

which works because in Igor, false is zero and true is 1.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More