Re: VHDL code for finding standard deviation for a chunk of numbers
- From: "Marty Ryba" <martin.ryba.nospam@xxxxxxxxxxx>
- Date: Tue, 18 Aug 2009 01:30:42 GMT
"Pratap" <pratap.iisc@xxxxxxxxx> wrote in message
news:1bc417fc-61e2-44d9-a1d4-969ae79a9661@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Yes...variance will also do...
Well, depending on your need for speed, I can assume you can take your time
and build up the necessary sums. The variance is the mean square minus the
mean squared (subtle addition of the d means something here). So, your
algorithm looks like this:
1. Define two numbers: sum, sumsq
2. Set both to zero to start
3. For each point from 1 to N:
sum <= sum + x;
sumsq <= sumsq + (x * x);
When done:
mean <= sum / N; -- Here's the mean if you need it
var <= sumsq / N - (mean * mean);
Power of two divisions can of course be replaced by shifts, or if you want
some form of floating point you are adjusting the exponent and leaving the
mantissa alone. If you want the variance of a number stream relative to a
forced zero mean you can dispense with the calculation of the mean and just
take the sum of squares divided by N.
-Marty
.
- References:
- Prev by Date: Re: Embedded Memory Controller
- Next by Date: Re: Post sythesys vs FPGA board implementation
- Previous by thread: Re: VHDL code for finding standard deviation for a chunk of numbers
- Next by thread: Embedded Memory Controller
- Index(es):
Relevant Pages
|