Bird
Raised Fist0
Signal Processingdata~20 mins

Fast Fourier Transform (FFT) algorithm in Signal Processing - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
FFT Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of FFT on a simple signal

What is the output of the following Python code using numpy.fft.fft on a simple signal?

Signal Processing
import numpy as np
signal = np.array([1, 0, 1, 0])
fft_result = np.fft.fft(signal)
print(np.round(fft_result, 2))
A[2.+0.j 1.+0.j 0.+0.j 1.+0.j]
B[2.+0.j 1.-1.j 0.+0.j 1.+1.j]
C[1.+0.j 0.+0.j 1.+0.j 0.+0.j]
D[2.+0.j 0.+0.j 2.+0.j 0.+0.j]
Attempts:
2 left
💡 Hint

Remember FFT output is complex and symmetric for real inputs.

🧠 Conceptual
intermediate
1:30remaining
Understanding FFT frequency bins

For a signal sampled at 8 Hz with 8 samples, what frequency does the 3rd FFT bin represent?

A3 Hz
B1 Hz
C0.375 Hz
D4 Hz
Attempts:
2 left
💡 Hint

Frequency bin = (bin index) * (sampling rate / number of samples)

🔧 Debug
advanced
1:30remaining
Identify the error in FFT implementation

What error will this code raise?

import numpy as np
signal = [1, 2, 3]
fft_result = np.fft.fft(signal, n=2)
print(fft_result)
ANo error, outputs FFT of length 2
BTypeError: signal must be a numpy array
CValueError: n must be >= signal length
DIndexError: index out of range
Attempts:
2 left
💡 Hint

Check how FFT handles the n parameter when smaller than signal length.

❓ data_output
advanced
2:00remaining
FFT magnitude spectrum output

What is the magnitude spectrum output of this code?

import numpy as np
signal = np.array([0, 1, 0, -1])
fft_result = np.fft.fft(signal)
magnitude = np.abs(fft_result)
print(np.round(magnitude, 2))
A[0. 1. 0. 1.]
B[0. 2. 0. 2.]
C[2. 0. 2. 0.]
D[1. 0. 1. 0.]
Attempts:
2 left
💡 Hint

Magnitude is the absolute value of complex FFT output.

🚀 Application
expert
3:00remaining
Using FFT to detect dominant frequency

You have a signal sampled at 100 Hz with 1000 samples. Which code snippet correctly finds the dominant frequency in the signal?

A
import numpy as np
fft_vals = np.fft.fft(signal)
dominant_freq = np.argmax(np.abs(fft_vals))
print(dominant_freq)
B
import numpy as np
fft_vals = np.fft.fft(signal)
freqs = np.fft.fftfreq(len(signal), 100)
dominant_freq = freqs[np.argmax(fft_vals)]
print(dominant_freq)
C
import numpy as np
fft_vals = np.fft.fft(signal)
freqs = np.fft.fftfreq(len(signal), 1/100)
dominant_freq = freqs[np.argmax(np.abs(fft_vals))]
print(dominant_freq)
D
import numpy as np
fft_vals = np.fft.fft(signal)
freqs = np.fft.fftfreq(len(signal), 1/100)
dominant_freq = np.max(freqs)
print(dominant_freq)
Attempts:
2 left
💡 Hint

Remember to use fftfreq with correct sample spacing and find frequency corresponding to max magnitude.

Practice

(1/5)
1. What is the main purpose of the Fast Fourier Transform (FFT) algorithm in signal processing?
easy
A. To compress the signal data for storage
B. To convert a signal from time domain to frequency domain
C. To filter out noise from the signal
D. To increase the amplitude of the signal

Solution

  1. Step 1: Understand FFT role and compare options

    FFT transforms time-domain signal to frequency domain. A matches exactly; B is compression, C filtering, D amplification.
  2. Final Answer:

    To convert a signal from time domain to frequency domain -> Option B
  3. Quick Check:

    FFT = Time to Frequency conversion [OK]
Hint: FFT changes signal view from time to frequency fast [OK]
Common Mistakes:
  • Confusing FFT with noise filtering
  • Thinking FFT compresses data
  • Assuming FFT amplifies signals
2. Which of the following is the correct way to import the FFT function from NumPy in Python?
easy
A. from numpy import fft
B. import numpy.fft as fft
C. import fft from numpy
D. from numpy.fft import fft

Solution

  1. Step 1: Recall and match Python import syntax

    Correct for specific function: 'from numpy.fft import fft' (C). A imports submodule, B aliases submodule (requires fft.fft()), D invalid.
  2. Final Answer:

    from numpy.fft import fft -> Option D
  3. Quick Check:

    Correct import syntax = from numpy.fft import fft [OK]
Hint: Use 'from module import function' to import FFT [OK]
Common Mistakes:
  • Using 'import fft from numpy' which is invalid syntax
  • Importing whole numpy.fft as fft causing confusion
  • Trying 'from numpy import fft' which imports the module, not function
3. Given the Python code:
import numpy as np
signal = np.array([1, 0, -1, 0])
fft_result = np.fft.fft(signal)
print(np.round(fft_result, 2))

What is the output?
medium
A. [0.+0.j 0.+2.j 0.+0.j 0.-2.j]
B. [0.+0.j 0.+0.j 0.+0.j 0.+0.j]
C. [0.+0.j 2.+0.j 0.+0.j 2.+0.j]
D. [0.+0.j 1.+0.j 0.+0.j 1.+0.j]

Solution

  1. Step 1: Compute and verify FFT output

    np.fft.fft([1,0,-1,0]) corresponds to a sine wave component, resulting in imaginary parts at k=1 and k=3. The output is [0.+0.j 0.+2.j 0.+0.j 0.-2.j], matching [0.+0.j 0.+2.j 0.+0.j 0.-2.j].
  2. Final Answer:

    [0.+0.j 0.+2.j 0.+0.j 0.-2.j] -> Option A
  3. Quick Check:

    FFT sine wave = imaginary components at k=1,3 [OK]
Hint: Sine-like signals yield imaginary FFT components [OK]
Common Mistakes:
  • Confusing cosine signal with sine (imaginary output)
  • Confusing zeros with non-zero frequency components
  • Rounding incorrectly or not at all
4. Consider this Python code snippet:
import numpy as np
signal = [1, 2, 3, 4]
fft_result = fft(signal)
print(fft_result.real)

It raises an error. What is the most likely cause?
medium
A. signal should be a NumPy array, not a list
B. np.fft.fft does not have a real attribute
C. Missing import statement for fft
D. print statement syntax is incorrect

Solution

  1. Step 1: Trace code execution for error

    fft(signal) raises NameError: 'fft' undefined. Import is numpy as np (use np.fft.fft); no direct fft import (e.g., from numpy.fft import fft). A, B, D unrelated.
  2. Final Answer:

    Missing import statement for fft -> Option C
  3. Quick Check:

    Undefined fft = missing import [OK]
Hint: Import fft properly: from numpy.fft import fft [OK]
Common Mistakes:
  • Not importing the fft function when using fft()
  • Thinking .real is invalid on FFT output
  • Confusing print syntax errors
5. You have a noisy signal sampled at 1000 Hz stored in a NumPy array data. You want to remove frequencies above 100 Hz using FFT. Which approach correctly achieves this?
hard
A. Compute FFT, zero out components with frequency > 100 Hz, then inverse FFT
B. Compute FFT, keep only first 100 components, then inverse FFT
C. Apply FFT and multiply all values by 0.1 to reduce noise
D. Use FFT to find max frequency and subtract it from signal

Solution

  1. Step 1: Outline correct FFT low-pass filtering

    FFT to freq domain (use fftfreq for bins), zero coeffs where |freq| > 100 (fs=1000, cutoff index ~100/500=0.2*N), ifft back. Matches B precisely; A ignores freq mapping, C/D ineffective.
  2. Final Answer:

    Compute FFT, zero out components with frequency > 100 Hz, then inverse FFT -> Option A
  3. Quick Check:

    Zero high freq + ifft = low-pass filter [OK]
Hint: Zero unwanted FFT frequencies, then inverse transform [OK]
Common Mistakes:
  • Confusing component count with frequency
  • Scaling FFT values instead of zeroing
  • Misusing FFT to subtract frequencies directly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard