Python实现rician莱斯衰落和rician莱斯信道

简介: 本文提供了一个Python类实现莱斯(Rician)衰落信道的模拟,包括理论概率密度函数的计算和实际随机变量的生成。

基本概念

(1)莱斯分布
在概率论中,Rice分布或Rician分布(或更不常见的是Ricean分布)是圆对称双变量正态随机变量的大小(可能具有非零均值(非中心))的概率分布。它以斯蒂芬·赖斯(Stephen O. Rice)的名字命名。

(2)莱斯信道
Rician (rice)衰落信道一般有两种实现方式

  • 第一种:将高斯白噪声通过线性时变滤波器获得,滤波器的传递函数由Droppler功率谱密度函数S(f)的平方根
  • 第二种:通过利用不同相位、幅度和频率的余弦波叠加来实现。以下代码就是该方法实现

    1.png


    参考资料
  • Rician fading
  • Rice衰落信道的仿真-百度文库

Example

来自Github-Rician-Fading-Python

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
目录
相关文章
|
机器学习/深度学习 移动开发 JavaScript
ZC序列理论学习及仿真(一)
ZC序列理论学习及仿真
4294 0
|
语音技术 Python
在语音信号处理中,预加重
在语音信号处理中,预加重
1144 2
|
安全 应用服务中间件 Linux
Linux上面配置Apache2支持Https(ssl)具体方案实现
虽然Nginx比较流行,但是由于一些老项目用到了Apache2来支持Web服务,最近想给服务上一个Https支持,虽然看似教程简单,但是也遇到一些特殊情况,经历了一番折腾也算是解决了所有问题,将过程记录如下。演示是基于Ubantu系统。
1502 0
|
边缘计算 人工智能 5G
5G引领家庭网络升级:速度、稳定性与智能化的新时代
5G引领家庭网络升级:速度、稳定性与智能化的新时代
822 69
|
数据可视化 Python
【Python】Python 仿真OFDM发射机、信道和接收机-实现多种调制方式
文章介绍了如何使用Python和Commpy工具包实现OFDM通信系统的仿真,包括发射机、信道和接收机的过程,并支持BPSK、QPSK、8PSK、16QAM、64QAM等多种调制方式,同时展示了导频插入、信道冲击响应、星座映射的可视化,并计算了系统的误比特率。
1048 0
|
并行计算 监控 Linux
《CST Studio Suite 2024 GPU加速计算指南》
《GPU Computing Guide》是Dassault Systèmes发布的CST Studio Suite 2024的GPU计算指南,涵盖了硬件支持、操作系统支持、许可证、启用方法、NVIDIA和AMD GPU的详细信息及使用指南和故障排除等内容。硬件支持包括NVIDIA和AMD的多种GPU型号,操作系统支持多种版本,许可证通过加速令牌或SimUnit令牌授权。启用方法包括交互式模拟和批处理模式。使用指南和故障排除部分提供了详细的配置和问题解决方法。
2201 9
舵机和电机
【11月更文挑战第12天】
510 3
|
算法 5G 调度
5G中的空分复用(SDMA):实现更高效的无线资源利用
5G中的空分复用(SDMA):实现更高效的无线资源利用
1077 1
|
算法 Python
群智能算法:灰狼优化算法(GWO)的详细解读
在优化问题中,寻找最优解是核心目标。灰狼优化算法(GWO)受到自然界灰狼狩猎行为和社会等级结构的启发,通过模拟Alpha(头狼)、Beta(助手狼)、Delta(支配狼)和Omega(普通狼)的角色,高效搜索最优解。本文详细解析GWO的原理与步骤,并提供Python代码实现,帮助读者理解并应用这一算法。
|
Python
【信号处理】Python实现BPSK、QPSK、8PSK、8QAM、16QAM、64QAM的调制和解调
使用Commpy开源包在Python中实现BPSK、QPSK、8PSK、8QAM、16QAM、64QAM等调制和解调方法的具体代码示例,但不包括8QAM的Commpy实现,以及一个完整的编码和解码示例。
1408 0

热门文章

最新文章