Python实现rician莱斯衰落和rician莱斯信道
Python 实现 信道
2023-09-14 09:13:11 时间
基本概念
(1)莱斯分布
在概率论中,Rice分布或Rician分布(或更不常见的是Ricean分布)是圆对称双变量正态随机变量的大小(可能具有非零均值(非中心))的概率分布。它以斯蒂芬·赖斯(Stephen O. Rice)的名字命名。
(2)莱斯信道
Rician (rice)衰落信道一般有两种实现方式
- 第一种:将高斯白噪声通过线性时变滤波器获得,滤波器的传递函数由Droppler功率谱密度函数S(f)的平方根
- 第二种:通过利用不同相位、幅度和频率的余弦波叠加来实现。以下代码就是该方法实现
参考资料 - Rician fading
- Rice衰落信道的仿真-百度文库
Example
2.1 Rician衰落类
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 4 18:55:46 2020
@author: Jonathan Browning
"""
import numpy as np
from scipy.stats import gaussian_kde as kdf
from scipy import special as sp
class Rice:
# numSamples = 2*(10**6) # the number of samples used in the simulation
# numSamples = 64 #表示要产生的随机数的长度
r = np.linspace(0, 6, 6000) # theoretical envelope PDF x axes
theta = np.linspace(-np.pi, np.pi, 6000) # theoretical phase PDF x axes
def __init__(self, K, r_hat_2, phi,numSamples):
# # user input checks and assigns value
self.K = self.input_Check(K, "K", 0, 50)
self.r_hat_2 = self.input_Check(r_hat_2, "\hat{r}^2", 0.5, 2.5)
self.phi = self.input_Check(phi, "\phi", -np.pi, np.pi)
self.numSamples = numSamples
# user input checks and assigns value
# simulating and theri densities
self.multipathFading = self.complex_Multipath_Fading()
self.xdataEnv, self.ydataEnv = self.envelope_Density()
self.xdataPh, self.ydataPh = self.phase_Density()
# theoretical PDFs calculated
self.envelopeProbability = self.envelope_PDF()
self.phaseProbability = self.phase_PDF()
# 输入格式检查
def input_Check(self, data, inputName, lower, upper):
# input_Check checks the user inputs
# has a value been entered
if data == "":
raise ValueError(" ".join((inputName, "must have a numeric value")))
# incase of an non-numeric input
try:
data = float(data)
except:
raise ValueError(" ".join((inputName, "must have a numeric value")))
# data must be within the range
if data < lower or data > upper:
raise ValueError(" ".join((inputName, f"must be in the range [{lower:.2f}, {upper:.2f}]")))
return data
def calculate_Means(self):
# calculate_means calculates the means of the complex Gaussians representing the
# in-phase and quadrature components
p = np.sqrt(self.K * self.r_hat_2 / (1+self.K)) * np.cos(self.phi)
q = np.sqrt(self.K * self.r_hat_2 / (1+self.K)) * np.sin(self.phi)
return p, q
def scattered_Component(self):
# scattered_Component calculates the power of the scattered signal component
sigma = np.sqrt(self.r_hat_2 / ( 2 * (1+self.K) ) )
return sigma
def generate_Gaussians(self, mean, sigma):
# generate_Gaussians generates the Gaussian random variables
gaussians = np.random.default_rng().normal(mean, sigma, self.numSamples)
return gaussians
def complex_Multipath_Fading(self):
# complex_Multipath_Fading generates the complex fading random variables
p, q = self.calculate_Means()
sigma = self.scattered_Component()
multipathFading = self.generate_Gaussians(p, sigma) + (1j*self.generate_Gaussians(q, sigma))
return multipathFading
def envelope_PDF(self):
# envelope_PDF calculates the theoretical envelope PDF
PDF = 2 * (1+self.K) * self.r / self.r_hat_2 \
* np.exp(- self.K - ((1+self.K)*self.r**2)/self.r_hat_2) \
* np.i0(2 * self.r * np.sqrt(self.K*(1+self.K)/self.r_hat_2))
return PDF
def phase_PDF(self):
# phase_PDF calculates the theoretical phase PDF
def q_func(x):
# Q-function
return 0.5-0.5*sp.erf(x/np.sqrt(2))
PDF = (1/(2*np.pi))* np.exp(- self.K) * (1 + (np.sqrt(4*np.pi*self.K) \
* np.exp(self.K * (np.cos(self.theta-self.phi))**2) *np.cos(self.theta-self.phi)) \
* (1 - q_func(np.sqrt(2*self.K) * np.cos(self.theta-self.phi))))
return PDF
def envelope_Density(self):
# envelope_Density finds the envelope PDF of the simulated random variables
R = np.sqrt((np.real(self.multipathFading))**2 + (np.imag(self.multipathFading))**2)
kde = kdf(R)
x = np.linspace(R.min(), R.max(), 100)
p = kde(x)
return x, p
def phase_Density(self):
# phase_Density finds the phase PDF of the simulated random variables
R = np.angle(self.multipathFading)
kde = kdf(R)
x = np.linspace(R.min(), R.max(), 100)
p = kde(x)
return x, p
写一个Demo测试程序
from rice import *
K =1 # K因子
hat = 1 # 振幅
phi = 1 # 相位
numSamples = 16 # 随机样本的长度
s = Rice(1,1,1,16)
# rician衰落随机数
print(s.multipathFading)
2.2 Ricican信道
# signal输入的信号
# channelResponse rician衰落随机数,就是以上代码求的s.multipathFading
# SNRdb,信噪比
def rician_channel(signal, channelResponse, SNRdb):
# 卷积
convolved = np.convolve(signal, channelResponse)
signal_power = np.mean(abs(convolved**2))
sigma2 = signal_power * 10**(-SNRdb / 10)
# 噪声
noise = np.sqrt(sigma2 / 2) * (np.random.randn(*convolved.shape) + 1j * np.random.randn(*convolved.shape))
return convolved + noise
相关文章
- 【Python】python 多线程两种实现方式
- python部署在后台执行
- python禁止函数修改列表的实现方法
- Atitit web httphandler的实现 java python node.js c# net php 目录 1.1. Java 过滤器 servelet1 1.2. Python的
- Python的IDE:基于Eclipse/MyEclipse软件的PyDev插件配置python的开发环境(不同python项目加载不同版本的python)—从而实现Python编程图文教程之详细攻略
- Python:利用python代码编程实现将视频的avi格式转换为MP4格式
- Python语言学习:利用python语言实现调用内部命令(python调用Shell脚本)—命令提示符cmd的几种方法
- Python:利用python编程实现三维图像绘制展示(六面体旋转、三维球柱状体、下雪场景等)
- Python的IDE:基于Eclipse/MyEclipse软件的PyDev插件配置python的开发环境(不同python项目加载不同版本的python)—从而实现Python编程图文教程之详细攻略
- Python语言学习:利用python语言实现调用内部命令(python调用Shell脚本)—命令提示符cmd的几种方法
- 〖Python WEB 自动化测试实战篇⑨〗- 实战 - selenium 实现浏览器标签页的切换
- 〖Python接口自动化测试实战篇⑧〗- 小案例 - 使用python实现接口请求 [查询天行数据]
- 基于蒙特卡洛法的规模化电动汽车充电负荷预测(Python&Matlab实现)
- Python实现GWO智能灰狼优化算法优化Catboost回归模型(CatBoostRegressor算法)项目实战
- Python实现随机分布式延迟PSO优化算法(RODDPSO)优化支持向量机回归模型(SVR算法)项目实战
- 【LeetCode Python实现】355. 设计推特(中等)
- 从0到1实现python基于RPC协议的接口自动化测试
- python基础===一行 Python 代码实现并行(转)
- 数据分析----IQR(Interquartile Range)四分位距的理解与应用及Python实现
- 【Python】Python 仿真OFDM发射机、信道和接收机-实现多种调制方式
- 〖Python自动化办公篇⑲〗 - python实现邮件自动化 - 邮件发送
- 〖Python自动化办公篇⑳〗 - python实现邮件自动化 - 发送html邮件和带附件的邮件