Bird
Raised Fist0
Signal Processingdata~10 mins

Fourier Transform intuition in Signal Processing - Interactive Code Practice

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

Complete the code to create a simple sine wave signal.

Signal Processing
import numpy as np
import matplotlib.pyplot as plt

# Time array from 0 to 1 second with 500 samples
t = np.linspace(0, 1, 500)

# Frequency of the sine wave
freq = 5

# Create the sine wave signal
signal = np.sin(2 * np.pi * freq * [1])

plt.plot(t, signal)
plt.title('Sine Wave Signal')
plt.xlabel('Time (seconds)')
plt.ylabel('Amplitude')
plt.show()
Drag options to blanks, or click blank then click option'
Afreq
Bt
Cnp.pi
Dnp.linspace
Attempts:
3 left
💡 Hint
Common Mistakes
Using frequency instead of time in the sine function.
Using np.pi directly instead of the time array.
2fill in blank
medium

Complete the code to compute the Fourier Transform of the signal.

Signal Processing
import numpy as np

# Assume signal is defined as a numpy array
fourier_transform = np.fft.[1](signal)

# Get the magnitude of the transform
magnitude = np.abs(fourier_transform)
Drag options to blanks, or click blank then click option'
Afft
Bifft
Cfftshift
Difftshift
Attempts:
3 left
💡 Hint
Common Mistakes
Using inverse FFT instead of FFT.
Using fftshift which only rearranges the output.
3fill in blank
hard

Fix the error in the code to plot the frequency spectrum correctly.

Signal Processing
import numpy as np
import matplotlib.pyplot as plt

# Sampling rate and number of samples
fs = 500
N = 500

# Frequency array
freqs = np.fft.fftfreq(N, 1/[1])

# Fourier Transform of the signal
ft = np.fft.fft(signal)

plt.plot(freqs, np.abs(ft))
plt.title('Frequency Spectrum')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude')
plt.show()
Drag options to blanks, or click blank then click option'
Afs
Bfreqs
Csignal
DN
Attempts:
3 left
💡 Hint
Common Mistakes
Using number of samples instead of sampling rate.
Using the signal array instead of a numeric value.
4fill in blank
hard

Fill both blanks to create a dictionary of frequencies and their magnitudes for frequencies above zero.

Signal Processing
freq_magnitude = {freq: mag for freq, mag in zip(freqs, np.abs(ft)) if freq [1] 0 and freq [2] fs/2}
Drag options to blanks, or click blank then click option'
A>
B<
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= or <= which includes zero or Nyquist frequency incorrectly.
Reversing the inequality signs.
5fill in blank
hard

Fill all three blanks to create a normalized frequency magnitude dictionary for positive frequencies.

Signal Processing
normalized_freq_mag = {freq: mag/[1] for freq, mag in freq_magnitude.items() if freq [2] 0 and freq [3] fs/2}
Drag options to blanks, or click blank then click option'
Amax(np.abs(ft))
B>
C<
Dsum(np.abs(ft))
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by max magnitude instead of sum.
Using wrong inequality signs.

Practice

(1/5)
1. What does the Fourier Transform do to a signal?
easy
A. Breaks it into simple waves of different frequencies
B. Changes the signal into a random noise
C. Removes all frequencies except the highest
D. Converts the signal into a single number

Solution

  1. Step 1: Understand the purpose of Fourier Transform

    The Fourier Transform breaks a complex signal into simpler parts called sine and cosine waves.
  2. Step 2: Identify what the transform reveals

    It shows the different frequencies that make up the original signal.
  3. Final Answer:

    Breaks it into simple waves of different frequencies -> Option A
  4. Quick Check:

    Fourier Transform = signal broken into frequencies [OK]
Hint: Fourier Transform splits signals into frequency waves [OK]
Common Mistakes:
  • Thinking it removes frequencies instead of showing them
  • Believing it converts signal to a single number
  • Confusing it with noise generation
2. Which of the following is the correct syntax to compute the Fourier Transform of a signal array signal using NumPy in Python?
easy
A. np.fft.fft(signal)
B. np.fft.transform(signal)
C. np.fourier(signal)
D. np.fft.fourier_transform(signal)

Solution

  1. Step 1: Recall NumPy FFT function name

    NumPy uses np.fft.fft() to compute the Fourier Transform of a signal.
  2. Step 2: Check other options for correctness

    Other options are not valid NumPy functions for Fourier Transform.
  3. Final Answer:

    np.fft.fft(signal) -> Option A
  4. Quick Check:

    NumPy FFT function = np.fft.fft() [OK]
Hint: Use np.fft.fft() for Fourier Transform in NumPy [OK]
Common Mistakes:
  • Using incorrect function names like np.fft.transform
  • Confusing Fourier Transform with other NumPy functions
  • Misspelling 'fft'
3. Given the Python code:
import numpy as np
signal = np.array([1, 0, -1, 0])
ft = np.fft.fft(signal)
print(np.round(ft, 2))

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

Solution

  1. Step 1: Compute FFT of the signal [1, 0, -1, 0]

    The FFT of this 4-point signal results in complex values representing frequency components.
  2. Step 2: Calculate or recall FFT output

    The FFT output is [0.+0.j, 0.+2.j, 0.+0.j, 0.-2.j] after rounding to 2 decimals.
  3. Final Answer:

    [0.+0.j 0.+2.j 0.+0.j 0.-2.j] -> Option B
  4. Quick Check:

    FFT of [1,0,-1,0] = [0, 2j, 0, -2j] [OK]
Hint: FFT output shows complex frequency components [OK]
Common Mistakes:
  • Ignoring imaginary parts in FFT output
  • Mixing up real and imaginary values
  • Assuming FFT output is all real numbers
4. The following code attempts to compute the Fourier Transform but gives an error:
import numpy as np
signal = [1, 2, 3, 4]
ft = np.fft.fft(signal, n='4')
print(ft)

What is the error and how to fix it?
medium
A. Error: print statement syntax wrong, fix by adding parentheses
B. Error: signal must be a NumPy array, fix by converting signal to np.array
C. Error: np.fft.fft does not accept 'n' parameter, remove it
D. Error: 'n' must be an integer, fix by removing quotes: n=4

Solution

  1. Step 1: Identify the error cause

    The parameter n expects an integer, but a string '4' is given causing a type error.
  2. Step 2: Fix the error

    Remove quotes around 4 to pass an integer: n=4.
  3. Final Answer:

    Error: 'n' must be an integer, fix by removing quotes: n=4 -> Option D
  4. Quick Check:

    Parameter types must match function signature [OK]
Hint: Pass integer, not string, for numeric parameters [OK]
Common Mistakes:
  • Passing string instead of integer for 'n'
  • Not converting list to NumPy array (not error here)
  • Misreading error as print syntax issue
5. You have a noisy audio signal sampled at 1000 Hz. You want to remove frequencies above 300 Hz using Fourier Transform. Which steps correctly describe this process?
hard
A. Remove frequencies above 300 Hz directly from time signal, then compute FFT
B. Apply inverse FFT first, then remove frequencies above 300 Hz
C. Compute FFT, zero out frequencies above 300 Hz, then apply inverse FFT
D. Compute FFT, keep only frequencies above 300 Hz, then apply inverse FFT

Solution

  1. Step 1: Use FFT to convert time signal to frequency domain

    Compute the Fourier Transform to see all frequency components.
  2. Step 2: Filter frequencies above 300 Hz

    Set frequency components above 300 Hz to zero to remove noise.
  3. Step 3: Convert back to time domain

    Apply inverse FFT to get the cleaned time signal without high frequencies.
  4. Final Answer:

    Compute FFT, zero out frequencies above 300 Hz, then apply inverse FFT -> Option C
  5. Quick Check:

    Filter in frequency domain, then inverse FFT [OK]
Hint: Filter frequencies in FFT, then inverse transform [OK]
Common Mistakes:
  • Filtering in time domain instead of frequency domain
  • Applying inverse FFT before filtering
  • Keeping unwanted frequencies instead of zeroing them
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