📖 Scenario: You are working with a simple signal processing task. You have a list of signal values and a list of noise values recorded from a sensor. You want to calculate the Signal-to-Noise Ratio (SNR) to understand how clear your signal is compared to the noise.
🎯 Goal: Build a program that calculates the Signal-to-Noise Ratio (SNR) by computing the average power of the signal and noise, then dividing the signal power by the noise power.
📋 What You'll Learn
Create two lists named signal and noise with exact values
Create a variable length to store the number of samples
Calculate the average power of the signal and noise using a for loop
Calculate the SNR as the ratio of signal power to noise power
Print the SNR value
💡 Why This Matters
🌍 Real World
Signal-to-Noise Ratio is used in audio processing, telecommunications, and sensor data analysis to measure how clear a signal is compared to background noise.
💼 Career
Understanding SNR is important for roles in data science, signal processing, and engineering where data quality and noise reduction are critical.
Progress0 / 4 steps
1
Create signal and noise data lists
Create a list called signal with values [10, 12, 11, 13, 12] and a list called noise with values [2, 3, 2, 4, 3].
Signal Processing
Hint
Use square brackets to create lists with the exact numbers given.
2
Create a variable for the number of samples
Create a variable called length and set it to the length of the signal list using the len() function.
Signal Processing
Hint
Use len(signal) to get the number of elements in the signal list.
3
Calculate average power of signal and noise
Create two variables signal_power and noise_power and set them to 0. Use a for loop with variable i from 0 to length - 1 to add the square of each signal[i] to signal_power and the square of each noise[i] to noise_power. Then divide both signal_power and noise_power by length to get the average power.
Signal Processing
Hint
Remember to square each value using ** 2 and divide sums by length after the loop.
4
Calculate and print the Signal-to-Noise Ratio (SNR)
Create a variable called snr and set it to the ratio of signal_power divided by noise_power. Then print the value of snr.
Signal Processing
Hint
Divide signal_power by noise_power and print the result.
Practice
(1/5)
1. What does Signal-to-Noise Ratio (SNR) measure in signal processing?
easy
A. The strength of the signal compared to the background noise
B. The total power of the noise only
C. The frequency of the signal
D. The duration of the signal
Solution
Step 1: Understand the definition of SNR
SNR is defined as the ratio of signal power to noise power, showing how strong the signal is compared to noise.
Step 2: Compare options with definition
Only The strength of the signal compared to the background noise correctly states that SNR measures signal strength relative to noise.
Final Answer:
The strength of the signal compared to the background noise -> Option A
Quick Check:
SNR = Signal strength / Noise strength [OK]
Hint: Remember: SNR compares signal power to noise power [OK]
Common Mistakes:
Confusing SNR with noise power alone
Thinking SNR measures frequency
Mixing up signal duration with SNR
2. Which of the following is the correct formula to calculate SNR in decibels (dB)?
easy
A. SNR(dB) = 10 * log10(signal power / noise power)
B. SNR(dB) = signal power / noise power
C. SNR(dB) = 20 * log10(signal power + noise power)
D. SNR(dB) = log10(signal power - noise power)
Solution
Step 1: Recall the SNR formula in decibels
SNR in dB is calculated as 10 times the base-10 logarithm of the ratio of signal power to noise power.
Step 2: Check each option against the formula
SNR(dB) = 10 * log10(signal power / noise power) matches the correct formula. Options A, B, and D are incorrect due to missing log, wrong multiplier, or incorrect operations.
Final Answer:
SNR(dB) = 10 * log10(signal power / noise power) -> Option A
Quick Check:
SNR(dB) = 10 * log10(Signal/Noise) [OK]
Hint: Use 10 * log10 for power ratios in dB [OK]
Common Mistakes:
Using 20 instead of 10 for power ratio
Forgetting the logarithm
Adding signal and noise instead of dividing
3. Given signal power = 50 and noise power = 2, what is the SNR in decibels (dB)? Use SNR(dB) = 10 * log10(signal power / noise power).
medium
A. 10 * log10(50 + 2) ≈ 17.16 dB
B. 10 * log10(50 / 2) ≈ 13.98 dB
C. 10 * log10(2 / 50) ≈ -13.98 dB
D. 10 * log10(50 - 2) ≈ 16.81 dB
Solution
Step 1: Calculate the ratio of signal power to noise power
B. Dividing noise power by signal power instead of the reverse
C. Using natural log instead of log base 10
D. Not importing the math module
Solution
Step 1: Check the logarithm function used
The code uses math.log(), which is natural logarithm (base e), but SNR in dB requires log base 10.
Step 2: Identify correct function for log base 10
Python's math module has math.log10() for base 10 logarithm, which should be used instead.
Final Answer:
Using natural log instead of log base 10 -> Option C
Quick Check:
Use math.log10() for dB calculations [OK]
Hint: Use math.log10() for dB, not math.log() [OK]
Common Mistakes:
Using math.log() instead of math.log10()
Swapping signal and noise in division
Confusing multiplication factor (10 vs 20)
5. You have a noisy signal with signal power 200 and noise power 50. You apply a filter that reduces noise power by half but also reduces signal power by 10%. What is the new SNR in dB? Use SNR(dB) = 10 * log10(signal power / noise power).
hard
A. 10 * log10(200 / 50) ≈ 6.02 dB
B. 10 * log10(200 / 25) ≈ 9.03 dB
C. 10 * log10(180 / 50) ≈ 5.56 dB
D. 10 * log10(180 / 25) ≈ 8.57 dB
Solution
Step 1: Calculate new signal and noise powers after filtering
Signal power reduced by 10%: 200 * 0.9 = 180 Noise power reduced by half: 50 / 2 = 25