The Real FFT (rfft) computes the Fast Fourier Transform of a real-valued input signal, returning only the positive frequency terms, which reduces computation and output size.
Click to reveal answer
beginner
Why use rfft instead of fft for real-valued signals?
Because real signals have symmetric frequency components, rfft returns only the positive half of the spectrum, making it faster and more memory efficient than fft.
Click to reveal answer
intermediate
What is the shape of the output array from scipy.fft.rfft for an input of length N?
The output array length is N//2 + 1, representing frequencies from 0 up to the Nyquist frequency.
Click to reveal answer
intermediate
How can you recover the original real signal from the rfft output?
You can use the inverse real FFT function scipy.fft.irfft to reconstruct the original real signal from the rfft output.
Click to reveal answer
intermediate
What is the Nyquist frequency in the context of rfft?
The Nyquist frequency is half the sampling rate and represents the highest frequency that can be accurately represented in the signal. rfft output includes this frequency as the last element.
Click to reveal answer
What type of input does scipy.fft.rfft expect?
AComplex-valued array
BBoolean array
CString data
DReal-valued array
✗ Incorrect
scipy.fft.rfft is designed for real-valued input arrays.
What is the length of the output of rfft for an input array of length 8?
A4
B8
C5
D7
✗ Incorrect
Output length is N//2 + 1, so 8//2 + 1 = 5.
Which function is used to invert the rfft transform?
Ascipy.fft.irfft
Bscipy.fft.ifft
Cscipy.fft.fft
Dscipy.fft.rfft
✗ Incorrect
scipy.fft.irfft is the inverse of rfft for real signals.
Why does rfft return fewer frequency components than fft?
ABecause it ignores negative frequencies for real inputs
BBecause it only works on half the data
CBecause it compresses the data
DBecause it uses a different algorithm
✗ Incorrect
Real signals have symmetric negative frequencies, so rfft returns only positive frequencies.
What does the last element of rfft output represent?
AThe DC component
BThe Nyquist frequency component
CThe highest negative frequency
DThe average value
✗ Incorrect
The last element corresponds to the Nyquist frequency component.
Explain how the Real FFT (rfft) differs from the standard FFT and why it is useful for real-valued signals.
Think about symmetry in frequency components for real signals.
You got /4 concepts.
Describe the process to recover the original time-domain signal after applying rfft.
Inverse transform is key to recovery.
You got /4 concepts.
Practice
(1/5)
1. What does the scipy.fft.rfft function compute when applied to a real-valued signal?
easy
A. The full complex Fourier transform including negative frequencies
B. The positive frequency components of the signal's Fourier transform
C. The inverse Fourier transform of the signal
D. The time-domain signal filtered by a low-pass filter
Solution
Step 1: Understand the input type
rfft is designed for real-valued input signals.
Step 2: Analyze the output of rfft
It returns only the positive frequency components because the negative frequencies are mirror images for real signals.
Final Answer:
The positive frequency components of the signal's Fourier transform -> Option B
Quick Check:
Real input -> half spectrum output [OK]
Hint: Real signals -> use rfft for positive frequencies only [OK]
Common Mistakes:
Confusing rfft with full fft output
Thinking rfft returns time-domain data
Assuming rfft returns negative frequencies
2. Which of the following is the correct way to import and use rfft from SciPy's FFT module?
easy
A. import scipy.fft as rfft
result = rfft.rfft(signal)
B. import scipy.rfft
result = scipy.rfft(signal)
C. from scipy.fft import rfft
result = rfft(signal)
D. from scipy import rfft
result = rfft.fft(signal)
Solution
Step 1: Recall correct import syntax
The rfft function is in scipy.fft, so import it directly from there.
Step 2: Check usage
Calling rfft(signal) after import is the correct usage.
Final Answer:
from scipy.fft import rfft\nresult = rfft(signal) -> Option C
Quick Check:
Correct import and call syntax [OK]
Hint: Import rfft directly from scipy.fft for simple use [OK]
Common Mistakes:
Trying to import rfft from scipy directly
Using wrong module names
Calling rfft as a method of scipy.fft without import
3. What is the output of the following code?
import numpy as np
from scipy.fft import rfft
signal = np.array([1, 0, -1, 0])
result = rfft(signal)
print(np.round(result, 2))
medium
A. [0.+0.j 1.+0.j 0.+0.j]
B. [0.+0.j 0.+0.j 0.+0.j]
C. [0.+0.j -2.+0.j 0.+0.j]
D. [0.+0.j 2.+0.j 0.+0.j]
Solution
Step 1: Understand the input signal
The signal is [1, 0, -1, 0], a simple 4-point real array.
Step 2: Compute rfft manually or recall pattern
rfft returns N/2+1 = 3 complex values for length 4 input. The values correspond to DC, positive frequency, and Nyquist frequency components. The result is approximately [0.+0.j, 2.+0.j, 0.+0.j].
Final Answer:
[0.+0.j 2.+0.j 0.+0.j] -> Option D
Quick Check:
rfft length 4 -> 3 outputs, middle value 2 [OK]
Hint: rfft output length = input//2 + 1 [OK]
Common Mistakes:
Expecting output length same as input
Ignoring complex number format
Misreading the signal values
4. Identify the error in this code snippet using rfft and fix it:
import numpy as np
from scipy.fft import rfft
signal = [1, 2, 3, 4]
result = rfft(signal, n=2)
print(result)
medium
A. The parameter n is smaller than signal length; use n=4 instead
B. The input signal must be a NumPy array, not a list
C. rfft does not accept the parameter n
D. The import statement is incorrect; use import scipy.fftpack
Solution
Step 1: Check the n parameter usage
The n parameter sets the length of the FFT. Here, n=2 is less than the signal length 4, so the signal is truncated.
Step 2: Fix the parameter to match or exceed signal length
Using n=4 ensures the full signal is transformed without truncation.
Final Answer:
The parameter n is smaller than signal length; use n=4 instead -> Option A
Quick Check:
FFT length must cover signal length [OK]
Hint: Set n ≥ signal length to avoid truncation [OK]
Common Mistakes:
Passing list instead of array (allowed but less efficient)
Ignoring effect of n parameter truncation
Wrong import module for rfft
5. You have a real sensor signal sampled at 100 Hz with 1000 points. You want to find the frequency with the highest amplitude using rfft. Which code snippet correctly computes this frequency?
hard
A. import numpy as np
from scipy.fft import rfft, rfftfreq
signal = np.random.rand(1000)
fft_vals = rfft(signal)
freqs = rfftfreq(len(signal), 1/100)
peak_freq = freqs[np.argmax(np.abs(fft_vals))]
print(peak_freq)
B. import numpy as np
from scipy.fft import fft
signal = np.random.rand(1000)
fft_vals = fft(signal)
freqs = np.fft.fftfreq(len(signal), 1/100)
peak_freq = freqs[np.argmax(np.abs(fft_vals))]
print(peak_freq)
C. import numpy as np
from scipy.fft import rfft
signal = np.random.rand(1000)
fft_vals = rfft(signal)
peak_freq = np.argmax(np.abs(fft_vals))
print(peak_freq)
D. import numpy as np
from scipy.fft import rfft, rfftfreq
signal = np.random.rand(1000)
fft_vals = rfft(signal)
freqs = rfftfreq(len(signal), 100)
peak_freq = freqs[np.argmax(np.abs(fft_vals))]
print(peak_freq)
Solution
Step 1: Use rfft and rfftfreq correctly
For real signals, rfft computes the positive frequencies, and rfftfreq gives the corresponding frequency bins. The sampling interval is 1/100 seconds.
Step 2: Find the peak frequency
Calculate the absolute values of FFT coefficients, find the index of the max, then map to frequency using freqs.
Final Answer:
Code snippet A correctly computes the peak frequency -> Option A
Quick Check:
Use rfft + rfftfreq with correct sampling interval [OK]
Hint: Use rfftfreq with 1/sampling_rate for correct frequencies [OK]
Common Mistakes:
Using fft and fftfreq for real signals (less efficient)
Wrong sampling interval in rfftfreq
Not mapping peak index to frequency
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.