📖 Scenario: You are working on a simple digital communication system. You want to understand how different digital modulation techniques work by generating their signals from a binary data sequence.These modulation types are Amplitude Shift Keying (ASK), Frequency Shift Keying (FSK), and Phase Shift Keying (PSK).
🎯 Goal: Build a Python program that creates a binary data sequence, sets modulation parameters, generates ASK, FSK, and PSK signals from the data, and finally plots these signals to visualize how the modulation changes the carrier wave.
📋 What You'll Learn
Create a binary data sequence as a list
Define modulation parameters like carrier frequency and sampling rate
Generate ASK, FSK, and PSK signals using the data and parameters
Plot the generated signals using matplotlib
💡 Why This Matters
🌍 Real World
Digital modulation is used in wireless communication systems like Wi-Fi, Bluetooth, and cellular networks to transmit data efficiently over radio waves.
💼 Career
Understanding digital modulation is essential for roles in telecommunications, signal processing, and embedded systems engineering.
Progress0 / 4 steps
1
Create the binary data sequence
Create a list called data with the exact binary values: [1, 0, 1, 1, 0, 0, 1].
Signal Processing
Hint
Use square brackets to create a list and separate values with commas.
2
Set modulation parameters
Define three variables: fc for carrier frequency set to 5, fs for sampling frequency set to 50, and Tb for bit duration set to 1.
Signal Processing
Hint
Assign the exact numbers to the variables using the equals sign.
3
Generate ASK, FSK, and PSK signals
Import numpy as np. Create a time vector t using np.linspace from 0 to Tb with fs points. Then generate three lists: ask_signal, fsk_signal, and psk_signal by looping over each bit in data and appending the corresponding modulated signal segment. Use carrier frequency fc, bit duration Tb, and sampling frequency fs. For ASK, amplitude is 1 for bit 1 and 0 for bit 0. For FSK, use frequency fc for bit 1 and fc/2 for bit 0. For PSK, phase is 0 for bit 1 and pi for bit 0.
Signal Processing
Hint
Use np.sin for sine waves and extend to add segments to the signal lists.
4
Plot the ASK, FSK, and PSK signals
Import matplotlib.pyplot as plt. Create a time axis time_axis that covers the entire signal length. Plot ask_signal, fsk_signal, and psk_signal on three separate subplots with titles 'ASK Signal', 'FSK Signal', and 'PSK Signal'. Label the x-axis as 'Time (s)' and y-axis as 'Amplitude'. Use plt.tight_layout() and plt.show() to display the plots.
Signal Processing
Hint
Use plt.subplot to create multiple plots and plt.plot to draw the signals.
Practice
(1/5)
1. Which digital modulation technique changes the amplitude of the carrier wave to represent data bits?
easy
A. Phase Shift Keying (PSK)
B. Amplitude Shift Keying (ASK)
C. Frequency Shift Keying (FSK)
D. Pulse Code Modulation (PCM)
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.
2. Which of the following is the correct Python syntax to generate a Frequency Shift Keying (FSK) signal using numpy arrays for two frequencies f1 and f2?
easy
A. signal = np.sin(2 * np.pi * f1 * t) + np.sin(2 * np.pi * f2 * t)
B. signal = np.cos(2 * np.pi * f1 * t) + np.cos(2 * np.pi * f2 * t)
C. signal = np.sin(2 * np.pi * f1 * t) * np.sin(2 * np.pi * f2 * t)
D. signal = np.sin(2 * np.pi * (f1 if bit == 0 else f2) * t)
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 D
Quick Check:
Conditional frequency selection = signal = np.sin(2 * np.pi * (f1 if bit == 0 else f2) * t) [OK]
Hint: FSK switches frequency based on bit using conditional [OK]
Common Mistakes:
Adding two sine waves instead of switching frequency
Multiplying sine waves which is incorrect
Using cosine instead of sine without reason
3. Given the following Python code snippet for Phase Shift Keying (PSK), what will be the output signal array for bits = [0, 1] and phase0 = 0, phase1 = pi?
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)
medium
A. [[ 1. 0. -1. 0. 1.]
[-1. 0. 1. 0. -1.]]
B. [[ 0. 0. 0. 0. 0.]
[ 1. 1. 1. 1. 1.]]
C. [[ 1. 0. -1. 0. 1.]
[ 1. 0. -1. 0. 1.]]
D. [[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]]
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].
4. The following code attempts to generate an ASK signal but produces an error. What is the error and how to fix it?
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)
medium
A. Error: signal is assigned a scalar 0 instead of an array; fix by replacing 0 with np.zeros_like(t)
B. Error: np.sin requires integer input; fix by casting t to int
C. Error: Missing parentheses in np.sin; fix by adding parentheses
D. No error; code runs correctly
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 A
Quick 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]
Hint: Use np.zeros_like(t) for zero arrays, not scalar 0 [OK]
Common Mistakes:
Using scalar 0 causing type mismatch
Casting t to int which is unnecessary
Ignoring conditional expression structure
5. You want to design a digital communication system that must be robust to amplitude noise but can tolerate frequency variations. Which modulation technique should you choose and why?
hard
A. ASK, because it changes amplitude which is sensitive to noise
B. ASK, because it changes phase which is robust to amplitude noise
C. FSK, because it changes frequency which is less affected by amplitude noise
D. PSK, because it changes phase which is sensitive to frequency noise
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 C
Quick Check:
Amplitude noise robustness = FSK [OK]
Hint: Choose FSK to avoid amplitude noise sensitivity [OK]
Common Mistakes:
Choosing ASK despite amplitude noise sensitivity
Confusing phase noise sensitivity with frequency noise
Misunderstanding modulation noise robustness
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.