I am working on a function that calculates the total energy of a vector.
From researching, and another system (completed in MatLab) the equation set’s out that it takes the abs value of each of the vector summed. The values of the summation of the vectors is “0” for each vector, here is the code:
vector<double> Audio::filter(vector<iniMatrix>&blocks, double sumThres, double ZeroThres)
{
vector<double> totalEnergy;
for(unsigned i=0; (i < blocks.size()); i++)
{
totalEnergy.push_back(abs(this->energy(blocks[i])));
}
for(unsigned i=0; (i < totalEnergy.size()); i++)
{
cout << totalEnergy[i] << endl;
}
}
double Audio::energy(vector<double>&blocks)
{
return accumulate(blocks.begin(), blocks.end(), 0);
}
There are 96 blocks, each containing 600 values. The values are doubles:
0.0078125, 0.0234375, 0.015625
0.0078125, 0.0234375, ….. ,
Anyone have any ideas to why I get “0” value for each one?
Accumulate is the following template:
Try to use a double as ‘init’: