Loading LOADSUB ALL FROM "WAVEFORM.HTS"
or LOADSUB Waveform FROM "MATHLIB.HTS"
or LOADSUB FROM "MATHLIB.HTS"
Usage INTEGER N
REAL P,A,B,S,Y(*)
CALL Waveform(P,A,B,S,N,Y(*))
Description
Waveform fills the array Y with a periodic waveform of type n having the period p, amplitude a, bias b, and starting point s. If Yk refers to an element of array Y, beginning with k = 0, the table below shows the expression for Yk for each value of n.
n
|
Type
|
Expression
|
1
|
sine
|
|
2
|
square
|
|
3
|
triangle
|
|
4
|
sawtooth
|
|
In the above expressions, fract(x) is the fractional part of x, calculated by finding the difference between x and the next lower integer from x. Fract(x) is between 0, inclusive, and 1, exclusive.
All the parameters may take any value except the period, p, which must be positive. P refers to the number of elements in the array Y between repetitions of the waveform. P and s do not need to be integers. The type, n, must be between 1 and 4, inclusive.
If p or s is contained in a variable of type INTEGER, be sure to use the BASIC REAL command to change the variable to a REAL value when passing it to the Pulse routine.
Other periodic waveforms can be produced using these four types. For example, a cosine wave can be produced from the sine waveform by setting s to -p/4. A falling sawtooth wave can be produced from the sawtooth waveform by using a negative value for a.
The four types of waveform are plotted on the following pages for a = 1, b = 0, s = 0, and p = 100.
Errors
Waveform causes an HTBasic error if its arguments are not of the types listed in the USAGE section, above, or if p is not positive, or if n is not between 1 and 4, inclusive.
See Also
Pulse
n = 1
n = 2
n = 3
n = 4
|