📖 Scenario: You are working on a simple real-time digital signal processing (DSP) pipeline. The pipeline processes audio samples from a microphone, applies a filter, and outputs the processed samples.This project simulates the pipeline steps using Python lists to represent audio samples.
🎯 Goal: Build a step-by-step DSP pipeline that:Creates an initial list of audio samples.Sets a threshold to filter out low amplitude noise.Applies the threshold filter to the samples.Prints the filtered output samples.
📋 What You'll Learn
Create a list called audio_samples with exact values: 0.1, 0.5, 0.05, 0.7, 0.2
Create a variable called noise_threshold and set it to 0.1
Use a list comprehension to create filtered_samples that includes only samples greater than noise_threshold
Print the filtered_samples list
💡 Why This Matters
🌍 Real World
Real-time DSP pipelines are used in audio devices to clean and enhance sound by removing noise and unwanted signals.
💼 Career
Understanding DSP pipelines is important for roles in audio engineering, telecommunications, and embedded systems development.
Progress0 / 4 steps
1
Create the initial audio samples list
Create a list called audio_samples with these exact values: 0.1, 0.5, 0.05, 0.7, 0.2
Signal Processing
Hint
Use square brackets [] to create a list and separate values with commas.
2
Set the noise threshold
Create a variable called noise_threshold and set it to 0.1
Signal Processing
Hint
Use the assignment operator = to set the variable.
3
Filter samples above the noise threshold
Use a list comprehension to create a list called filtered_samples that contains only the values from audio_samples that are greater than noise_threshold
Signal Processing
Hint
Use the syntax: [item for item in list if condition] to filter the list.
4
Print the filtered samples
Print the filtered_samples list
Signal Processing
Hint
Use print(filtered_samples) to display the list.
Practice
(1/5)
1. What is the main purpose of a real-time DSP processing pipeline?
easy
A. To process signals step-by-step as data arrives
B. To store large amounts of data for later analysis
C. To generate random signals for testing
D. To visualize signals after processing is complete
Solution
Step 1: Understand real-time processing
Real-time DSP means processing data immediately as it comes in, not storing for later.
Step 2: Identify pipeline purpose
The pipeline processes signals step-by-step to analyze or clean them on the fly.
Final Answer:
To process signals step-by-step as data arrives -> Option A
Quick Check:
Real-time DSP = step-by-step processing [OK]
Hint: Real-time means processing data immediately as it arrives [OK]
Common Mistakes:
Confusing real-time with batch processing
Thinking pipeline stores data only
Assuming visualization is the main goal
2. Which of the following is the correct syntax to apply a moving average filter on a signal array data in Python using a window size of 3?
easy
A. filtered = [sum(data[i:i+3])*3 for i in range(len(data)-2)]
B. filtered = [sum(data[i:i+3])/3 for i in range(len(data)-2)]
C. filtered = [sum(data[i:i+3])/3 for i in range(len(data)+2)]
D. filtered = sum(data[i:i+3])/3 for i in range(len(data)-2)
Solution
Step 1: Understand moving average filter
It averages each group of 3 consecutive elements in the data.
Step 2: Check syntax correctness
filtered = [sum(data[i:i+3])/3 for i in range(len(data)-2)] correctly uses list comprehension with range(len(data)-2) and divides sum by 3.
Final Answer:
filtered = [sum(data[i:i+3])/3 for i in range(len(data)-2)] -> Option B
Quick Check:
Correct list comprehension with proper range and division [OK]
Hint: Use range(len(data)-window+1) for correct slicing [OK]
Common Mistakes:
Missing brackets for list comprehension
Using wrong range length causing index errors
Multiplying instead of dividing for average
3. Given the Python code below for a simple real-time DSP pipeline, what is the output of print(filtered_signal)?
signal = [1, 3, 5, 7, 9]
window_size = 2
filtered_signal = [ (signal[i] + signal[i+1]) / 2 for i in range(len(signal)-1) ]
print(filtered_signal)
medium
A. [1.0, 4.0, 6.0, 8.0]
B. [1.0, 3.0, 5.0, 7.0, 9.0]
C. [2.0, 4.0, 6.0, 8.0]
D. [3.0, 5.0, 7.0, 9.0]
Solution
Step 1: Understand the list comprehension
It averages each pair of consecutive elements: (signal[i] + signal[i+1]) / 2.
4. The following code attempts to implement a moving average filter but raises an error. What is the error and how to fix it?
data = [2, 4, 6, 8]
window = 3
filtered = []
for i in range(len(data)):
avg = (data[i] + data[i+1] + data[i+2]) / window
filtered.append(avg)
print(filtered)
medium
A. IndexError because indexing goes beyond list end; fix by using range(len(data)-window+1)
B. ZeroDivisionError because window is zero; fix by setting window to 1
C. TypeError because sum cannot add list slices; fix by converting slice to list
D. No error; code runs correctly
Solution
Step 1: Identify the error cause
Loop runs till len(data), but indexing data[i+2] exceeds list length at end.
Step 2: Fix the loop range
Change loop to range(len(data)-window+1) to avoid out-of-range indexing.
Final Answer:
IndexError because indexing goes beyond list end; fix by using range(len(data)-window+1) -> Option A
Quick Check:
Loop range must prevent out-of-bound indexing [OK]
Hint: Loop till len(data)-window+1 for safe indexing [OK]
Common Mistakes:
Ignoring index bounds causing IndexError
Changing window size incorrectly
Assuming no error occurs
5. You want to build a real-time DSP pipeline that filters noise from a sensor signal using a moving average filter of window size 4, but the sensor sometimes sends fewer than 4 samples at once. How should you adapt your pipeline to handle this situation correctly?
hard
A. Use a fixed window size of 1 to avoid buffering
B. Apply the filter on whatever samples arrive, even if fewer than 4, without buffering
C. Discard any samples fewer than 4 and wait for a full batch
D. Process only when at least 4 samples are available; buffer incoming data until then
Solution
Step 1: Understand window size requirement
Moving average with window 4 needs 4 samples to compute an average.
Step 2: Handle fewer samples in real-time
Buffer incoming samples until at least 4 are collected, then apply filter.