Java examples for java.lang:double
Returns the average power per sample.
//package com.java2s; public class Main { /**//from w w w .j a v a 2s . co m * Returns the average power per sample. * @param sample * @return */ public static double getAveragePower(double[] sample) { return getPower(sample) / sample.length; } /** * Calculates the power in a sample as sum of the squares of the absolute values of all samples. * @param sample * @return */ public static double getPower(double[] sample) { double power = 0; for (int i = 0; i < sample.length; i++) { power += Math.pow(Math.abs(sample[i]), 2); } return power; } }