Challenge - 5 Problems
Downsampling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of simple downsampling with slicing
What is the output plot's number of points after downsampling the data by slicing every 3rd point?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 30) y = np.sin(x) x_downsampled = x[::3] y_downsampled = y[::3] plt.plot(x_downsampled, y_downsampled, 'o-') plt.title(f'Downsampled points: {len(x_downsampled)}') plt.show() print(len(x_downsampled))
Attempts:
2 left
💡 Hint
Remember slicing with step 3 picks every third element starting from index 0.
✗ Incorrect
The original array has 30 points (0 to 29). Slicing with step 3 picks indices 0, 3, 6, ..., 27, which is 10 points total.
❓ data_output
intermediate2:00remaining
Resulting data after averaging downsampling
Given a 1D numpy array of 12 values, what is the resulting array after downsampling by averaging every 4 points?
Matplotlib
import numpy as np data = np.array([2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]) # Downsample by averaging every 4 points downsampled = data.reshape(-1, 4).mean(axis=1) print(downsampled)
Attempts:
2 left
💡 Hint
Calculate the mean of each group of 4 consecutive numbers.
✗ Incorrect
The groups are [2,4,6,8], [10,12,14,16], and [18,20,22,24]. Their means are 5.0, 13.0, and 21.0 respectively.
❓ visualization
advanced2:00remaining
Visual difference between no downsampling and decimation
Which plot correctly shows the effect of decimation downsampling by factor 5 on a noisy sine wave?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 4 * np.pi, 500) y = np.sin(x) + np.random.normal(0, 0.1, 500) y_decimated = y[::5] x_decimated = x[::5] plt.figure(figsize=(10, 4)) plt.plot(x, y, label='Original') plt.plot(x_decimated, y_decimated, 'o-', label='Decimated (factor 5)') plt.legend() plt.title('Decimation Downsampling') plt.show()
Attempts:
2 left
💡 Hint
Decimation picks every nth point, so the decimated plot should have fewer points but follow the original shape.
✗ Incorrect
Decimation reduces points by picking every 5th point, so the decimated plot shows fewer points connected, preserving the sine shape but with less detail.
🧠 Conceptual
advanced2:00remaining
Effect of downsampling on signal frequency content
What is the main risk when downsampling a signal without applying a low-pass filter first?
Attempts:
2 left
💡 Hint
Think about what happens to frequencies higher than half the new sampling rate.
✗ Incorrect
Without low-pass filtering, high-frequency components fold back into lower frequencies causing aliasing, which distorts the signal.
🔧 Debug
expert2:00remaining
Identify the error in downsampling code using pandas resample
What error will this code raise when trying to downsample a time series by 2 minutes using pandas resample?
Matplotlib
import pandas as pd import numpy as np rng = pd.date_range('2024-01-01', periods=5, freq='T') data = pd.Series(np.arange(5), index=rng) # Attempt to downsample by 2 minutes result = data.resample('2min').mean() print(result)
Attempts:
2 left
💡 Hint
Check if '2min' is a valid frequency string for pandas resample.
✗ Incorrect
The code correctly uses '2min' frequency string and resample with mean works without error, producing averaged values over 2-minute intervals.