📖 Scenario: Imagine you have a simple signal represented by a list of numbers. This signal could be a sound wave, a sensor reading, or any data changing over time. Sometimes, you want to shift this signal forward or backward in time to analyze or compare it.
🎯 Goal: You will create a Python program that shifts a signal by a given number of time steps. Positive shifts move the signal forward (delay), and negative shifts move it backward (advance). The empty spaces created by shifting will be filled with zeros.
📋 What You'll Learn
Create a list called signal with exact values: [3, 5, 7, 9, 11]
Create an integer variable called shift_amount with the value 2
Write code to shift the signal by shift_amount steps, filling empty spots with 0
Print the shifted signal list
💡 Why This Matters
🌍 Real World
Time shifting signals is common in audio processing, sensor data analysis, and communications to align or compare signals.
💼 Career
Understanding how to manipulate signals by shifting is a basic skill for data scientists working with time series or signal data.
Progress0 / 4 steps
1
Create the original signal list
Create a list called signal with these exact values: [3, 5, 7, 9, 11]
Signal Processing
Hint
Use square brackets to create a list and separate numbers with commas.
2
Set the shift amount
Create an integer variable called shift_amount and set it to 2
Signal Processing
Hint
Just assign the number 2 to the variable shift_amount.
3
Shift the signal by the shift amount
Write code to create a new list called shifted_signal that shifts the signal by shift_amount steps forward. Fill empty positions with 0. Use list slicing and concatenation.
Signal Processing
Hint
Use [0]*shift_amount to create zeros and signal[:-shift_amount] to slice the list.
4
Print the shifted signal
Print the shifted_signal list to see the result
Signal Processing
Hint
Use print(shifted_signal) to display the shifted list.
Practice
(1/5)
1. What does a positive time shift do to a signal in signal processing?
easy
A. It advances the signal, moving it backward in time.
B. It delays the signal, moving it forward in time.
C. It changes the signal's amplitude.
D. It reverses the signal in time.
Solution
Step 1: Understand time shift direction
A positive time shift means the signal is moved to a later time, which delays it.
Step 2: Compare options with definition
Only It delays the signal, moving it forward in time. correctly states that a positive shift delays the signal.
Final Answer:
It delays the signal, moving it forward in time. -> Option B
Quick Check:
Positive shift = delay [OK]
Hint: Positive shift means delay, negative means advance [OK]
Common Mistakes:
Confusing positive shift with advancing the signal
Thinking time shift changes amplitude
Mixing up delay and reversal
2. Which of the following is the correct Python syntax to shift a discrete signal array x by 3 units forward (delay)?
easy
A. shifted_x = np.roll(x, 3)
B. shifted_x = np.roll(x, -3)
C. shifted_x = x + 3
D. shifted_x = x.shift(3)
Solution
Step 1: Understand np.roll behavior
In numpy, np.roll(x, 3) shifts elements to the right by 3, delaying the signal.
Step 2: Check other options
shifted_x = x.shift(3) is invalid syntax for numpy arrays, np.roll(x, -3) shifts left (advances), x + 3 adds 3 to values (not time shift).
Final Answer:
shifted_x = np.roll(x, 3) -> Option A
Quick Check:
np.roll with positive shift delays signal [OK]
Hint: np.roll with positive number delays signal [OK]
Common Mistakes:
Using negative shift to delay signal
Adding number to array instead of rolling
Using non-existent shift method
3. Given the signal array x = [1, 2, 3, 4, 5], what is the output of np.roll(x, -2)?
medium
A. [4, 5, 1, 2, 3]
B. [2, 3, 4, 5, 1]
C. [3, 4, 5, 1, 2]
D. [5, 1, 2, 3, 4]
Solution
Step 1: Understand np.roll with negative shift
Negative shift moves elements to the left by 2 positions.
Forgetting to convert list to numpy array (not required here)
5. You have two signals sampled at the same rate: s1 = [0, 1, 2, 3, 4] and s2 = [3, 4, 0, 1, 2]. Which time shift applied to s1 aligns it best with s2?