【基础教程】Matlab生成阴影 Rician 随机数

简介: 【基础教程】Matlab生成阴影 Rician 随机数

 ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法神经网络预测雷达通信 无线传感器

信号处理图像处理路径规划元胞自动机无人机

1 内容介绍

莱斯分布实际上可以理解为主信号与服从瑞利分布的多径信号分量的和。概率密度函数公式中,R即为正弦(余弦)信号加窄带高斯随机信号的包络,参数A是主信号幅度的峰值,σ^2是多径信号分量的功率,I0()是修正的0阶第一类贝塞尔函数。

是不是感觉这个更抽象了,那有什么用呢,在通信中,有一个信号占主要成分的噪声中,信道噪声一般呈现莱斯分布。

2 部分代码

clear;clc;

close all

%% Parameters

N = 1e5;

b = 0.279;

m = 2;

Omega = 0.251;

%% Generate Shadowed Rician Random Number

X = ShadowedRicianRandGen(b,m,Omega,N);

%% Points for which distribution has to be evaluated

x = linspace(0,5,1000);

%% Estimate Distribution

[fsim,Fsim] = EstimateDistribution(X,x);

%% Theoretical PDF & CDF

[fana,Fana] = ShadowedRicianDistribution(b,m,Omega,x);

%% Plot Results

subplot(121);plot(x(1:30:end),Fsim(1:30:end),'-b*',x,Fana,'-');grid on;

xlabel('x');ylabel('F_X(x) = P(X<=x)');

subplot(122);plot(x(1:30:end),fsim(1:30:end),'-b*',x,fana,'-');grid on;

xlabel('x');

ylabel('Probability Density Function');

legend('Simulated','Theoretical');

function X = ShadowedRicianRandGen(b,m,Omega,N,a)

% This function generates random number according to shadowed Rician

% density function.

%

% INPUTS:

%           b = Scalar (real), Average power of multipath component

%           m = Scalar (real), Fading severity parameter

%       Omega = Scalar (real), Average power of LOS component

%           N = Scalar (real) specifying number of random number to be

%               generated

% OUTPUTS:

%           X = Scalar (Column Vector if N > 1) specifying random number

%               generated using Shadowed Rician distribution function

%

% USAGE EXAMPLES:

% X = ShadowedRicianRandGen(0.279,2,0.251);

%

% REFERENCES:

% A. Abdi, W. C. Lau, M.-S. Alouini, and M. Kaveh, 揂 new simple model

% for land mobile satellite channels: First- and second-order statistics,?% IEEE Trans. Wireless Commun., vol. 2, no. 3, pp. 519?28, May 2003.

% Jeruchim, M. C., P. Balaban, and K. S. Shanmugam, Simulation of

% Communication Systems, New York, Plenum Press, 1992.

%

% Implemented By:

% Ashish (MEET) Meshram

% meetashish85@gmail.com;

% Checking Input Arguments

if nargin<5||isempty(a),a = 10;end

if nargin<4||isempty(N),N = 10000;end

if nargin<3||isempty(Omega)

   error('Missing Input Argument: Please specify omega');

end

if nargin<2||isempty(m)

   error('Missing Input Argument: Please specify m');

end

if nargin<1||isempty(b)

   error('Missing Input Argument: Please specify b');

end

% Implementation Starts Here

X = zeros(N,1);                   % Preallocating memory space for X

% Intermediate Variables

alpha = ((2*b*m)/(2*b*m + Omega))^m;

beta = Omega/(2*b*(2*b*m + Omega));

lambda = 1/(2*b);

% Maximum value of Shadowed Rician value occurs at x = 0;

maxfx = alpha*lambda;

c = maxfx;

% Accept and Reject Algorithm

for k = 1:N

   accept = false;

   while accept == false

       U2 = c*rand;              % Generating U2, Uniformly disributed

                                 % random number [0,c]

       U1 = a*rand;              % Generating U1, Uniformly distributed

                                 % in [0,a]

       % Evaluating fx for U1                        

       fx = alpha*lambda*exp(-U1*lambda)*Kummer(m,1,beta*U1);

       % if U2 is less than or equal to fx at U1 then its taken as X else

       % repeat the above procedure

       if U2 <= fx

           X(k) = U1;

           accept = true;

       end

   end

end

function y = Kummer(a,b,z,maxit)

% This function implements 1F1(.;.;.), Confluent Hypergeometric function.

%

% INPUTS:

%       a = Scalar and complex

%       b = Scalar and complex

%       z = Scalar and complex

%   maxit = Scalar and real number specifying maximum number of iteration.

%           Default, maxit = 5;

%

% OUTPUT:

%       y = Scalar and complex

%

% Implemented By:

% Ashish (MEET) Meshram

% meetashish85@gmail.com;

% Checking Input Arguments

if nargin<1||isempty(a)

   error('Missing Input Argument: Please specify a');

end

if nargin<2||isempty(b)

   error('Missing Input Argument: Please specify b');

end

if nargin<3||isempty(z)

   error('Missing Input Argument: Please specify z');

end

if nargin<4||isempty(maxit),maxit = 5;end

% Implementation

ytemp = 1;

for k = 1:maxit

   ytemp = ytemp...

           + PochhammerSymbol(a,k)/(PochhammerSymbol(b,k)...

           * factorial(k))*z^k;

   y = ytemp;

end

function y = PochhammerSymbol(x,n)

if n == 0

   y = 1;

else

   y = 1;

   for k = 1:n

       y = y*(x + k - 1);

   end

end

function [f,F] = EstimateDistribution(X,x)

% This function implements estimation of CDF and PDF of one dimensional

% random variables.

%

% INPUTS:

%           X = vector specifying random variables

%           x = vector specifying points for which CDF and PDF has to be

%               evaluated

% OUTPUTS:

%           f = vector specifying estimated PDF of random variable X for

%               points.

%           F = vector specifying estimated CDF of random variable X for

%               points.

%

% USAGE EXAMPLES:

% %% Generate N Standard Normally Distributed Random Variable

% N = 1000000;

% X = randn(N,1);

% %% Points for which CDF and PDF are to be evaluated

% x = linspace(-10,10,1000);

% %% Estimate PDF and CDF

% [f,F] = EstimateDistribution(X,x);

% %% Plot Results

% figure(1);

% plot(x,f,x,F);

% xlabel('x');

% ylabel('Simulated PDF & CDF');

% str1 = strcat('PDF;','Area = ',num2str(trapz(x,f)));

% legend(str1,'CDF','Location','northwest');

%

%

% %% Generate N Gaussianly Distributed Random Variable with specific mean and

% %% Standard Deviation

% N = 1000000;

% mu = -1;

% sigma = 5;

% X = mu + sigma*randn(N,1);

% %% Points for which CDF and PDF are to be evaluated

% x = linspace(-10,10,1000);

% %% Theoretical PDF and CDF

% fx = (1/sqrt((2*pi*sigma*sigma)))*exp(-(((x - mu).^2)/(2*sigma*sigma)));

% Fx = 0.5*(1 + erf((x - mu)/(sqrt(2*sigma*sigma))));

% %% Estimate PDF and CDF

% [f,F] = EstimateDistribution(X,x);

% %% Plot Results

% figure(2);

% plot(x,f,x,fx,x,F,x,Fx);

% xlabel('x');

% ylabel('PDF & CDF');

% str1 = strcat('Simulated PDF;','Area = ',num2str(trapz(x,f)));

% str2 = strcat('Theoretical PDF;','Area = ',num2str(trapz(x,fx)));

% legend(str1,str2,'Simulated CDF','Theoretical CDF','Location','northwest');

%

%

% %% Generate N Uniformaly Distributed Random Variable

% N = 1000000;

% X = rand(N,1);

% %% Points for which CDF and PDF are to be evaluated

% x = linspace(-10,10,1000);

% %% Estimate PDF and CDF

% [f,F] = EstimateDistribution(X,x);

% %% Plot Results

% figure(3);

% plot(x,f,x,F);

% xlabel('x');

% ylabel('Simulated PDF & CDF');

% str1 = strcat('PDF;','Area = ',num2str(trapz(x,f)));

% legend(str1,'CDF','Location','northwest');

%

% REFERENCES:

% Athanasios Papoulis, S. Unnikrishna Pillai, Probability, Random Variables

% and Stochastic Processes, 4e

% Peyton Z. Peebles Jr., Probability, Random Variables, And Random Signal

% Principles, 2e

% Saeed Ghahramani, Fundamentals of Probability, with Stochastic Processes,

% 3e

%

% SEE ALSO:

% interp1, smooth

%

% AUTHOR:

% Ashish (Meet) Meshram

% meetashish85@gmail.com; mt1402102002@iiti.ac.in

% Checking Input Arguments

if nargin<2||isempty(x), x = linspace(-10,10,1000);end

if nargin<2||isempty(X)

   error('Missing Input Arguments: Please specify vector random variables');

end

% Impelementation Starts Here

f = zeros(1,length(x)); % Preallocation of memory space

F = f;                  % Preallocation of memory space

h = 0.000000001;        % Small value closer to zero for evaluating

                       % numerical differentiation.

% Estimating CDF by its definition

for m = 1:length(x)

   p = 0;              % True Probability

   q = 0;              % False Probability

   for n = 1:length(X)

       if X(n)<=x(m)   % Definition of CDF

           p = p + 1;

       else

           q = q + 1;

       end

   end

   F(m) = p/(p + q);   % Calulating Probability

end

% Estimating PDF by differentiation of CDF

for k = 1:length(x)

   fxph = interp1(x,F,x(k) + h,'spline');  % Interpolating value of F(x+h)

   fxmh = interp1(x,F,x(k) - h,'spline');  % Interpolating value of F(x-h)

   f(k) = (fxph - fxmh)/(2*h);             % Two-point formula to compute

end                                         % Numerical differentiation

f = smooth(f);                              % Smoothing at last

function [f,F] = ShadowedRicianDistribution(b,m,Omega,x)

lambda = 1/(2*b);

alpha = (2*b*m)/(2*b*m + Omega);

beta = Omega/(2*b*(2*b*m + Omega));

% Theoretical PDF

f = zeros(length(x),1);

for k = 1:length(x)

   f(k) = (alpha^m)*lambda*exp(-x(k)*lambda)*Kummer(m,1,beta*x(k));

end

% Theoretical CDF

sumk = zeros(500,1);

F = zeros(length(x),1);

for p = 1:length(x)

   for q = 1:500

       mmk = gamma(m+k);

       mk = gamma(m);

       betabylambdak = (beta/lambda)^k;

       gammak = gammainc(k+1,lambda*x(p));

       sumk(q) = (mmk/(mk*(factorial(k))^2))*betabylambdak*gammak;

   end

   F(p) = alpha*sum(sumk);

end

3 运行结果

image.gif编辑

4 参考文献

博主简介:擅长智能优化算法神经网络预测信号处理元胞自动机图像处理路径规划无人机雷达通信无线传感器等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。


相关文章
|
5月前
【Simulink】示波器图形数据导入Matlab重新绘图的简明教程(论文)
【Simulink】示波器图形数据导入Matlab重新绘图的简明教程(论文)
|
5月前
【MATLAB】全网入门快、免费获取、持续更新的科研绘图教程系列1
【MATLAB】全网入门快、免费获取、持续更新的科研绘图教程系列1
112 0
【MATLAB】全网入门快、免费获取、持续更新的科研绘图教程系列1
|
2月前
|
Go C++ Windows
Matlab 冰壶仿真游戏安装及教程
在Matlab上安装并运行冰壶仿真游戏的详细教程,包括编译环境准备、通过APP安装或直接运行源代码的方式,以及游戏的基本操作步骤。
33 0
|
4月前
|
算法 数据可视化 数据挖掘
大学生必备!GitHub星标破千的matlab教程(从新手到骨灰级玩家)
MATLAB(Matrix Laboratory)是MathWorks公司推出的用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境的商业数学软件。 MATLAB具有数值分析、数值和符号计算、工程与科学绘图、数字图像处理、财务与金融工程等功能,为众多科学领域提供了全面的解决方案。
|
4月前
|
算法 数据可视化 数据挖掘
大学生必备!GitHub星标破千的matlab教程(从新手到骨灰级玩家)
MATLAB(Matrix Laboratory)是MathWorks公司推出的用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境的商业数学软件。 MATLAB具有数值分析、数值和符号计算、工程与科学绘图、数字图像处理、财务与金融工程等功能,为众多科学领域提供了全面的解决方案。
|
4月前
|
数据可视化 数据挖掘 计算机视觉
Matlab教程:入门指南
Matlab教程:入门指南
|
5月前
MATLAB2022安装下载教程
MATLAB2022安装下载教程
717 2
|
5月前
|
编解码 移动开发 资源调度
【MATLAB】全网入门快、免费获取、持续更新的科研绘图教程系列1
【MATLAB】全网入门快、免费获取、持续更新的科研绘图教程系列1
82 0
|
5月前
第三章:MATLAB基础教程:控制流程和条件语句
第三章:MATLAB基础教程:控制流程和条件语句
62 0
|
5月前
|
存储 索引
第二章:MATLAB基础教程:数组和矩阵运算
第二章:MATLAB基础教程:数组和矩阵运算
59 0

热门文章

最新文章