C语言实现高斯随机信号-浮点信号

#include <string.h>
#include <stdlib.h>
#include <math.h>


float crtl_rand_gauss(void) 
{
    float v1,v2,s;

    do {
        v1 = 2.0 * ((float) rand()/RAND_MAX) - 1;
        v2 = 2.0 * ((float) rand()/RAND_MAX) - 1;

        s = v1*v1 + v2*v2;
    } while ( s >= 1.0 || s == 0.0);

    return (v1*sqrt(-2.0 * log(s) / s));
}

发布了632 篇原创文章 · 获赞 325 · 访问量 57万+

猜你喜欢

转载自blog.csdn.net/Rong_Toa/article/details/105302177
今日推荐