imag
result = im(x)
Input: x · Output: result
What it is
Imaginary component of a Complex/CVec/CMat (0 elementwise when x is real). x is a scalar, Vec, or Mat (real or complex).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = im(x) | x Complex, CVec, Vec, CMat, Mat, or scalarnot documented yet | result Complex, Num, CVec, Vec, CMat, or Mat | Returns the same shape as x but always real-valued — a Complex gives a Num, a CVec a real Vec, a CMat a real Mat. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
fs = 1000
t = (0 to 999) / fs
x = sin(2*pi*100*t) + 0.5*sin(2*pi*300*t)
sig = signal(x, fs)
X = fft(sig)
print("df = {X.df} Hz, Nyquist = {X.nyquist} Hz")
print("power at 100 Hz: {band_power(X, 90, 110)}") # 0.5 = 1.0^2/2
print("power at 300 Hz: {band_power(X, 290, 310)}") # 0.125 = 0.5^2/2
clean = ifft(band_zero(X, 250, 350)) # notch out the 300 Hz tone
print("residual imaginary part: {max(abs(imag(clean)))}") # ~1e-16, still real
output
df = 1 Hz, Nyquist = 500 Hz power at 100 Hz: 0.5 power at 300 Hz: 0.125 residual imaginary part: 3.079059e-16
from signal-processing
x = 0.5
print("tan={tan(x)} asin={asin(x)} acos={acos(x)} atan={atan(x)}")
print("sinh={sinh(x)} cosh={cosh(x)} tanh={tanh(x)}")
print("ln(e^2)={ln(exp(2))} log(e^2)={log(exp(2))} log2(8)={log2(8)}")
z = 3 + 4j
print("arg={arg(z)} phase={phase(z)} re={re(z)} imag={imag(z)} im={im(z)} conj={conj(z)}")
print(ceil(2.1)) # 3
output
tan=0.546302 asin=0.523599 acos=1.047198 atan=0.463648 sinh=0.521095 cosh=1.127626 tanh=0.462117 ln(e^2)=2 log(e^2)=2 log2(8)=3 arg=0.927295 phase=0.927295 re=3 imag=4 im=4 conj=3 - 4j 3
from core-math
See also
im — documented in the same entry.