Digital modulation (ASK, FSK, PSK) in Signal Processing - Time & Space Complexity
We want to understand how the time needed to modulate signals grows as the input size increases.
How does the processing time change when we modulate more bits using ASK, FSK, or PSK?
Analyze the time complexity of the following code snippet.
for bit in input_bits:
if modulation_type == 'ASK':
modulated_signal.append(amplitude * bit)
elif modulation_type == 'FSK':
modulated_signal.append(frequency_shift(bit))
elif modulation_type == 'PSK':
modulated_signal.append(phase_shift(bit))
This code modulates each bit of input using one of three digital modulation methods.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Loop over each bit in the input array.
- How many times: Once for every bit in the input (n times).
Each bit requires one modulation operation, so the total work grows directly with the number of bits.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 modulation steps |
| 100 | 100 modulation steps |
| 1000 | 1000 modulation steps |
Pattern observation: Doubling the input doubles the work needed.
Time Complexity: O(n)
This means the time to modulate grows in a straight line with the number of bits.
[X] Wrong: "Modulating more bits takes the same time because each modulation is simple."
[OK] Correct: Even if each step is simple, doing it many times adds up, so total time grows with input size.
Understanding how processing time grows with input size helps you explain efficiency clearly and shows you can think about real system limits.
"What if we processed bits in parallel instead of one by one? How would the time complexity change?"
Practice
Solution
Step 1: Understand modulation types
ASK changes the amplitude of the carrier wave to represent data bits, while FSK changes frequency and PSK changes phase.Step 2: Match modulation to description
The question asks for the technique that changes amplitude, which is ASK.Final Answer:
Amplitude Shift Keying (ASK) -> Option BQuick Check:
Amplitude change = ASK [OK]
- Confusing ASK with FSK or PSK
- Choosing PCM which is not a modulation technique
- Mixing phase and amplitude changes
Solution
Step 1: Understand FSK signal generation
FSK uses one frequency for bit 0 and another for bit 1, so the signal switches frequency based on the bit.Step 2: Check syntax for conditional frequency
signal = np.sin(2 * np.pi * (f1 if bit == 0 else f2) * t) uses a conditional expression to select frequency based on bit, which is correct for FSK.Final Answer:
signal = np.sin(2 * np.pi * (f1 if bit == 0 else f2) * t) -> Option DQuick Check:
Conditional frequency selection = signal = np.sin(2 * np.pi * (f1 if bit == 0 else f2) * t) [OK]
- Adding two sine waves instead of switching frequency
- Multiplying sine waves which is incorrect
- Using cosine instead of sine without reason
import numpy as np t = np.linspace(0, 1, 5) bits = [0, 1] phase0 = 0 phase1 = np.pi signal = np.array([np.cos(2 * np.pi * 1 * t + (phase0 if bit == 0 else phase1)) for bit in bits]) print(signal)
Solution
Step 1: Calculate cosine values for bit 0
For bit 0, phase = 0, t = np.linspace(0,1,5) = [0, 0.25, 0.5, 0.75, 1], angles = 2πt = [0, π/2, π, 3π/2, 2π], cos = [1, 0, -1, 0, 1].Step 2: Calculate cosine values for bit 1
For bit 1, phase = π, angles = 2πt + π, cos(θ + π) = -cos(θ) = [-1, 0, 1, 0, -1].Final Answer:
[[ 1. 0. -1. 0. 1.] [-1. 0. 1. 0. -1.]] -> Option AQuick Check:
PSK phase shift: cos(θ + π) = -cos(θ) [OK]
- Confusing phase shift effect on cosine
- Misinterpreting array shape or values
- Ignoring phase addition in cosine
import numpy as np bit = 0 t = np.linspace(0, 1, 100) f = 5 signal = np.sin(2 * np.pi * f * t) if bit == 1 else 0 print(signal)
Solution
Step 1: Identify the error in conditional assignment
If bit == 1, signal is an array from np.sin, else signal is scalar 0, causing inconsistent types.Step 2: Fix by using array of zeros
Replace 0 with np.zeros_like(t) to keep signal as an array in both cases.Final Answer:
Error: signal is assigned a scalar 0 instead of an array; fix by replacing 0 with np.zeros_like(t) -> Option AQuick Check:
Consistent array types needed = Error: signal is assigned a scalar 0 instead of an array; fix by replacing 0 with np.zeros_like(t) [OK]
- Using scalar 0 causing type mismatch
- Casting t to int which is unnecessary
- Ignoring conditional expression structure
Solution
Step 1: Analyze noise tolerance requirements
The system must be robust to amplitude noise, so modulation should not rely on amplitude changes.Step 2: Match modulation to noise tolerance
FSK changes frequency, which is less affected by amplitude noise, making it suitable. ASK changes amplitude and is sensitive to amplitude noise. PSK changes phase and can be sensitive to frequency noise.Final Answer:
FSK, because it changes frequency which is less affected by amplitude noise -> Option CQuick Check:
Amplitude noise robustness = FSK [OK]
- Choosing ASK despite amplitude noise sensitivity
- Confusing phase noise sensitivity with frequency noise
- Misunderstanding modulation noise robustness
Ready to prove it?
Pass the test and this pattern moves unknown
