SPL Hot Variables

 

SPL includes an unusual but very powerful type of variable. Similar to a DADiSP Window, SPL hot variables link a formula to a variable. When a dependent element of the formula changes, the hot variable automatically re-evaluates. Hot variables are assigned with the := operator. For example,

 

svar = integ(w1)

 

hvar := integ(w1)

 

The standard variable svar is assigned the series that results by integrating W1. The hot variable hvar is assigned the formula integ(w1). The value of hvar is also the series that results by integrating W1. However, when the value of Window 1 changes, the value of hvar automatically updates, but svar does not.

 

Hot variables can also be assigned and evaluated with the sethotvar and gethotvar functions.

 

All hot variables are global, thus a hot variable and a standard global variable cannot have the same name. For a hot variable to automatically update, its formula must be dependent on some combination of windows and/or other hot variables.

 

Unlike a window, hot variables can assume any of the data types supported by standard variables. For example, to explore the effects of the moving average function on the data in Window 1, set up a scalar hot variable.

 

mlen := 10

 

In Window 2,

 

movavg(w1, mlen)

 

Now, to change the moving average length to 20, type:

 

mlen := 20

 

and the data in W2 automatically updates.

 

By using hot variables, here’s a remarkably simple demonstration of aliasing errors caused by undersampling a sinewave:

 

f := 1.0  

W1: gsin(100,.01,f);label(sprintf("Frequency: %g", f))

W2: spectrum(W1, 1024)

f := 1;while(f <= 100, f++)