0
0
SciPydata~10 mins

FFT-based filtering 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 FFT of the signal array.

SciPy
import numpy as np
from scipy.fft import fft

signal = np.array([1, 2, 3, 4, 5])
fft_result = [1](signal)
Drag options to blanks, or click blank then click option'
Afftshift
Bifft
Crfft
Dfft
Attempts:
3 left
💡 Hint
Common Mistakes
Using ifft instead of fft will compute the inverse transform.
fftshift rearranges FFT output but does not compute FFT.
rfft computes FFT for real inputs but is not the general FFT function.
2fill in blank
medium

Complete the code to create a frequency mask that keeps frequencies below 10 Hz.

SciPy
import numpy as np
sampling_rate = 50  # Hz
n = 100
freqs = np.fft.fftfreq(n, d=1/sampling_rate)
mask = np.abs(freqs) [1] 10
Drag options to blanks, or click blank then click option'
A<
B>
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= or > will select frequencies above 10 Hz, which is incorrect.
Using <= includes 10 Hz exactly, which might be acceptable but the question asks for below 10.
3fill in blank
hard

Fix the error in the code to apply a low-pass filter using FFT.

SciPy
import numpy as np
from scipy.fft import fft, ifft

signal = np.sin(2 * np.pi * 5 * np.linspace(0, 1, 100)) + np.sin(2 * np.pi * 20 * np.linspace(0, 1, 100))
fft_signal = fft(signal)
freqs = np.fft.fftfreq(len(signal), d=1/100)
mask = np.abs(freqs) [1] 10
filtered_fft = fft_signal * mask
filtered_signal = ifft(filtered_fft).real
Drag options to blanks, or click blank then click option'
A<
B>
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using > or >= will keep high frequencies instead of low frequencies.
Using <= includes 10 Hz exactly, which might be acceptable but the question expects strictly less.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

SciPy
words = ['data', 'science', 'is', 'fun']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as value instead of its length.
Using <= instead of > will select shorter words.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary of uppercase keys and values greater than 0.

SciPy
data = {'a': 1, 'b': -2, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys without uppercase.
Filtering values less than or equal to zero.
Swapping keys and values.