Returns the average power per sample. - Java java.lang

Java examples for java.lang:double

Description

Returns the average power per sample.

Demo Code


//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;
    }
}

Related Tutorials