View Raw SPL
/*****************************************************************************
* *
* GHALFSIN.SPL Copyright (C) 2020 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Generates a half sin function *
* *
* Revisions: 12 May 2020 RRR Creation *
* *
*****************************************************************************/
#if @HELP_GHALFSIN
GHALFSIN
Purpose: Generates a half sin function in accordance with the specified
parameters.
Syntax: GHALFSIN(length, spacing, tau)
length - An integer, the length of the output series.
Defaults to 1000 samples.
spacing - A real, the spacing (delta X) between each point
on the X axis. Defaults to 1/1000.
tau - Optional. A real, the time duration of the
half sin. Defaults to 0.5 seconds.
Returns: A series.
Example:
W1: ghalfsin()
Generates 1000 samples of a half sin samples at 1000 Hz where
the non-zero duration is 0.5 seconds.
Example:
W2: ghalfsin(2000, 1/2000, 0.1)
Generates 2000 samples of a half sin sampled at 2000 Hz where
the non-zero duration is 0.1 seconds.
Remarks:
The half sin function returns values equal to the first half
of the period of a sin and zero everywhere else.
The function is useful in shock response testing.
Tau determines the time duration of the half sine.
See Also:
Ghaversin
Gsin
Haversin
Sin
#endif
/* generate a half sinewave of duration tau */
ghalfsin(N, dx, tau)
{
local h;
if (argc < 3)
{
if (argc < 2)
{
if (argc < 1) N = 1000;
dx = 1 / N;
}
tau = 0.5;
}
h = gsin(N, dx, 1 / (2 * tau));
h[find(xvals(h) > tau)] = 0;
setvunits(h, "G");
return(h);
}