Bird
Raised Fist0
SciPydata~20 mins

Why signal processing extracts information in SciPy - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Signal Processing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Fourier Transform on a Simple Signal
What is the output magnitude array of the Fourier Transform applied to a simple sine wave signal?
SciPy
import numpy as np
from scipy.fft import fft

# Create a sine wave signal
fs = 100  # Sampling frequency
f = 5     # Frequency of sine wave
x = np.linspace(0, 1, fs, endpoint=False)
signal = np.sin(2 * np.pi * f * x)

# Compute Fourier Transform
fft_result = fft(signal)
magnitude = np.abs(fft_result)
print(magnitude[:10])
A[0.0, 50.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
B[2.5e-15, 50.0, 1.2e-15, 1.1e-15, 1.0e-15, 1.0e-15, 1.1e-15, 1.2e-15, 1.3e-15, 1.4e-15]
C[2.5e-15, 0.0, 0.0, 0.0, 0.0, 50.0, 0.0, 0.0, 0.0, 0.0]
D[0.0, 25.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
Attempts:
2 left
💡 Hint
Look for the peak magnitude at the frequency of the sine wave.
❓ data_output
intermediate
2:00remaining
Number of Peaks Detected in a Noisy Signal
Given a noisy signal with multiple peaks, how many peaks does the scipy.signal.find_peaks function detect?
SciPy
import numpy as np
from scipy.signal import find_peaks

np.random.seed(0)
x = np.linspace(0, 6*np.pi, 1000)
signal = np.sin(x) + 0.5 * np.sin(3*x) + 0.2 * np.random.normal(size=1000)
peaks, _ = find_peaks(signal, height=0.5)
print(len(peaks))
A6
B9
C12
D15
Attempts:
2 left
💡 Hint
Consider the combined frequencies and the threshold height parameter.
❓ visualization
advanced
3:00remaining
Visualizing the Effect of a Low-Pass Filter
Which plot correctly shows the effect of applying a low-pass Butterworth filter to a noisy signal?
SciPy
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import butter, filtfilt

fs = 500
x = np.linspace(0, 1, fs, endpoint=False)
signal = np.sin(2*np.pi*5*x) + 0.5*np.sin(2*np.pi*50*x) + 0.3*np.random.normal(size=fs)

b, a = butter(4, 10, btype='low', fs=fs)
filtered = filtfilt(b, a, signal)

plt.figure(figsize=(10, 4))
plt.plot(x, signal, label='Noisy Signal')
plt.plot(x, filtered, label='Filtered Signal', linewidth=2)
plt.legend()
plt.title('Low-Pass Filter Effect')
plt.xlabel('Time [s]')
plt.ylabel('Amplitude')
plt.show()
APlot shows noisy signal with high-frequency noise and filtered signal smooth with only low-frequency components.
BPlot shows filtered signal with amplified high-frequency noise compared to original.
CPlot shows filtered signal identical to noisy signal with no smoothing.
DPlot shows filtered signal with added random noise spikes.
Attempts:
2 left
💡 Hint
Low-pass filters remove high-frequency noise, leaving smooth low-frequency signals.
🧠 Conceptual
advanced
1:30remaining
Why Signal Processing Extracts Information
Why does signal processing help extract meaningful information from raw data?
ABecause it transforms data to highlight patterns and reduce noise, making features clearer.
BBecause it compresses data without any loss of information.
CBecause it converts data into random noise to test system robustness.
DBecause it removes all data except the largest values, making analysis simpler.
Attempts:
2 left
💡 Hint
Think about how filtering and transformations help reveal hidden patterns.
🔧 Debug
expert
2:30remaining
Identify the Error in Signal Filtering Code
What error does the following code produce when applying a Butterworth filter, and why? import numpy as np from scipy.signal import butter, filtfilt fs = 100 x = np.linspace(0, 1, fs, endpoint=False) signal = np.sin(2 * np.pi * 10 * x) b, a = butter(4, 60, btype='low', fs=fs) filtered_signal = filtfilt(b, a, signal) print(filtered_signal[:5])
SciPy
import numpy as np
from scipy.signal import butter, filtfilt

fs = 100
x = np.linspace(0, 1, fs, endpoint=False)
signal = np.sin(2 * np.pi * 10 * x)

b, a = butter(4, 60, btype='low', fs=fs)
filtered_signal = filtfilt(b, a, signal)
print(filtered_signal[:5])
ANo error, code runs and prints filtered signal values.
BTypeError: butter() got an unexpected keyword argument 'fs'.
CRuntimeWarning: Filter coefficients are unstable causing NaN values in output.
DValueError: The critical frequency must be 0 < Wn < fs/2 because 60 is above Nyquist frequency.
Attempts:
2 left
💡 Hint
Check the critical frequency relative to the sampling frequency.

Practice

(1/5)
1. Why do we use signal processing to extract information from data?
easy
A. To make the data more complex and harder to understand
B. To clean and highlight important parts of the data
C. To delete all the data and keep nothing
D. To randomly change the data values

Solution

  1. Step 1: Understand the purpose of signal processing

    Signal processing is used to clean data and focus on useful parts.
  2. Step 2: Identify the correct purpose from options

    Only To clean and highlight important parts of the data says it cleans and highlights important data, which matches the purpose.
  3. Final Answer:

    To clean and highlight important parts of the data -> Option B
  4. Quick Check:

    Signal processing cleans data = A [OK]
Hint: Signal processing cleans data to find useful info [OK]
Common Mistakes:
  • Thinking signal processing makes data complex
  • Believing it deletes all data
  • Assuming it changes data randomly
2. Which of the following is the correct way to import the signal module from scipy?
easy
A. import scipy as signal
B. import signal from scipy
C. import scipy.signal
D. from scipy import signal

Solution

  1. Step 1: Recall Python import syntax

    The correct syntax to import a submodule is 'from package import module'.
  2. Step 2: Match options with correct syntax

    'from scipy import signal' is correct as it imports the signal module directly into the namespace. 'import scipy as signal' only aliases the scipy package. 'import signal from scipy' is invalid syntax. 'import scipy.signal' requires using scipy.signal.function().
  3. Final Answer:

    from scipy import signal -> Option D
  4. Quick Check:

    Correct import syntax = C [OK]
Hint: Use 'from scipy import signal' to import correctly [OK]
Common Mistakes:
  • Using invalid import syntax like 'import signal from scipy'
  • Forgetting 'from' keyword
  • Trying to import submodule directly without package
3. What will be the output of this code snippet?
from scipy import signal
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = signal.savgol_filter(x, window_length=3, polyorder=1)
print(np.round(y, 2))
medium
A. [1.33 2. 3. 4. 4.67]
B. [1. 2. 3. 4. 5. ]
C. [1.5 2.5 3.5 4.5 5.5]
D. [0.5 1.5 2.5 3.5 4.5]

Solution

  1. Step 1: Understand what savgol_filter does

    The Savitzky-Golay filter smooths data by fitting polynomials in windows.
  2. Step 2: Apply filter to input array

    With window_length=3 and polyorder=1, the filter smooths edges slightly, producing values close to but not identical to original.
  3. Final Answer:

    [1.33 2. 3. 4. 4.67] -> Option A
  4. Quick Check:

    Savgol filter smooths data = A [OK]
Hint: Savgol filter smooths edges, output differs slightly [OK]
Common Mistakes:
  • Expecting output to be identical to input
  • Confusing filter parameters
  • Rounding errors in output
4. Identify the error in this code that tries to apply a low-pass filter using scipy.signal:
from scipy import signal
import numpy as np
fs = 1000
cutoff = 100
b, a = signal.butter(4, cutoff, btype='low')
data = np.sin(2 * np.pi * 50 * np.linspace(0, 1, fs))
filtered = signal.lfilter(b, a, data)
print(filtered[:5])
medium
A. The sampling frequency fs is missing
B. The filter order 4 is too high for this data
C. The cutoff frequency should be normalized between 0 and 1
D. The signal.lfilter function is used incorrectly

Solution

  1. Step 1: Check butter function parameters

    scipy.signal.butter expects cutoff (Wn) normalized between 0 and 1 (fraction of Nyquist) when fs is not provided.
  2. Step 2: Examine the butter call

    signal.butter(4, cutoff, btype='low') uses cutoff=100 (>1) without fs, causing ValueError.
  3. Step 3: Confirm other options

    fs is defined but not passed; order 4 is fine; lfilter usage correct.
  4. Final Answer:

    The cutoff frequency should be normalized between 0 and 1 -> Option C
  5. Quick Check:

    Without fs, cutoff must be normalized 0-1 = D [OK]
Hint: Check if cutoff frequency needs normalization with butter [OK]
Common Mistakes:
  • Forgetting to normalize cutoff frequency when fs is missing
  • Confusing filter order with data size
  • Misusing lfilter parameters
5. You have noisy heart rate data sampled at 500 Hz. Which scipy.signal method helps extract the true heart rate by removing high-frequency noise?
hard
A. signal.butter with a low-pass filter
B. signal.medfilt to apply a median filter
C. signal.correlate to find repeating patterns
D. signal.spectrogram to visualize frequencies

Solution

  1. Step 1: Understand the problem context

    Noisy heart rate data needs noise removal to find true rate, especially removing high-frequency noise.
  2. Step 2: Identify suitable signal processing method

    Low-pass filters remove high-frequency noise, preserving slower heart rate signals. Butterworth filter is a common low-pass filter.
  3. Step 3: Evaluate other options

    Median filter removes spikes but less effective for frequency noise. Correlate finds patterns but does not filter noise. Spectrogram visualizes frequencies but does not filter.
  4. Final Answer:

    signal.butter with a low-pass filter -> Option A
  5. Quick Check:

    Low-pass filter removes high-frequency noise = B [OK]
Hint: Use low-pass butter filter to remove high-frequency noise [OK]
Common Mistakes:
  • Choosing median filter for frequency noise
  • Using correlate to filter noise
  • Confusing visualization with filtering
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