Think about which property of the carrier wave changes in ASK.
ASK changes the amplitude of the carrier signal to encode digital bits, while frequency and phase remain unchanged.
import numpy as np bit_seq = [0, 1] fs = 1000 # sampling frequency bit_duration = 0.01 # seconds f0 = 100 # frequency for bit 0 f1 = 200 # frequency for bit 1 signal = np.array([]) for bit in bit_seq: t = np.linspace(0, bit_duration, int(fs * bit_duration), endpoint=False) freq = f0 if bit == 0 else f1 wave = np.sin(2 * np.pi * freq * t) signal = np.concatenate((signal, wave)) output_shape = signal.shape
Calculate samples per bit: sampling frequency times bit duration.
Each bit lasts 0.01 seconds with 1000 samples per second, so each bit has 10 samples. Two bits produce 20 samples total. But code uses int(fs * bit_duration) = 10 samples per bit, concatenated twice, total 20 samples. The shape is (20,).
import numpy as np bits = np.array([0, 1, 0, 1]) constellation = np.where(bits == 0, 1+0j, -1+0j)
Recall BPSK maps bits to points on the real axis.
BPSK maps bit 0 to +1 and bit 1 to -1 on the real axis, so the constellation array matches the bit sequence accordingly.
import numpy as np import matplotlib.pyplot as plt bit_seq = [1, 0, 1] fs = 1000 bit_duration = 0.02 f1 = 150 f0 = 75 signal = np.array([]) time = np.array([]) for i, bit in enumerate(bit_seq): t = np.linspace(i*bit_duration, (i+1)*bit_duration, int(fs*bit_duration), endpoint=False) freq = f1 if bit == 1 else f0 wave = np.sin(2 * np.pi * freq * (t - i*bit_duration)) signal = np.concatenate((signal, wave)) time = np.concatenate((time, t)) plt.plot(time, signal) plt.xlabel('Time (s)') plt.ylabel('Amplitude') plt.title('FSK Signal') plt.grid(True) plt.show()
FSK changes frequency based on bit value.
The signal switches frequency according to bits: 1 maps to 150 Hz (high freq), 0 maps to 75 Hz (low freq), so the plot shows high-low-high frequency segments.
import numpy as np bits = [0, 1] fs = 1000 bit_duration = 0.01 phases = {0: 0, 1: np.pi} signal = np.array([]) for bit in bits: t = np.linspace(0, bit_duration, int(fs * bit_duration)) wave = np.cos(2 * np.pi * 100 * t + phases[bit]) signal = np.concatenate((signal, wave))
Check how numpy.concatenate expects its arguments.
numpy.concatenate expects a single sequence (like a list or tuple) of arrays as its first argument, but the code passes two separate arguments, causing a TypeError.
