Here you can find the source of modulusSq(float[][] a)
Parameter | Description |
---|---|
a | complex array |
public static float[][] modulusSq(float[][] a)
//package com.java2s; /*/*from w ww . j av a2 s. c om*/ * Copyright 2016 Universidad Nacional de Colombia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Computes the squared modulus of a complex array. * <p> * {@code * modulusSq[i][j] = Re[i][j]^2 + Im[i][j]^2 * } * * @param a complex array * @return modulus squared array */ public static float[][] modulusSq(float[][] a) { checkDimension(a); int M = a.length; int N = a[0].length / 2; float[][] modulusSq = new float[M][N]; for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { modulusSq[i][j] = (a[i][2 * j] * a[i][2 * j]) + (a[i][2 * j + 1] * a[i][2 * j + 1]); } } return modulusSq; } /** * Computes the squared modulus of a complex array. * <p> * {@code * modulusSq[i][j] = Re[i][j]^2 + Im[i][j]^2 * } * * @param a complex array * @return modulus squared array */ public static double[][] modulusSq(double[][] a) { checkDimension(a); int M = a.length; int N = a[0].length / 2; double[][] modulusSq = new double[M][N]; for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { modulusSq[i][j] = (a[i][2 * j] * a[i][2 * j]) + (a[i][2 * j + 1] * a[i][2 * j + 1]); } } return modulusSq; } private static void checkDimension(float[][] a) { if (a.length == 0) { throw new IllegalArgumentException("Arrays dimension must be greater than 0."); } else if (a[0].length == 0) { throw new IllegalArgumentException("Arrays dimension must be greater than 0."); } } private static void checkDimension(double[][] a) { if (a.length == 0) { throw new IllegalArgumentException("Arrays dimension must be greater than 0."); } else if (a[0].length == 0) { throw new IllegalArgumentException("Arrays dimension must be greater than 0."); } } }