瑞利衰落信道仿真(Python)

本文介绍了在无线通信中如何使用对数正常阴影衰落和瑞利衰落模型来模拟多径效应下的信号衰减。通过定义距离依赖的路径损耗函数,结合随机生成的距离值和对数正态分布的阴影衰落,以及复高斯分布的瑞利衰落系数,生成了信道衰落系数数组。
摘要由CSDN通过智能技术生成

2024年4月24日16:46:31更新:
(这个比较正确)
在这里插入图片描述
重点是这个对数阴影衰落

    import numpy as np

    # Define distance-dependent path-loss function
    def path_loss(d):
        return 128.1 + 37.6 * np.log10(d)

    # Set the number of channels
    num_channels = 10

    # Simulate distances (assuming random distances for this example)
    distances = np.random.rand(num_channels) * 10  # Distances in kilometers

    # Calculate path loss for each channel
    path_loss_dB = path_loss(distances)

    # Apply log-normal shadowing (10 dB standard deviation)
    shadowing = np.random.normal(scale=10, size=num_channels)

    # Convert path loss from dB to linear scale
    path_loss_linear = np.power(10, -path_loss_dB / 10)

    # Generate Rayleigh fading coefficients (complex numbers)
    fading = np.random.rayleigh(size=num_channels) * np.exp(2j * np.pi * np.random.rand(num_channels))

    # Combine path loss, shadowing, and fading  log(10^(-shadowing/10)=e^(-shadowing / 10) 正好就是对数正态分布
    channel_coefficients = fading * np.sqrt(path_loss_linear) * np.exp(-shadowing / 10)

    # Print the channel coefficients
    print(channel_coefficients)

ChatGPT答案:

import numpy as np

def generate_rayleigh_channel(num_samples):
    # 生成实部和虚部,均为高斯分布 N(0, 1/2)
    real_part = np.random.normal(0, np.sqrt(0.5), num_samples)
    imag_part = np.random.normal(0, np.sqrt(0.5), num_samples)

    # 合成复数形式的瑞利衰落系数
    h = real_part + 1j * imag_part
    return h

# 生成样本数量
num_samples = 1000

# 生成瑞利信道系数
h = generate_rayleigh_channel(num_samples)

# 打印前10个系数
print("First 10 Rayleigh channel coefficients:", h[:10])

瑞利衰落信道模型通常用于描述多径效应下的信号衰落,其中衰落系数 ( h ) 是复数,并且其幅度服从瑞利分布,相位服从均匀分布。在复高斯分布 C N ( 0 , 1 ) \mathcal{CN}(0,1) CN(0,1)的情况下,实际上是指 ( h ) 的实部和虚部分别独立地服从高斯分布 ( \mathcal{N}(0,1/2) ),因为复高斯分布的功率归一化到1。

下面是一个生成瑞利信道衰落系数 ( h ) 的 Python 代码示例,其中 ( h ) 的实部和虚部均服从标准高斯分布(均值为0,方差为1):

def generate_rayleigh_channels(num_channels):   
# 生成实部和虚部   
	real_parts = np.random.normal(0, 1/np.sqrt(2), num_channels)   
	imag_parts = np.random.normal(0, 1/np.sqrt(2), num_channels)   
	# 合成复数衰落系数数组   
	h = real_parts + 1j * imag_parts   
	return h 
# 生成多个瑞利信道衰落系数
num_channels = 10
h_array = generate_rayleigh_channels(num_channels)
print("Generated Rayleigh channel fading coefficients:", h_array)

注意,由于我们希望 ( h ) 的功率归一化为1,即 ( ∣ h ∣ 2 |h|^2 h2 ) 的期望值为1,因此我们使用标准差为 ( 1 / 2 1/\sqrt{2} 1/2 ) 的高斯分布来生成实部和虚部。这是因为复数 ( h ) 的功率是实部和虚部平方和的一半,即 ( ∣ h ∣ 2 = ( r e a l _ p a r t 2 + i m a g _ p a r t 2 ) / 2 |h|^2 = (real\_part^2 + imag\_part^2)/2 h2=(real_part2+imag_part2)/2 ),所以需要将方差设置为 ( 1/2 ),而标准差为 ( 1 / 2 1/\sqrt{2} 1/2 )。

  • 8
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值