2ASK调制加解调

import numpy as np
from math import pi
import matplotlib.pyplot as plt
import matplotlib
import scipy.signal as signal
from scipy.fftpack import fft,ifft
import math
# 码元数
size = 10
sampling_t = 0.01
t = np.arange(0, size, sampling_t)
a = np.random.randint(0, 2, size)
m = np.zeros(len(t), dtype=np.float32)
for i in range(len(t)):
    m[i] = a[math.floor(t[i])]
fig = plt.figure(figsize=(12,4))
ax1 = fig.add_subplot(2, 1, 1)
plt.xticks(np.arange(0,11,1))
plt.yticks(range(0,2,1))
plt.axis([0, size+1, 0, 1.5])
xy=plt.gca()
xy.spines['top'].set_color('none')
xy.spines['right'].set_color('none')
xy.spines['left'].set_linewidth(2)
xy.spines['bottom'].set_linewidth(2)
plt.title("Baseband Signal")
plt.plot(t, m)

在这里插入图片描述

fc = 4000
fs = 20 * fc  # 采样频率
ts = np.arange(0, (100 * size) / fs, 1 / fs)
coherent_carrier = np.cos(2 * pi * fc*ts)#cos(8000*pi*t)
plt.figure(figsize=(12,6))
plt.subplot(3,1,1)
plt.xticks(np.arange(0,1000,100))
plt.title("Sine Wave Carray")
plt.axis([0,1000,-1.5,1.5])
plt.plot(coherent_carrier)
plt.tight_layout(4)

plt.subplot(3,1,2)
plt.title('Sine frequancy')

plt.plot(fft(coherent_carrier))

plt.subplot(3,1,3)
ook = m * np.cos(np.dot(2 * pi * fc, ts))
plt.title('Sine Wave Carray X Baseband Signal')
plt.xticks(np.arange(0,1000,100))
plt.axis([0,1000,-1.5,1.5])
plt.plot(ook)

在这里插入图片描述

plt.figure(figsize=(12,3))
plt.title('2ASK Signal')
plt.xlabel('time')
plt.ylabel('A')
plt.xticks(np.arange(0,10,1))
plt.axis([0, 10, -1.5, 1.5])
plt.plot(t,ook)

在这里插入图片描述

def awgn(y, snr):
    snr = 10 ** (snr / 10.0)
    xpower = np.sum(y ** 2) / len(y)
    npower = xpower / snr
    return np.random.randn(len(y)) * np.sqrt(npower) + y


# 加AWGN噪声
noise_ook = awgn(ook, 5)# 信噪比为5的高斯白噪音


plt.figure(figsize=(12,4))
plt.title('2ASK+Noise')
plt.axis([0,10, -2, 2])
plt.xticks(np.arange(0,11,1))
plt.plot(t, noise_ook)

在这里插入图片描述

# 带通巴斯沃特滤波器设计,通带为[2000,6000]
[b11, a11] = signal.butter(5,[2000 * 2 / 80000, 6000 * 2 / 80000], btype='bandpass', analog=False, output='ba')

# 低通滤波器设计,通带截止频率为2000Hz
[b12, a12] = signal.butter(5,(2000 * 2 / 80000), btype='lowpass', analog=False, output='ba')

# 通过带通滤波器滤除带外噪声
bandpass_out = signal.filtfilt(b11, a11, noise_ook)
fig3=plt.figure(figsize=(12,10))
bx1 = fig3.add_subplot(3, 1, 1)
bx1.set_title('Bandpass filter_out')
plt.axis([0, size, -1.5, 1.5])
plt.plot(t, bandpass_out)
# 相干解调,乘以同频同相的相干载波
coherent_demod = bandpass_out * (coherent_carrier * 2)

bx1 = fig3.add_subplot(3, 1, 2)
bx1.set_title('Coherent demodulation_out')
plt.axis([0, size, -1.5, 1.5])
plt.plot(t, coherent_demod)
# 通过低通滤波器
lowpass_out = signal.filtfilt(b12, a12, coherent_demod)

bx1 = fig3.add_subplot(3, 1, 3)
bx1.set_title('Lowpass filter_out')
plt.axis([0, size, -1.5, 1.5])
plt.plot(t, lowpass_out)

在这里插入图片描述

# 抽样判决
detection_bpsk = np.zeros(len(t), dtype=np.float32)
flag = np.zeros(size, dtype=np.float32)

for i in range(10):
    tempF = 0
    for j in range(100):
        tempF = tempF + lowpass_out[i * 100 + j]
    if tempF > 5:
        flag[i] = 1
    else:
        flag[i] = 0
for i in range(size):
    if flag[i] == 0:
        for j in range(100):
            detection_bpsk[i * 100 + j] = 0
    else:
        for j in range(100):
            detection_bpsk[i * 100 + j] = 1
plt.figure(figsize=(12,4))

plt.title('Simpling Judgment')
plt.axis([0, size, 0, 1.5])
plt.xticks(np.arange(0,11,1))
plt.yticks(np.arange(0,2,1))
plt.plot(t, detection_bpsk)
plt.show()

在这里插入图片描述

  • 1
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值