1. 程式人生 > 其它 >C#設計模式學習筆記:(12)代理模式

C#設計模式學習筆記:(12)代理模式

技術標籤:基於能量採集的認知無線電時間和功率分配

產生通道因子-h

訊號服從瑞利衰落,\LARGE h_{S,T}=\sqrt{\kappa }*\widehat{h}_{S,T}是從源節點到目的節點的通道因子,

其中,\large \widehat{h}_{S,T}~C_{N}(0,\sigma_{S,T}^{2})是瑞利衰減係數,服從復高斯分佈,\large \kappa =\frac{\lambda }{4\pi D_{S,T}}是路徑損失因子,\large D_{S,T}是源節點到接收端的距離,\large \lambda是訊號波長。

import numpy as np
import math
from numpy import mat
N= 1#目的節點個數
lam=0.1
def decay():
    #目的節點在rS-dor的圓環內隨機分佈
    r_outside=1.2

    S = np.random.random(N) * 2 * np.pi - np.pi
    r_inside=0#內部環

    x = np.cos(S)
    y = np.sin(S)

    for i in range(N):
        l = r_inside+r_outside*np.sqrt(np.random.random())
        x[i] = x[i] * l
        y[i] = y[i] * l

    dis =np.zeros((1,N))
    for j in range(N):
        dis[0,j]=np.sqrt((x[j])**2+(y[j])**2)

    for i in range(N):
        dis[0,i]=((lam/(4*math.pi)/dis[0,i]))
    return dis

if __name__ == '__main__':
    time=50000 #產生time條資料
    H=[]

    for i in range(time):
        r1=mat(np.random.normal(0,1,N))
        r2=1/pow(2,1/2)
        real = r1*r2
        h=[]

        i1=mat(np.random.normal(0,1,N))
        i2=1/pow(2,1/2)
        Imaginary=i2*i1

        R_deacy = decay()

        for j in range(0,N):
            c=complex(real[0,j],Imaginary[0,j])
            d=c*R_deacy [0,j]
            h.append((abs(d)))#準確的通道增益

        #print('一個通道',h)
        H.append(np.array(h))

    print('H',H[:10])