fftc
Builtin index · Signal processing
result = rfft(x, [scaling=])
Input: x, scaling · Output: result
What it is
x: a length-N real vector (rfft) or real/complex vector (fftc). rfft returns a length-floor(N/2)+1 complex vector, the one-sided half-spectrum; fftc returns a length-N complex vector, the full spectrum. rfft is about twice as fast on real data since it only computes the non-redundant half. scaling= (optional string: "raw", the default, "amplitude" or "rms") picks the normalisation stamped on the result's X.norm — see *Frequency-Based Addressing* below — and requires x to be a Signal (the convention is metadata on Value::Spectrum; a bare CVec has nowhere to record it).
Overloads
One call shape — this function is not overloaded.
Code Input Output Description
result = rfft(x, [scaling=])x vector x: a length-N real vector (rfft) or real/complex vector (fftc).
scaling string or Signal, optional scaling= (optional string: "raw", the default, "amplitude" or "rms") picks the normalisation stamped on the result's X.norm — see *Frequency-Based Addressing* below — and requires x to be a Signal (the convention is metadata on Value::Spectrum.
CVec vector plain vector x
spectrum Signal Signal x
Returns a CVec (plain vector x) or a spectrum (Signal x): length floor(N/2)+1 from rfft, length N from fftc.
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
n = 0 :1 :1023
t = n / Fs
x = sin (2 *pi*80 *t) + 0.5 *sin (2 *pi*300 *t)
X = fftc (x)
mag = abs (X)[0 :512 ] # positive-frequency half
freqs = linspace (0 , Fs/2 , 512 )
peaks = find_peaks (mag, min_height =max (mag)*0.2 , min_distance =5 )
print ("tones at: {freqs[peaks]} Hz" )
plot (freqs, mag)
xlabel ("frequency (Hz)" )
output tones at: [80.234834, 300.391389] Hz
· plot: figure 2 (513 points)
0
50
100
150
200
250
300
350
400
450
500
-100
0
100
200
300
400
500
600
x=0.21, y=0
x=0.21, y=0
x=0.21, y=0
x=0.21, y=0
x=0.21, y=0
x=0.21, y=0
x=0.21, y=$10^{-9}$
x=0.21, y=$1.1\times10^{-9}$
x=0.21, y=$1.2\times10^{-9}$
x=0.21, y=$1.3\times10^{-9}$
x=0.21, y=$1.4\times10^{-9}$
x=0.21, y=$1.5\times10^{-9}$
x=0.21, y=$1.7\times10^{-9}$
x=0.21, y=$1.8\times10^{-9}$
x=0.21, y=$2\times10^{-9}$
x=0.21, y=$2.1\times10^{-9}$
x=0.21, y=$2.3\times10^{-9}$
x=0.21, y=$2.5\times10^{-9}$
x=0.21, y=$2.7\times10^{-9}$
x=0.21, y=$2.9\times10^{-9}$
x=0.21, y=$3.2\times10^{-9}$
x=0.21, y=$3.4\times10^{-9}$
x=0.21, y=$3.7\times10^{-9}$
x=0.21, y=$4\times10^{-9}$
x=0.21, y=$4.4\times10^{-9}$
x=0.21, y=$4.8\times10^{-9}$
x=0.21, y=$5.2\times10^{-9}$
x=0.21, y=$5.6\times10^{-9}$
x=0.21, y=$6.1\times10^{-9}$
x=0.21, y=$6.6\times10^{-9}$
x=0.21, y=$7.1\times10^{-9}$
x=0.21, y=$7.7\times10^{-9}$
x=0.21, y=$8.4\times10^{-9}$
x=0.21, y=$9.1\times10^{-9}$
x=0.21, y=$9.9\times10^{-9}$
x=0.21, y=$1.1\times10^{-8}$
x=0.21, y=$1.2\times10^{-8}$
x=0.21, y=$1.3\times10^{-8}$
x=0.21, y=$1.4\times10^{-8}$
x=0.21, y=$1.5\times10^{-8}$
x=0.21, y=$1.6\times10^{-8}$
x=0.21, y=$1.7\times10^{-8}$
x=0.21, y=$1.9\times10^{-8}$
x=0.21, y=$2\times10^{-8}$
x=0.21, y=$2.2\times10^{-8}$
x=0.21, y=$2.4\times10^{-8}$
x=0.21, y=$2.6\times10^{-8}$
x=0.21, y=$2.8\times10^{-8}$
x=0.21, y=$3.1\times10^{-8}$
x=0.21, y=$3.3\times10^{-8}$
x=0.21, y=$3.6\times10^{-8}$
x=0.21, y=$3.9\times10^{-8}$
x=0.21, y=$4.2\times10^{-8}$
x=0.21, y=$4.6\times10^{-8}$
x=0.21, y=$5\times10^{-8}$
x=0.21, y=$5.4\times10^{-8}$
x=0.21, y=$5.9\times10^{-8}$
x=0.21, y=$6.4\times10^{-8}$
x=0.21, y=$6.9\times10^{-8}$
x=0.21, y=$7.5\times10^{-8}$
x=0.21, y=$8.1\times10^{-8}$
x=0.21, y=$8.8\times10^{-8}$
x=0.21, y=$9.5\times10^{-8}$
x=0.21, y=$10^{-7}$
x=0.21, y=$1.1\times10^{-7}$
x=0.21, y=$1.2\times10^{-7}$
x=0.21, y=$1.3\times10^{-7}$
x=0.21, y=$1.4\times10^{-7}$
x=0.21, y=$1.5\times10^{-7}$
x=0.21, y=$1.7\times10^{-7}$
x=0.21, y=$1.8\times10^{-7}$
x=0.21, y=$2\times10^{-7}$
x=0.21, y=$2.1\times10^{-7}$
x=0.21, y=$2.3\times10^{-7}$
x=0.21, y=$2.5\times10^{-7}$
x=0.21, y=$2.7\times10^{-7}$
x=0.21, y=$3\times10^{-7}$
x=0.21, y=$3.2\times10^{-7}$
x=0.21, y=$3.5\times10^{-7}$
x=0.21, y=$3.8\times10^{-7}$
x=0.21, y=$4.1\times10^{-7}$
x=0.21, y=$4.4\times10^{-7}$
x=0.21, y=$4.8\times10^{-7}$
x=0.21, y=$5.2\times10^{-7}$
x=0.21, y=$5.7\times10^{-7}$
x=0.21, y=$6.1\times10^{-7}$
x=0.21, y=$6.7\times10^{-7}$
x=0.21, y=$7.2\times10^{-7}$
x=0.21, y=$7.8\times10^{-7}$
x=0.21, y=$8.5\times10^{-7}$
x=0.21, y=$9.2\times10^{-7}$
x=0.21, y=$10^{-6}$
x=0.21, y=$1.1\times10^{-6}$
x=0.21, y=$1.2\times10^{-6}$
x=0.21, y=$1.3\times10^{-6}$
x=0.21, y=$1.4\times10^{-6}$
x=0.21, y=$1.5\times10^{-6}$
x=0.21, y=$1.6\times10^{-6}$
x=0.21, y=$1.8\times10^{-6}$
x=0.21, y=$1.9\times10^{-6}$
x=0.21, y=$2.1\times10^{-6}$
x=0.21, y=$2.2\times10^{-6}$
x=0.21, y=$2.4\times10^{-6}$
x=0.21, y=$2.6\times10^{-6}$
x=0.21, y=$2.9\times10^{-6}$
x=0.21, y=$3.1\times10^{-6}$
x=0.21, y=$3.4\times10^{-6}$
x=0.21, y=$3.6\times10^{-6}$
x=0.21, y=$4\times10^{-6}$
x=0.21, y=$4.3\times10^{-6}$
x=0.21, y=$4.7\times10^{-6}$
x=0.21, y=$5\times10^{-6}$
x=0.21, y=$5.5\times10^{-6}$
x=0.21, y=$5.9\times10^{-6}$
x=0.21, y=$6.4\times10^{-6}$
x=0.21, y=$7\times10^{-6}$
x=0.21, y=$7.6\times10^{-6}$
x=0.21, y=$8.2\times10^{-6}$
x=0.21, y=$8.9\times10^{-6}$
x=0.21, y=$9.6\times10^{-6}$
x=0.21, y=$10^{-5}$
x=0.21, y=$1.1\times10^{-5}$
x=0.21, y=$1.2\times10^{-5}$
x=0.21, y=$1.3\times10^{-5}$
x=0.21, y=$1.4\times10^{-5}$
x=0.21, y=$1.6\times10^{-5}$
x=0.21, y=$1.7\times10^{-5}$
x=0.21, y=$1.8\times10^{-5}$
x=0.21, y=$2\times10^{-5}$
x=0.21, y=$2.2\times10^{-5}$
x=0.21, y=$2.3\times10^{-5}$
x=0.21, y=$2.5\times10^{-5}$
x=0.21, y=$2.8\times10^{-5}$
x=0.21, y=$3\times10^{-5}$
x=0.21, y=$3.2\times10^{-5}$
x=0.21, y=$3.5\times10^{-5}$
x=0.21, y=$3.8\times10^{-5}$
x=0.21, y=$4.1\times10^{-5}$
x=0.21, y=$4.5\times10^{-5}$
x=0.21, y=$4.9\times10^{-5}$
x=0.21, y=$5.3\times10^{-5}$
x=0.21, y=$5.7\times10^{-5}$
x=0.21, y=$6.2\times10^{-5}$
x=0.21, y=$6.7\times10^{-5}$
x=0.21, y=$7.3\times10^{-5}$
x=0.21, y=$7.9\times10^{-5}$
x=0.21, y=$8.6\times10^{-5}$
x=0.21, y=$9.3\times10^{-5}$
x=0.21, y=$10^{-4}$
x=0.21, y=$1.1\times10^{-4}$
x=0.21, y=$1.2\times10^{-4}$
x=0.21, y=$1.3\times10^{-4}$
x=0.21, y=$1.4\times10^{-4}$
x=0.21, y=$1.5\times10^{-4}$
x=0.21, y=$1.6\times10^{-4}$
x=0.21, y=$1.8\times10^{-4}$
x=0.21, y=$1.9\times10^{-4}$
x=0.21, y=$2.1\times10^{-4}$
x=0.21, y=$2.3\times10^{-4}$
x=0.21, y=$2.5\times10^{-4}$
x=0.21, y=$2.7\times10^{-4}$
x=0.21, y=$2.9\times10^{-4}$
x=0.21, y=$3.1\times10^{-4}$
x=0.21, y=$3.4\times10^{-4}$
x=0.21, y=$3.7\times10^{-4}$
x=0.21, y=$4\times10^{-4}$
x=0.21, y=$4.3\times10^{-4}$
x=0.21, y=$4.7\times10^{-4}$
x=0.21, y=$5.1\times10^{-4}$
x=0.21, y=$5.5\times10^{-4}$
x=0.21, y=$6\times10^{-4}$
x=0.21, y=$6.5\times10^{-4}$
x=0.21, y=$7\times10^{-4}$
x=0.21, y=$7.6\times10^{-4}$
x=0.21, y=$8.2\times10^{-4}$
x=0.21, y=$8.9\times10^{-4}$
x=0.21, y=$9.7\times10^{-4}$
x=0.21, y=0.001
x=0.21, y=0.001
x=0.21, y=0.001
x=0.21, y=0.001
x=0.21, y=0.001
x=0.21, y=0.002
x=0.21, y=0.002
x=0.21, y=0.002
x=0.21, y=0.002
x=0.21, y=0.002
x=0.209, y=0.002
x=0.209, y=0.002
x=0.209, y=0.003
x=0.209, y=0.003
x=0.209, y=0.003
x=0.209, y=0.003
x=0.209, y=0.003
x=0.209, y=0.004
x=0.208, y=0.004
x=0.208, y=0.004
x=0.208, y=0.004
x=0.207, y=0.004
x=0.207, y=0.005
frequency (Hz)
from signal-processing
How it works
DFT: fft(x) or fft(x, n) (zero-pads/truncates to n samples). fftc is an explicit-complex alias of fft (same function).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
rfft — documented in the same entry.