Qu

ifft

Builtin index · Signal processing

result = ifft(X, [n])

Input: X, n · Output: result

What it is

Inverse DFT, same underlying kernel as fft run in reverse. X is a length-N complex vector (CVec); n (optional number, default N) is the target length, same zero-pad/truncate rule as fft.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = ifft(X, [n])
X vector or CVecX is a length-N complex vector (CVec).
n number, optionaln (optional number, default N) is the target length, same zero-pad/truncate rule as fft.
result CVec
Returns a length-n CVec.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

xr = real(ifft(X, N))
print("round-trip err = {max(abs(xr - x)):.2e}")
output
round-trip err = 4.93e-32

from numerics-dsp

t = 1, 2, ..., 50        # N = 50, not a power of two

x = sin(t)
X = fft(x)
print("length(X) = {length(X)}")
print("round trip err = {max(abs(real(ifft(X)) - x)):.2e}")
output
length(X) = 50
round trip err = 3.33e-16

from numerics-dsp

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