0
0
SciPydata~10 mins

Real FFT (rfft) in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to compute the real FFT of the signal array.

SciPy
import numpy as np
from scipy.fft import [1]
signal = np.array([0, 1, 0, -1])
result = [1](signal)
Drag options to blanks, or click blank then click option'
Arfft
Bfft
Cifft
Dirfft
Attempts:
3 left
💡 Hint
Common Mistakes
Using fft instead of rfft causes output to be complex and longer.
Using ifft or irfft is for inverse transforms, not forward.
2fill in blank
medium

Complete the code to compute the frequencies corresponding to the rfft output.

SciPy
import numpy as np
from scipy.fft import rfft, [1]
signal = np.array([0, 1, 0, -1])
sample_rate = 4
freqs = [1](len(signal), 1/sample_rate)
Drag options to blanks, or click blank then click option'
Afftfreq
Bfftshift
Cirfft
Drfftfreq
Attempts:
3 left
💡 Hint
Common Mistakes
Using fftfreq returns frequencies for full FFT, not real FFT.
Using irfft or fftshift does not return frequencies.
3fill in blank
hard

Fix the error in the code to correctly compute the inverse real FFT.

SciPy
import numpy as np
from scipy.fft import rfft, [1]
signal = np.array([0, 1, 0, -1])
transformed = rfft(signal)
recovered = [1](transformed)
Drag options to blanks, or click blank then click option'
Aifft
Birfft
Crfft
Dfft
Attempts:
3 left
💡 Hint
Common Mistakes
Using ifft instead of irfft may cause shape mismatch.
Using rfft or fft again does not invert the transform.
4fill in blank
hard

Fill both blanks to create a dictionary of frequencies and their corresponding rfft magnitudes.

SciPy
import numpy as np
from scipy.fft import rfft, rfftfreq
signal = np.array([0, 1, 0, -1])
sample_rate = 4
freqs = [1](len(signal), 1/sample_rate)
magnitudes = np.abs([2](signal))
result = dict(zip(freqs, magnitudes))
Drag options to blanks, or click blank then click option'
Arfftfreq
Brfft
Cfft
Dirfft
Attempts:
3 left
💡 Hint
Common Mistakes
Using fft instead of rfft causes mismatch in frequencies and magnitudes.
Using irfft instead of rfft for magnitudes is incorrect.
5fill in blank
hard

Fill all three blanks to compute the normalized power spectrum of a real signal.

SciPy
import numpy as np
from scipy.fft import rfft, rfftfreq
signal = np.array([0, 1, 0, -1])
sample_rate = 4
freqs = [1](len(signal), 1/sample_rate)
transform = [2](signal)
power = np.square(np.abs(transform)) / [3](signal)
Drag options to blanks, or click blank then click option'
Arfftfreq
Brfft
Cfloat
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using float(len(signal)) instead of len(signal) causes type issues.
Using fftfreq instead of rfftfreq causes frequency mismatch.