Signal functions¶
The functions in this section describe non-sinusoidal waveforms, which are often used in signal processing and electronics.
Square wave signal¶
squarew()
¶
- mpmath.squarew(t, amplitude=1, period=1)¶
Computes the square wave function using the definition:
\[x(t) = A(-1)^{\left\lfloor{2t / P}\right\rfloor}\]where \(P\) is the period of the wave and \(A\) is the amplitude.
Examples
Square wave with period = 2, amplitude = 1
>>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> squarew(0,1,2) 1.0 >>> squarew(0.5,1,2) 1.0 >>> squarew(1,1,2) -1.0 >>> squarew(1.5,1,2) -1.0 >>> squarew(2,1,2) 1.0
Triangle wave signal¶
trianglew()
¶
- mpmath.trianglew(t, amplitude=1, period=1)¶
Computes the triangle wave function using the definition:
\[x(t) = 2A\left(\frac{1}{2}-\left|1-2 \operatorname{frac}\left(\frac{x}{P}+\frac{1}{4}\right)\right|\right)\]where \(\operatorname{frac}\left(\frac{t}{T}\right) = \frac{t}{T}-\left\lfloor{\frac{t}{T}}\right\rfloor\) , \(P\) is the period of the wave, and \(A\) is the amplitude.
Examples
Triangle wave with period = 2, amplitude = 1
>>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> trianglew(0,1,2) 0.0 >>> trianglew(0.25,1,2) 0.5 >>> trianglew(0.5,1,2) 1.0 >>> trianglew(1,1,2) 0.0 >>> trianglew(1.5,1,2) -1.0 >>> trianglew(2,1,2) 0.0
Sawtooth wave signal¶
sawtoothw()
¶
- mpmath.sawtoothw(t, amplitude=1, period=1)¶
Computes the sawtooth wave function using the definition:
\[x(t) = A\operatorname{frac}\left(\frac{t}{T}\right)\]where \(\operatorname{frac}\left(\frac{t}{T}\right) = \frac{t}{T}-\left\lfloor{\frac{t}{T}}\right\rfloor\), \(P\) is the period of the wave, and \(A\) is the amplitude.
Examples
Sawtooth wave with period = 2, amplitude = 1
>>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> sawtoothw(0,1,2) 0.0 >>> sawtoothw(0.5,1,2) 0.25 >>> sawtoothw(1,1,2) 0.5 >>> sawtoothw(1.5,1,2) 0.75 >>> sawtoothw(2,1,2) 0.0
Unit triangle signal¶
unit_triangle()
¶
- mpmath.unit_triangle(t, amplitude=1)¶
Computes the unit triangle using the definition:
\[x(t) = A(-\left| t \right| + 1)\]where \(A\) is the amplitude.
Examples
Unit triangle with amplitude = 1
>>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> unit_triangle(-1,1) 0.0 >>> unit_triangle(-0.5,1) 0.5 >>> unit_triangle(0,1) 1.0 >>> unit_triangle(0.5,1) 0.5 >>> unit_triangle(1,1) 0.0
Sigmoid wave signal¶
sigmoid()
¶
- mpmath.sigmoid(t, amplitude=1)¶
Computes the sigmoid function using the definition:
\[x(t) = \frac{A}{1 + e^{-t}}\]where \(A\) is the amplitude.
Examples
Sigmoid function with amplitude = 1
>>> from mpmath import * >>> mp.dps = 25; mp.pretty = True >>> sigmoid(-1,1) 0.2689414213699951207488408 >>> sigmoid(-0.5,1) 0.3775406687981454353610994 >>> sigmoid(0,1) 0.5 >>> sigmoid(0.5,1) 0.6224593312018545646389006 >>> sigmoid(1,1) 0.7310585786300048792511592