View Raw SPL
/*****************************************************************************
* *
* SLP.SPL Copyright (C) 1998-2020 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Digital emulation of single pole analog low pass filter *
* *
* Revisions: 12 Feb 1998 RRR Creation - from SPOLE.MAC *
* 19 Apr 2020 RRR use filteq, optional filter coef return *
* *
*****************************************************************************/
#if @HELP_SLP
SLP
Purpose: Emulates a single pole analog low pass filter.
Syntax: SLP(s, fc)
(b, a) = SLP(s, fc)
(b, a, yout) = SLP(s, fc)
s - Input series
fc - Optional real, cutoff frequency in Hertz, defaults
to rate(s) / 10.
Returns: A series, the low pass filtered result.
(b, a) = SLP(s, fc) returns the low pass filter coefficients
derived from the input data.
(b, a, yout) = SLP(s, fc) returns the filter coefficients and
the filtered result.
Example:
W1: gsqrwave(100, .01, 4)
W2: slp(w1, 10)
Lowpass filters the squarewave in W1 with a cutoff frequency
of 10 Hz. The sample rate is set to the sample rate of the
input data.
Example:
W1: gsqrwave(100, .01, 4)
W2: (b, a) = slp(w1, 10);filteq(b, a, w1)
Same as above accept the filter coefficients are obtained
and the input data is explicitly processed using
FILTEQ.
Remarks:
The single pole analog lowpass filter is implemented in the
digital domain using the impulse invariance technique.
See Also:
Filteq
Shp
#endif
/* Single pole low pass analog filter */
ITERATE slp(s, fc)
{
local b1, b, a, rc, ts, lps;
if (argc < 2)
{
if (argc < 1) error("slp - input series required");
fc = rate(s) / 10;
}
/* sample interval */
ts = deltax(s);
/* inverse frequency in radians */
rc = 1 / (2 * pi * fc);
/* impulse invariant transformation */
b1 = exp(-1.0 * ts / rc);
b = {1 - b1};
a = {1, -b1};
if (outargc == 2)
{
/* (b, a) = slp(s) - just return coefficients */
return(b, a);
}
/* calculate via difference equation */
lps = filteq(b, a, s);
/* set output sample interval */
setdeltax(lps, deltax(s));
if (outargc > 2)
{
return(b, a, lps);
}
else
{
return(lps);
}
}