📅  最后修改于: 2023-12-03 15:26:06.457000             🧑  作者: Mango
数字调制技术是指利用数字信号对模拟信号进行调制和解调的技术。数字信号在数字通信中占据了重要的地位,数字调制技术则成为数字通信中的重要技术之一。
数字调制技术按照调制和解调的方式不同可划分为以下几类:
数字调制技术被广泛应用于数字通信中,如数字电视、数字广播、数字移动通信、卫星通信等。其中,4G手机中采用的LTE(Long-Term Evolution)技术,通过QAM实现高速数据的传输。
使用Python实现数字调制十分便捷,下述代码实现了ASK和PSK的调制和解调:
import numpy as np
import matplotlib.pyplot as plt
# Amplitude-shift keying (ASK)
def ask_modulation(bitstream, fc, fs, A):
t = np.arange(0, len(bitstream)/fs, 1/fs)
car_wave = A * np.sin(2*np.pi*fc*t)
ask_wave = []
for bit in bitstream:
if bit=='0':
waveform = np.zeros(int(fs/(2*fc)))
else:
waveform = car_wave[:int(fs/(2*fc))]
ask_wave.extend(waveform)
return np.array(ask_wave)
def ask_demodulation(ask_wave, fc, fs, A):
t = np.arange(0, len(ask_wave)/fs, 1/fs)
car_wave = A * np.sin(2*np.pi*fc*t)
demodulate_signal = []
for i in range(0, len(ask_wave), int(fs/fc)):
demodulate_signal.append(np.sum(ask_wave[i:i+int(fs/fc)])/(fs/fc))
bits = []
for signal in demodulate_signal:
if signal>np.mean(car_wave):
bits.append('1')
else:
bits.append('0')
return ''.join(bits)
# Phase-shift keying (PSK)
def psk_modulation(bitstream, fc, fs, A):
t = np.arange(0, len(bitstream)/fs, 1/fs)
car_wave = A * np.sin(2*np.pi*fc*t)
psk_wave = []
for i in range(0, len(bitstream), 2):
if bitstream[i:i+2]=='00':
waveform = A * np.sin(2*np.pi*fc*t[i:i+int(fs/fc)])
elif bitstream[i:i+2]=='01':
waveform = A * np.sin(2*np.pi*fc*t[i:i+int(fs/fc)] + np.pi/2)
elif bitstream[i:i+2]=='10':
waveform = A * np.sin(2*np.pi*fc*t[i:i+int(fs/fc)] + np.pi)
elif bitstream[i:i+2]=='11':
waveform = A * np.sin(2*np.pi*fc*t[i:i+int(fs/fc)] + np.pi*3/2)
psk_wave.extend(waveform)
return np.array(psk_wave)
def psk_demodulation(psk_wave, fc, fs, A):
t = np.arange(0, len(psk_wave)/fs, 1/fs)
car_wave = A * np.sin(2*np.pi*fc*t)
demodulate_signal = []
for i in range(0, len(psk_wave), int(fs/fc)):
demodulate_signal.append(np.sum(psk_wave[i:i+int(fs/fc)])/(fs/fc))
bits = []
for signal in demodulate_signal:
delta_signal = signal-car_wave[0]
if delta_signal>0:
bits.append('00')
elif delta_signal<-A*np.cos(np.pi/4):
bits.append('10')
elif delta_signal<-A*np.sin(np.pi/4):
bits.append('11')
else:
bits.append('01')
return ''.join(bits)
# Generate binary stream
bitstream = '111010100001101101'
# Set parameters
fc = 10
fs = 50*fc
A = 1
# Modulate the binary stream using ASK and PSK
ask_wave = ask_modulation(bitstream, fc, fs, A)
psk_wave = psk_modulation(bitstream, fc, fs, A)
# Demodulate the modulated signals
demodulate_ask = ask_demodulation(ask_wave, fc, fs, A)
demodulate_psk = psk_demodulation(psk_wave, fc, fs, A)
# Plot the signals
fig, axs = plt.subplots(3)
fig.suptitle('Digital Modulation')
axs[0].plot(ask_wave)
axs[0].set_title('ASK')
axs[1].plot(psk_wave)
axs[1].set_title('PSK')
axs[2].plot(ask_wave-psk_wave)
axs[2].set_title('Comparison')
plt.show()
# Print the binary stream before and after demodulation
print('Binary stream before demodulation:', bitstream)
print('Binary stream after ASK demodulation:', demodulate_ask)
print('Binary stream after PSK demodulation:', demodulate_psk)
数字调制技术在数字通信中起到至关重要的作用,能够使数据的传输更加高效和可靠。Python作为一种强大的编程语言,能够轻松地实现数字调制和解调的过程,方便工程师进行测试和验证。