数据拟合-在c++中拟合正态分布到直方图

data fitting - fiitting a normal distribution to a histogram in C++

本文关键字:拟合 正态分布 直方图 c++ 数据      更新时间:2023-10-16

我正在研究c++中的频谱传感,直到现在我的问题是如何估计噪声的确切值。所以我做了数据的直方图,我想把高斯分布拟合到这个直方图上,然后我得到了这个拟合分布的均值,就像在matlab中[mean,variance]=normfit(x)。

vec noise::gauss_fit(vec spectrum_sensed,int Nfft)
{
    Histogram<double> hist;
    hist.setup(min(spectrum_sensed),max(spectrum_sensed),Nfft);
    // now I need to fit this histogram by a normal distribution "Normal"
    // and finally I get the mean of this distribution: normal.get_setup();
}

提前感谢您的帮助!

正态分布使得这很容易:

mean = sum(spectrum_sensed)/N
variance = sum((spectrum_sensed-mean)^2)/N

你不是拟合直方图,而是拟合数据。在正态分布的情况下,没有拟合,因为一切都是分析性的。