Java Abs abs2(float[] f)

Here you can find the source of abs2(float[] f)

Description

Computes the power spectrum from FFT data taking into account even/odd length arrays refer to JTransforms documentation for layout of the FFT data

License

Open Source License

Parameter

Parameter Description
f the DFT-transformed data from JTransforms.realForward()

Return

the power spectrum of the complex frequency spectrum in f

Declaration

public static float[] abs2(float[] f) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w w  w  .j a  v a2 s  .c o  m
     * Computes the power spectrum from FFT data
     * taking into account even/odd length arrays
     * refer to JTransforms documentation for layout of the FFT data
     * @param f the DFT-transformed data from JTransforms.realForward()
     * @return the power spectrum of the complex frequency spectrum in f
     */
    public static float[] abs2(float[] f) {
        int n = f.length;
        float[] ps = new float[n / 2 + 1];
        // DC component
        ps[0] = (f[0] * f[0]) / (n * n);

        // Even
        if (n % 2 == 0) {
            for (int k = 1; k < n / 2; k++) {
                ps[k] = f[2 * k] * f[2 * k] + f[2 * k + 1] * f[2 * k + 1];
            }
            ps[n / 2] = f[1] * f[1];
            // Odd
        } else {
            for (int k = 1; k < (n - 1) / 2; k++) {
                ps[k] = f[2 * k] * f[2 * k] + f[2 * k + 1] * f[2 * k + 1];
            }

            ps[(n - 1) / 2] = f[n - 1] * f[n - 1] + f[1] * f[1];
        }

        return ps;
    }
}

Related

  1. abs(int x)
  2. abs(long index)
  3. Abs(Object in)
  4. abs(short x)
  5. abs2(double[][] IN)
  6. abs_fractional(double number)
  7. abs_min(double a, double b)
  8. absAngleDifference(double angle1Radians, double angle2Radians)
  9. absApproximation(double x, double M)