高斯白噪声的C语言实现.txt
用C语言实现了高斯白噪声数据的产生 Routine mrandom : To generate the random number(pseudo-white noise). input Parameters: n : the random data number requested; integer . iseed: the seed for pseudo-random data generation.it must be initialized by main program(suggested value is ISEED=12357), and the random number is cycled,the cycle length=1,048,576 itype: random data distribution type, see below: itype=1: Uniform distributed,from 0.0 to 1.0 itype=2: Uniform distributed,Mean=0.0, Variance(方差)(Power) p=1.0 itype=3: Uniform distributed,Mean=0.0, Variance(Power) p=p. itype=4: Gaussian distributed,Mean=0.0, Variance(Power) p=1.0 itype=5: Gaussian distributed,Mean=0.0, Variance(Power) p=p. p :variance(Power) of random, only used when itype=3 or itype=5. out parameters: u :n dimensioned real array, data is stored in u(0) to u(n-1). in Chapter 1
#include <stdlib.h>
#include <math.h>
#include "msp.h"
float randnu(long *iseed)
{
float z;
*iseed=2045*(*iseed)+1;
*iseed=*iseed-(*iseed/1048576)*1048576;//等价于*iseed=(*iseed) % 1048576
z=(float)((*iseed+1)/1048577.0);
return(z);
}
/*--------------------------------------------------------------------*/
void meavar(float u[],int *n,float *pum,float *puv)
{
int i,k;
*pum=0.0;
for(k=0;k<*n;k++)
*pum=*pum+u[k];
*pum=*pum/(*n);
*puv=0.0;
for(i=0;i<*n;i++)
*puv=*puv+pow((u-*pum),2);
*puv=*puv/(*n-1.);//样本方差
return;
}
/*---------------------------------------------------------------------
Routine mrandom : To generate the random number(pseudo-white noise).
input Parameters:
n : the random data number requested; integer .
initialized by main program(suggested value is ISEED=12357),
and the random number is cycled,the cycle length=1,048,576
itype: random data distribution type, see below:
itype=1: Uniform distributed,from 0.0 to 1.0
itype=2: Uniform distributed,Mean=0.0, Variance(方差)(Power) p=1.0
itype=3: Uniform distributed,Mean=0.0, Variance(Power) p=p.
itype=4: Gaussian distributed,Mean=0.0, Variance(Power) p=1.0
itype=5: Gaussian distributed,Mean=0.0, Variance(Power) p=p.
p :variance(Power) of random, only used when itype=3 or itype=5.
out parameters:
u :n dimensioned real array, data is stored in u(0) to u(n-1).
in Chapter 1
---------------------------------------------------------------------*/
void mrandom(float u[],int *n,long *piseed,int itype,float p)
{
int k,ns,ksection,ks,j;
float a,v,umean,uvari;
float *pum,*puv;
pum=&umean;
puv=&uvari;
if(itype >6 || itype <1)
return;
for(k=0;k<*n;k++)
u[k]=randnu(piseed);
if(itype==2 || itype==3)
{
meavar(u,n,pum,puv);
/* to obtain a zero mean and P-power random sequence u[k]).*/
a=1/uvari;
剩余6页未读,继续阅读
- 粉丝: 0
- 资源: 2
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
- 1
- 2
- 3
- 4
- 5
- 6
前往页