⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signalstrength.cpp

📁 模拟一个逐渐离开基站的手机接收到的顺时信号强度
💻 CPP
字号:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h> 
#define MAX 50.0
#define MIN 0.1
#define MIU 2
#define SIGMA 7
#define n 3
#define PI 3.14159

double AverageRandom(double min,double max)
{
        int MINnteger = (int)(min*10000);
        int MAXnteger = (int)(max*10000);
        int randInteger = rand()*rand();
        int diffInteger = MAXnteger - MINnteger;
        int resultInteger = randInteger % diffInteger + MINnteger;
        return resultInteger/10000.0;
}
double LogNormal(double x,double miu,double sigma) //对数正态分布概率密度函数
{
        return 1.0/(x*sqrt(2*PI)*sigma) * exp(-1*(log10(x)-miu)*(log(x)-miu)/(2*sigma*sigma));
}
double Rayleigh(double x,double miu,double sigma) 
{
		return 2*x/(sigma*sigma)*exp(-x*x/(sigma*sigma));//瑞利分布概率密度函数
}
double Random_LogNormal(double miu,double sigma,double min,double max)//产生对数正态分布随机数
{
        double x;
        double dScope;
        double y;
        do
        {
        x = AverageRandom(min,max); 
        y = LogNormal(x, miu, sigma);
        dScope = AverageRandom(0, LogNormal(miu,miu,sigma));
        }while( dScope > y);
        return x;
}
double Random_Rayleigh(double miu,double sigma,double min,double max)//产生瑞利分布随机数
{
        double x;
        double dScope;
        double y;
        do
        {
        x = AverageRandom(min,max); 
        y = Rayleigh(x, miu, sigma);
        dScope = AverageRandom(0, Rayleigh(miu,miu,sigma));
        }while( dScope > y);
        return x;
}

double SignalStrength(double a1,double a2,double a3,double R,double nn)
{	
		return (a1+a2+a3)*pow(R,-nn); //接收信号强度
}
void main(void)
{
		srand(time(NULL));
		double R,S;
		double alpha1,alpha2,alpha3;
		alpha1=1.0;
		for (R=0.5;R<=2;R+=0.05)
		{
			printf("R=%-11.3f",R);
			alpha2=Random_LogNormal(MIU,SIGMA,MIN,MAX);//产生对数正态分布随机数
			alpha3=Random_Rayleigh(MIU,SIGMA,MIN,MAX); //产生瑞利分布随机数
			S=SignalStrength(alpha1,alpha2,alpha3,R,n);//接收信号强度
			printf("S=%lf\n",S);
		}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -