๐ Scenario: Imagine you want to understand how sounds, images, or sensor data are represented in computers. These are all examples of signals. Signals carry information that we can analyze and use.
๐ฏ Goal: You will create a simple example of a signal using a list of numbers. Then, you will set a threshold to identify which parts of the signal are strong. Finally, you will print the filtered signal values.
๐ What You'll Learn
Create a list called signal with exact values representing a simple signal
Create a variable called threshold with a specific numeric value
Use a list comprehension to create a new list called filtered_signal that keeps only values above the threshold
Print the filtered_signal list
๐ก Why This Matters
๐ Real World
Signals are everywhere: sounds, images, heartbeats, and sensor readings are all signals we analyze to understand the world.
๐ผ Career
Understanding signals is important for jobs in data science, engineering, healthcare, and technology where analyzing data streams is common.
Progress0 / 4 steps
1
Create a simple signal list
Create a list called signal with these exact values: [0, 2, 5, 3, 8, 1, 0, 4]
Signal Processing
Hint
Use square brackets [] to create a list and separate numbers with commas.
2
Set a threshold value
Create a variable called threshold and set it to the number 3
Signal Processing
Hint
Assign the number 3 to the variable threshold using the equals sign.
3
Filter the signal using the threshold
Use a list comprehension to create a new list called filtered_signal that contains only the values from signal that are greater than threshold
Signal Processing
Hint
Use [value for value in signal if value > threshold] to filter values.
4
Print the filtered signal
Write a print statement to display the filtered_signal list
Signal Processing
Hint
Use print(filtered_signal) to show the result.
Practice
(1/5)
1. What is a signal in simple terms?
easy
A. A fixed number that never changes
B. A type of computer program
C. A way to carry information about changes over time or space
D. A random noise with no meaning
Solution
Step 1: Understand the definition of a signal
A signal is something that carries information about changes, like sound or temperature over time.
Step 2: Compare options to the definition
Only A way to carry information about changes over time or space describes a signal as carrying information about changes over time or space.
Final Answer:
A way to carry information about changes over time or space -> Option C
Quick Check:
Signal = Information carrier [OK]
Hint: Signals carry info about change, not fixed values [OK]
Common Mistakes:
Thinking a signal is a fixed number
Confusing signal with software
Assuming signals have no meaning
2. Which of the following is the correct way to represent a simple signal in code?
easy
A. signal = [1, 2, 3, 4, 5]
B. signal = 'hello world'
C. signal = 42
D. signal = True
Solution
Step 1: Identify what a signal looks like in code
A signal is often a list or array of numbers representing values over time or space.
Step 2: Check each option
signal = [1, 2, 3, 4, 5] is a list of numbers, which fits the signal concept. Others are a string, a single number, or a boolean, which do not represent signals well.
Final Answer:
signal = [1, 2, 3, 4, 5] -> Option A
Quick Check:
Signal = list of numbers [OK]
Hint: Signals are lists or arrays of numbers [OK]
Common Mistakes:
Using strings or single values as signals
Confusing booleans with signals
Not using a sequence for signal data
3. Given the code below, what is the output?
signal = [10, 20, 30, 40]
average = sum(signal) / len(signal)
print(average)
medium
A. 40
B. 20
C. 30
D. 25.0
Solution
Step 1: Calculate the sum of the signal values
Sum = 10 + 20 + 30 + 40 = 100
Step 2: Calculate the average by dividing sum by number of elements
Average = 100 / 4 = 25.0
Final Answer:
25.0 -> Option D
Quick Check:
Average = 25.0 [OK]
Hint: Average = sum of values รท count [OK]
Common Mistakes:
Forgetting to divide by length
Using sum without parentheses
Mixing sum and max functions
4. Find the error in the code below that tries to calculate the average of a signal:
signal = [5, 15, 25]
average = sum(signal) / signal.length
print(average)
medium
A. signal should be a string, not a list
B. Using signal.length instead of len(signal)
C. Missing parentheses in print statement
D. Using sum() instead of average()
Solution
Step 1: Identify how to get list length in Python
Python uses len(list) to get length, not list.length.
Step 2: Check the code for length usage
The code uses signal.length which is invalid in Python and causes an error.
Final Answer:
Using signal.length instead of len(signal) -> Option B
Quick Check:
List length = len(list) [OK]
Hint: Use len() for list length in Python [OK]
Common Mistakes:
Using .length like in other languages
Confusing sum() with average()
Forgetting parentheses in print
5. You have a signal representing temperature readings every hour: temps = [22, 21, 23, 22, 24, 23]. How would you create a new signal that shows the change in temperature between each hour?
hard
A. changes = [temps[i+1] - temps[i] for i in range(len(temps)-1)]
B. changes = [temps[i] + temps[i+1] for i in range(len(temps))]
C. changes = [temps[i] * 2 for i in range(len(temps))]
D. changes = [temps[i] / temps[i+1] for i in range(len(temps)-1)]
Solution
Step 1: Understand the goal to find temperature changes between hours
We want the difference between each consecutive temperature reading.
Step 2: Check each option for correct difference calculation
changes = [temps[i+1] - temps[i] for i in range(len(temps)-1)] correctly subtracts temps[i] from temps[i+1] for all valid indices.
Final Answer:
changes = [temps[i+1] - temps[i] for i in range(len(temps)-1)] -> Option A
Quick Check:
Difference = next - current [OK]
Hint: Subtract consecutive values to find changes [OK]
Common Mistakes:
Adding instead of subtracting
Using wrong range causing index error
Multiplying or dividing instead of subtracting
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.