0
0
SciPydata~10 mins

Real FFT (rfft) in SciPy - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Real FFT (rfft)
Input: Real-valued signal array
Apply rfft: Compute FFT for real input
Output: Complex frequency components (half spectrum)
Use magnitude/phase or power spectrum for analysis
The real FFT takes a real input signal and computes its frequency components efficiently, outputting half the spectrum as complex numbers.
Execution Sample
SciPy
import numpy as np
from scipy.fft import rfft

x = np.array([0, 1, 0, -1])
X = rfft(x)
print(X)
This code computes the real FFT of a simple 4-point signal and prints the frequency components.
Execution Table
StepActionInput SignalFFT Output (Complex)Explanation
1Start with input array[0, 1, 0, -1]-Input is a real-valued signal of length 4
2Apply rfft[0, 1, 0, -1][0.+0.j 0.-2.j 0.+0.j]Compute FFT for real input, output length is N/2+1=3
3Print output-[0.+0.j 0.-2.j 0.+0.j]Output shows DC, one frequency, and Nyquist components
4End--FFT computation complete
💡 All frequency components for the real input signal computed; output length is half plus one of input length.
Variable Tracker
VariableStartAfter rfftFinal
x[0, 1, 0, -1][0, 1, 0, -1][0, 1, 0, -1]
Xundefined[0.+0.j 0.-2.j 0.+0.j][0.+0.j 0.-2.j 0.+0.j]
Key Moments - 2 Insights
Why does the output length of rfft differ from the input length?
Because rfft exploits the input being real, it outputs only the first half plus one of the frequency components, as shown in execution_table step 2.
What do the complex numbers in the output represent?
Each complex number represents amplitude and phase of a frequency component. For example, in step 2, 0.-2.j means a frequency with magnitude 2 and phase -90 degrees.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is the length of the FFT output array?
A4
B2
C3
D1
💡 Hint
Check the 'FFT Output (Complex)' column at step 2 in execution_table.
At which step is the FFT output first available?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Look at the 'Action' and 'FFT Output' columns in execution_table.
If the input array length was 8, what would be the length of the rfft output?
A4
B5
C8
D7
💡 Hint
Recall rfft output length is input length divided by 2 plus 1.
Concept Snapshot
Real FFT (rfft) computes frequency components of a real input signal.
Input: real-valued array of length N.
Output: complex array of length N/2+1.
Output shows amplitude and phase of frequencies.
Efficient for real signals, saves computation and memory.
Full Transcript
We start with a real input signal array. The rfft function computes the frequency components efficiently by using the fact that the input is real. The output is a complex array representing the amplitudes and phases of frequencies, but only half the spectrum plus one element is returned. This reduces computation and memory use. The example shows a 4-point input and a 3-point output. Each step in the execution table tracks the input, the rfft call, and the output. Key points include understanding why the output length is shorter and what the complex numbers mean. The quizzes test understanding of output length and steps.