Channel noise and SNR in Signal Processing - Time & Space Complexity
We want to understand how the time to calculate signal quality changes as the signal length grows.
How does the work needed to measure noise and signal-to-noise ratio grow with input size?
Analyze the time complexity of the following code snippet.
# Calculate noise and SNR for a signal
noise = signal - clean_signal
noise_power = sum(noise ** 2)
signal_power = sum(clean_signal ** 2)
snr = 10 * np.log10(signal_power / noise_power)
This code finds the noise by subtracting the clean signal from the received signal, then calculates power values and finally the signal-to-noise ratio.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Summing the squares of noise and clean signal arrays.
- How many times: Once for each element in the signal arrays (length n).
As the signal length grows, the number of calculations grows proportionally.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 20 sums (10 for noise, 10 for signal) |
| 100 | About 200 sums |
| 1000 | About 2000 sums |
Pattern observation: Doubling the signal length roughly doubles the work needed.
Time Complexity: O(n)
This means the time to compute noise and SNR grows linearly with the signal length.
[X] Wrong: "Calculating noise and SNR takes the same time no matter how long the signal is."
[OK] Correct: Because each element in the signal must be processed, longer signals need more work.
Understanding how signal processing steps scale helps you explain efficiency clearly and shows you can think about real data sizes.
"What if we used a sliding window to calculate SNR repeatedly over parts of the signal? How would the time complexity change?"
Practice
Solution
Step 1: Understand the meaning of SNR
SNR measures how strong the useful signal is compared to the noise interfering with it.Step 2: Compare options with definition
Only The strength of the signal compared to the background noise correctly describes SNR as the ratio of signal strength to noise level.Final Answer:
The strength of the signal compared to the background noise -> Option AQuick Check:
SNR = Signal strength / Noise level [OK]
- Confusing SNR with noise level alone
- Thinking SNR measures speed or frequency
- Mixing signal strength with noise amount
Solution
Step 1: Recall the SNR dB formula
SNR in decibels is calculated as 10 times the base-10 logarithm of the ratio of signal power to noise power.Step 2: Match formula with options
SNR(dB) = 10 * log10(signal power / noise power) matches the correct formula exactly; others are incorrect or mathematically invalid.Final Answer:
SNR(dB) = 10 * log10(signal power / noise power) -> Option AQuick Check:
SNR(dB) = 10 * log10(Signal/Noise) [OK]
- Using 20 instead of 10 for power ratio
- Multiplying signal and noise instead of dividing
- Subtracting powers inside log instead of dividing
SNR(dB) = 10 * log10(signal power / noise power).Solution
Step 1: Calculate the ratio signal power / noise power
Ratio = 50 mW / 5 mW = 10Step 2: Calculate SNR in dB using formula
SNR(dB) = 10 * log10(10) = 10 * 1 = 10 dBStep 3: Re-check calculation
Log base 10 of 10 is 1, so SNR = 10 dBFinal Answer:
10 dB -> Option BQuick Check:
10 * log10(10) = 10 dB [OK]
- Using natural log instead of log base 10
- Dividing noise by signal instead of signal by noise
- Forgetting to multiply by 10
import math signal_power = 100 noise_power = 20 snr_db = 10 * math.log(signal_power / noise_power) print(snr_db)
Solution
Step 1: Identify the logarithm function used
The code uses math.log which is natural log (base e), but SNR in dB requires log base 10.Step 2: Correct the log function
Replace math.log with math.log10 to get correct SNR in decibels.Final Answer:
Using math.log instead of math.log10 -> Option DQuick Check:
Use math.log10 for dB calculations [OK]
- Using natural log instead of log10
- Swapping signal and noise in division
- Forgetting to import math module
SNR(dB) = 10 * log10(signal power / noise power).Solution
Step 1: Calculate initial SNR
Initial SNR = 10 * log10(200 / 50) = 10 * log10(4) ≈ 10 * 0.602 = 6.02 dBStep 2: Calculate new SNR after noise doubles
New noise power = 50 * 2 = 100 mW
New SNR = 10 * log10(200 / 100) = 10 * log10(2) ≈ 10 * 0.301 = 3.01 dBStep 3: Find change in SNR
Change = 6.02 - 3.01 = 3.01 dB decreaseFinal Answer:
SNR decreases by about 3 dB -> Option CQuick Check:
Doubling noise halves ratio, drops SNR by ~3 dB [OK]
- Thinking SNR increases when noise increases
- Calculating log base e instead of base 10
- Forgetting to multiply log by 10
Ready to prove it?
Pass the test and this pattern moves unknown
