Giter Site home page Giter Site logo

shaojiawei07 / rayleigh_diversity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eldrtimo/rayleigh_diversity

0.0 1.0 0.0 1.08 MB

Simulate BER for BPSK under K-path Rayleigh fading with differet diversity combining techniques

Jupyter Notebook 97.78% Python 2.22%

rayleigh_diversity's Introduction

%run -i ./python/bpsk_rayleigh_3path.py

BER Simulation for BPSK for 3-Path Rayleigh Fading under Section, Equal Gain, and Max Ratio Combining Methods

N       = 2**20                 # Number of symbols
K       = 3                     # Number of diversity branches
Ga_l    = np.logspace(0,2,16)   # Simulation SNR values
Ga_l_dB = 10*np.log10(Ga_l)
FIGNAME = "diversity_combining_methods.png"
Pe_MAX  = 10**(-3)              # Maximum BER to estimate Minimum SNR

fig, axs = plt.subplots()
axs.set_title(r"Simulated BER of BPSK under Rayligh fading and diversity order $K = {}$".format(K))
axs.set_xlabel(r"Signal-to-noise ratio $\Gamma$ (dB)")
axs.set_ylabel(r"Simulated bit error rate $P_b$")
axs.set_yscale("log")

# Annotate maximum Pe line
axs.axhline(Pe_MAX,color = "black",linestyle="-",
            linewidth=1,label="$P_e = 10^{{{:.0f}}}$".format(np.log10(Pe_MAX)))


for combiner_ix, combiner in enumerate(COMBINERS):
    # Compute BER rates
    Pe_l = BPSKRayleighDiversityBER(N,K,Ga_l,combiner)

    # Interpolation
    Pe_est = interp1d(Ga_l[l_interp],Pe_l[l_interp],
                      fill_value="extrapolate")
    

    # Estimate and annotate minimum SNR
    l_interp = (Pe_l > 0)
    if np.any(Pe_l < Pe_MAX):
        # Points to interpolate
        x = np.log10(Pe_l[l_interp])
        y = Ga_l_dB[l_interp]
        
        # Linear interpolator
        f = interp1d(x,y,fill_value="interpolate",kind="linear")
        
        # Interpolated estimate of minimum SNR
        Ga_min_est_dB = f(np.log10(Pe_MAX))
        axs.axvline(Ga_min_est_dB,color="black",linestyle="--",linewidth=1)
        annotation = r"{} $\gamma_\min \approx {:.1f}$ dB".format(
            combiner,Ga_min_est_dB)
        xy = (Ga_min_est_dB,Pe_MAX)
        xytext = (Ga_min_est_dB,Pe_MAX*10**(0.15 + .33*combiner_ix))
        axs.annotate(annotation,xy,xytext)


    # Plot BER curve
    l_plot = (Pe_l > 0)
    ber_curve = axs.plot(Ga_l_dB[l_plot],Pe_l[l_plot],"o-",label=combiner)


    # Estimate diversity order via linear regression
    l_regression = (Pe_l > 0) & (Ga_l_dB > 5)
    x = Ga_l_dB[l_regression]
    y = np.log10(Pe_l[l_regression])
    A = np.stack([np.ones_like(x),x],axis=1)
    a0, a1 = np.linalg.lstsq(A,y,rcond=None)[0]
    K_est = -a1 * 5 # Estimated diversity order

    # Plot linear regression line
    label = "$K_{{\mathrm{{est}}}} = {:.2f}$".format(K_est)
    axs.plot(x,np.power(10,a0 + a1*x),"--",
             color=ber_curve[0].get_color(),linewidth=1,label=label)

axs.legend()
fig.tight_layout()
fig.savefig("./plots/{}".format(FIGNAME))

png

BER Simulation for BPSK for K-Path Rayleigh Fading under Section Combining Method

N        = 2**18                 # number of symbols
Ga_l     = np.logspace(0,2,16)   # SNR values
Ga_l_dB  = 20*np.log10(Ga_l)
COMBINER = "section"             # Possible values: {"section", "equal gain", "max ratio"}
FIGNAME  = "diversity_order.png"

fig, axs = plt.subplots()
for K in [1,2,3,4]:
    # Calculate symbol error rate (same as BER for BPSK)
    Pe_l = BPSKRayleighDiversityBER(N,K,Ga_l,COMBINER)
    
    # Plot BER curve
    l_plot = (Pe_l > 0)
    ber_curve = axs.plot(Ga_l_dB[l_plot],Pe_l[l_plot],marker="o",
                         label=r"$K = {}$".format(K))
    
    # Estimate diversity order via linear regression
    l_regression = (Pe_l > 0) & (Ga_l_dB > 10)
    x = Ga_l_dB[l_regression]
    y = np.log10(Pe_l[l_regression])
    A = np.stack([np.ones_like(x),x],axis=1)
    a0, a1 = np.linalg.lstsq(A,y,rcond=None)[0]
    K_est = -a1 * 10 # Estimated diversity order

    # Plot linear regression line
    label = "$K_{{\mathrm{{est}}}} = {:.2f}$".format(K_est)
    axs.plot(x,np.power(10,a0 + a1*x),"--",
             color=ber_curve[0].get_color(),linewidth=1,label=label)
    
axs.set_title(r"Simulated BER of BPSK with Rayleigh fading $K$-order {} combining".format(COMBINER))
axs.set_xlabel(r"Signal-to-noise ratio $\Gamma$ (dB)")
axs.set_ylabel(r"Simulated bit error rate $P_b$")
axs.set_yscale("log")
axs.legend(title = "Diversity order")
fig.tight_layout()
fig.savefig("./plots/{}".format(FIGNAME))

png

%run -i ./python/block_fading.py

rayleigh_diversity's People

Contributors

tijwelch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.