irfft
Builtin index · Signal processing
result = irfft(half_spectrum, n)
Input: half_spectrum, n · Output: result
What it is
Inverse of rfft. half_spectrum is a length-floor(n/2)+1 complex vector (CVec); n (required number), the real output length, can't be recovered from the half-spectrum's length alone (even and odd n can share a half-length).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = irfft(half_spectrum, n) | half_spectrum vector or CVechalf_spectrum is a length-floor(n/2)+1 complex vector (CVec).n numbern (required number), the real output length, can't be recovered from the half-spectrum's length alone (even and odd n can share a half-length). | result vector | Returns a length-n real vector. (fftr is a deprecated second name for this — see below.) |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
half = rfft(x) # length floor(N/2)+1
back = irfft(half, length(x))
from numerics-dsp
fs = 1000
n = 0:1:63
t = n / fs
x = sin(2*pi*100*t)
X = fft(x)
xr = idft(X)
print("idft roundtrip max err: {max(abs(xr - x))}")
k100 = 100 * length(x) / fs # bin index equivalent to 100 Hz
bin100 = goertzel(x, k100)
print("goertzel magnitude at bin {k100}: {abs(bin100)}")
same = goertzel_freq(x, fs, 100) # the Hz-parameterized convenience form
print("goertzel_freq agrees: {abs(same - bin100) < 1e-9}")
half = rfft(x)
back = irfft(half, 64)
print("rfft/irfft roundtrip max err: {max(abs(back - x))}")
idft roundtrip max err: 1.604386e-14 goertzel magnitude at bin 6.4: 32.158025 goertzel_freq agrees: true rfft/irfft roundtrip max err: 3.330669e-16
from signal-processing
How it works
irfft(half_spectrum, n) -- n (the real output length) is required since it can't be recovered from the half-spectrum's length alone (both even and odd n can share a half-length). fftr is an alias ("the real-valued inverse fft").
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.