Butterfly Diagram in DSP: Formula & FFT Use

Formulas & functions · Updated November 23, 2026

The butterfly diagram in DSP is the graphical representation of the radix-2 Fast Fourier Transform (FFT) computation, and its core formula is X[k] = X0[k] + W_N^k * X1[k] and X[k+N/2] = X0[k] - W_N^k * X1[k], where W_N = e^(-2πi/N) is the twiddle factor. This two-output, two-input structure is the fundamental building block that reduces the DFT’s complexity from O(N²) to O(N log N).

What the Butterfly Diagram Represents

The butterfly diagram is a visual shorthand for a single stage of the radix-2 FFT. It shows two complex inputs entering from the left, a single complex multiplication by a twiddle factor, and two complex outputs leaving on the right. The name comes from the shape: the two inputs and two outputs with a crossing in the middle resemble a butterfly’s wings.

In the decimation-in-time (DIT) FFT, the butterfly computes:

  • Output1 = Input1 + W_N^k * Input2
  • Output2 = Input1 - W_N^k * Input2

Here Input1 is the even-indexed sample’s partial result and Input2 is the odd-indexed sample’s partial result at that stage. The twiddle factor W_N^k is a complex root of unity, defined as e^(-2πik/N) for an N-point FFT.

The Mathematical Derivation of the Butterfly Formula

The formula comes directly from the DFT definition:

X[k] = Σ_{n=0}^{N-1} x[n] * e^(-2πikn/N)

Splitting the sum into even and odd indices gives:

X[k] = Σ_{m=0}^{N/2-1} x[2m] * e^(-2πik(2m)/N) + Σ_{m=0}^{N/2-1} x[2m+1] * e^(-2πik(2m+1)/N)

Factoring out the twiddle factor from the odd part:

X[k] = X_even[k] + e^(-2πik/N) * X_odd[k]

Because X_even[k] and X_odd[k] are periodic with period N/2, the second half of the output is:

X[k+N/2] = X_even[k] - e^(-2πik/N) * X_odd[k]

This pair of equations is exactly the butterfly. For a concrete example, take N=8 and k=1: W_8^1 = e^(-2πi/8) = cos(π/4) - i sin(π/4) = 0.7071 - 0.7071i. If Input1 = 1+0i and Input2 = 0+1i, then Output1 = (1+0i) + (0.7071-0.7071i)*(0+1i) = 1 + 0.7071i + 0.7071 = 1.7071 + 0.7071i and Output2 = 1 - (0.7071+0.7071i) = 0.2929 - 0.7071i.

How the Butterfly Diagram Fits into the Full FFT

An N-point radix-2 FFT (where N is a power of 2) consists of log2(N) stages, each containing N/2 butterflies. For N=8, there are 3 stages and 4 butterflies per stage. The input is first bit-reversed, then butterflies are applied in a specific pattern.

In the first stage, the twiddle factors are all W_N^0 = 1, so no complex multiplication is needed. In the second stage, twiddle factors are W_N^0 and W_N^{N/4}. In the final stage, all distinct twiddle factors appear. The pattern of twiddle factors per stage is:

  • Stage 1: W_N^0 only
  • Stage 2: W_N^0, W_N^{N/4}
  • Stage 3: W_N^0, W_N^{N/8}, W_N^{2N/8}, W_N^{3N/8}
  • Stage m: W_N^{j*N/2^m} for j = 0 to 2^(m-1)-1

This systematic reuse of twiddle factors is what eliminates redundant computations. The total number of complex multiplications drops from N² to (N/2) log2(N). For N=1024, that’s 5120 multiplications instead of 1,048,576.

Decimation-in-Time vs. Decimation-in-Frequency

The butterfly diagram described above is for the decimation-in-time (DIT) FFT, which splits the input sequence into even and odd indices. There is also a decimation-in-frequency (DIF) FFT, which splits the output frequency indices. The DIF butterfly has a slightly different structure:

  • DIT: Inputs are even/odd indexed; twiddle factor is applied to one input before the add/subtract.
  • DIF: Inputs are first half/second half; twiddle factor is applied after the add/subtract.

Both produce the same result, but the bit-reversal occurs at the output for DIF instead of the input. The DIF butterfly formula is:

Temp = Input1 + Input2
Output1 = Temp
Output2 = (Input1 - Input2) * W_N^k

In practice, DIT is more common in textbooks, but DIF is used in some hardware implementations because it allows in-place computation with a different memory access pattern.

Common Misconceptions About the Butterfly Diagram

One frequent error is thinking the twiddle factor is always W_N^k with k being the global frequency index. In reality, k is the local index within each butterfly group, ranging from 0 to (group size/2 – 1). For example, in stage 2 of an 8-point FFT, there are two groups of 4 butterflies, and k goes 0,1,0,1 across the four butterflies.

Another misconception is that the butterfly diagram is only for FFT. The same structure appears in the inverse FFT (IFFT), with the twiddle factor changed to W_N^{-k} and a final division by N. Also, the butterfly is used in other transforms like the discrete cosine transform (DCT) when implemented via FFT.

Some also believe that the butterfly diagram is a hardware component. It is not; it is a signal flow graph. In hardware, it is implemented with adders, subtractors, and complex multipliers, but the diagram itself is an algorithmic abstraction.

Practical Implementation in Code

When implementing the butterfly in a programming language, the key is to update the two outputs in-place to save memory. A typical Python loop for a single butterfly might look like:

def butterfly(a, b, w):
    t = w * b
    return a + t, a - t

In a full FFT, you iterate over stages and groups. For example, in Python with numpy, the core loop for a DIT FFT is:

import numpy as np
def fft(x):
    N = len(x)
    X = np.asarray(x, dtype=complex)
    # bit-reversal permutation
    X = X[np.bitwise_xor.outer(np.arange(N), 0)]  # simplified; use actual bit-reversal
    for m in range(1, int(np.log2(N))+1):
        length = 2**m
        for k in range(0, N, length):
            for j in range(length//2):
                w = np.exp(-2j*np.pi*j/length)
                u = X[k+j]
                v = X[k+j+length//2] * w
                X[k+j] = u + v
                X[k+j+length//2] = u - v
    return X

Note that the twiddle factor w uses length as the current sub-DFT size, not the global N. This is a common source of bugs. In MATLAB, the built-in fft function uses an optimized version, but you can write your own for learning.

Choosing the Right FFT Variant

For most applications, you don’t need to implement the butterfly yourself; libraries like FFTW, Intel MKL, or numpy’s fft are highly optimized. However, understanding the butterfly helps when:

  • You need a fixed-point implementation for embedded systems.
  • You are working with non-power-of-2 sizes and need mixed-radix FFTs.
  • You are optimizing for cache performance or parallel processing.

If N is not a power of 2, you can zero-pad to the next power of 2, but this increases computation. Alternatively, use a mixed-radix FFT that handles factors of 3, 5, etc. The butterfly for radix-4 is more complex but reduces the number of complex multiplications further.

Frequently Asked Questions

What is the twiddle factor in the butterfly diagram?
The twiddle factor is the complex exponential W_N^k = e^(-2πik/N). It rotates one of the two inputs before the addition and subtraction. It varies by stage and by butterfly position.

Why is it called a butterfly diagram?
Because the signal flow graph looks like a butterfly: two inputs on the left, two outputs on the right, with a crossing in the middle. The term was popularized in early FFT literature.

Can I use the butterfly diagram for inverse FFT?
Yes. For the inverse FFT, use the same butterfly structure but with twiddle factors W_N^{-k} (i.e., positive exponent) and divide the final output by N. Some implementations also use a different scaling.

How many butterflies are in an N-point FFT?
There are (N/2) * log2(N) butterflies. For N=8, that’s 4 * 3 = 12 butterflies. Each butterfly performs one complex multiplication and two complex additions.

What is bit-reversal and why is it needed?
Bit-reversal is the permutation of input indices where the binary representation of each index is reversed. In the DIT FFT, the input must be in bit-reversed order before the first stage. This is because the even/odd splitting recursively reorders the indices.

Does the butterfly diagram work for real-valued signals?
Yes, but you can exploit the symmetry of real signals to compute two real FFTs with one complex FFT, or use a real-only FFT algorithm. The butterfly itself still uses complex arithmetic, but you can pack two real samples into one complex number.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.