Mkachakh Madridsita
Mkachakh Madridsita

Reputation: 41

fiitting a normal distribution to a histogram in C++

I am working on spectrum sensing in C++ and my problem until now is how to estimate the exact value of noise. So I did the histogram of my data and I want to fit a gaussian distribution to this histogram and then I have the mean of this fitting distribution like in 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();
}

Thanks in advance for any help!

Upvotes: 0

Views: 1633

Answers (1)

rubenvb
rubenvb

Reputation: 76519

The normal distribution makes this quite easy:

mean = sum(spectrum_sensed)/N

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

You don't fit a histogram, you fit the data. And in the case of a normal distribution, there's no fitting involved as everything is analytical.

Upvotes: 1

Related Questions