Root Mean Square Value of Histogram

How do I find the root mean square value of this histogram?
The data is Histo = [1;47;56;1298;9770;1114;0;0;2]

 Accepted Answer

Rik
Rik on 15 Jan 2018
Edited: Rik on 15 Jan 2018
If you don't have the original data, you can approximate it with the code below.
Histo = [1;47;56;1298;9770;1114;0;0;2]
centers=-4:4;
mean_of_squared_values=sum(Histo.*(centers(:).^2))/sum(Histo);
RMS=sqrt(mean_of_squared_values);
This works because the mean is the sum divided by the count.

6 Comments

Why do you take the histo.*centers(:)?
You need to calculate the mean, but you only have the bin counts. But now that you point to it: there is indeed an error there, see edit.
for the Mean Squared values, why isit necessary to multipy Histo with the squared values of centre? Isn't Mean Squared Values = (Histo.^2)) which can also be MSV = sum((Histo.^2)/length(Histo))
No, because Histo is the number of items in each bin, not the data itself. By squaring the center values you apply the square, by multiplying with Histo, summing and dividing by the total number of values (i.e. sum(Histo)) you take the mean. Then only the square root remains to have a root-mean-square.
Amy Wong
Amy Wong on 17 Jan 2018
Edited: Amy Wong on 17 Jan 2018
I know that the RMS is to find the Standard Deviation of the histogram. Do I use the RMS of the original data values or the RMS the bin locations?
I'm guessing you overlooked my answer below. We don't know which of the 3 RMS values you want. Only you know that. Maybe if you told us what you wanted to do with that information we could guide you.

Sign in to comment.

More Answers (1)

Amy:
I just want to make sure you realize that the RMS of the original data values is not the same as the RMS of the bin locations (what Rik gave you), and neither is the same as the RMS of the bin heights. Yo DO know that don't you? So, which do you want? I give an illustration of all 3 in the demo code below, and you can see how they're different.
r = randn(20);
h = histogram(r)
counts = h.Values'
edges = h.BinEdges'
binCenters = (edges(1:end-1) + edges(2:end))/2
mean_of_squared_values = sum(counts.*(binCenters.^2))/sum(counts);
% Compute the RMS value of the bin center locations.
rmsCenters = sqrt(mean_of_squared_values)
% Compute the RMS value of the bin heights (counts).
rmsCounts = rms(counts)
% Compute the RMS of the actual data values.
rmsValues = rms(r(:))
% They're not the same!

Categories

Asked:

on 15 Jan 2018

Commented:

on 17 Jan 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!