Challenge - 5 Problems
Time Shifting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of time-shifted discrete signal
What is the output of the following Python code that shifts a discrete signal by 2 units to the right?
Signal Processing
import numpy as np signal = np.array([1, 2, 3, 4, 5]) shift = 2 shifted_signal = np.zeros_like(signal) if shift > 0: shifted_signal[shift:] = signal[:-shift] else: shifted_signal[:shift] = signal[-shift:] print(shifted_signal.tolist())
Attempts:
2 left
💡 Hint
Think about how shifting right by 2 affects the indices of the array elements.
✗ Incorrect
Shifting the signal by 2 to the right means the first two elements become zero, and the rest are the original elements shifted right.
❓ data_output
intermediateLength of time-shifted continuous signal array
If you have a continuous signal sampled into 1000 points and you shift it by 100 points to the left using zero padding, what is the length of the resulting array?
Attempts:
2 left
💡 Hint
Shifting with zero padding keeps the array length the same.
✗ Incorrect
Time shifting with zero padding does not change the length of the signal array; it remains 1000.
❓ visualization
advancedIdentify the correct plot after time shifting
Given a sine wave signal sampled at 100 points, which plot correctly shows the signal shifted 10 points to the right with zero padding?
Signal Processing
import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2*np.pi, 100) signal = np.sin(x) shift = 10 shifted_signal = np.zeros_like(signal) shifted_signal[shift:] = signal[:-shift] plt.plot(signal, label='Original') plt.plot(shifted_signal, label='Shifted') plt.legend() plt.show()
Attempts:
2 left
💡 Hint
Right shift means zeros appear at the start of the shifted signal.
✗ Incorrect
The shifted signal has zeros for the first 10 points, then the sine wave starts, matching option A.
🧠 Conceptual
advancedEffect of negative time shift on signal indices
What happens to the indices of a discrete signal when it is shifted by a negative integer value (e.g., -3)?
Attempts:
2 left
💡 Hint
Negative shift means moving the signal earlier in time.
✗ Incorrect
A negative shift moves the signal left, so the start is earlier and zeros fill the right end.
🔧 Debug
expertIdentify the error in time shifting code
What error does the following code produce when shifting a signal by 3 to the right?
import numpy as np
signal = np.array([1, 2, 3, 4, 5])
shift = 3
shifted_signal = np.zeros_like(signal)
shifted_signal[:shift] = signal[shift:]
print(shifted_signal.tolist())
Signal Processing
import numpy as np signal = np.array([1, 2, 3, 4, 5]) shift = 3 shifted_signal = np.zeros_like(signal) shifted_signal[:shift] = signal[shift:] print(shifted_signal.tolist())
Attempts:
2 left
💡 Hint
Check the lengths of slices on left and right sides of the assignment.
✗ Incorrect
The slices shifted_signal[:shift] and signal[shift:] have different lengths, causing IndexError.
