Package com.nr.fft

Source Code of com.nr.fft.WrapVecDoub

package com.nr.fft;

import com.nr.Complex;

public class WrapVecDoub {
 
  private double[] v;

  private int n, mask;

  public WrapVecDoub(final int nn) {
    v = new double[nn];
    n = nn / 2;
    mask = n - 1;
    validate();
  }

  public WrapVecDoub(final double[] vec) {
    v = vec;
    n = vec.length / 2;
    mask = n - 1;
    validate();
  }

  private void validate() {
    if ((n & (n - 1)) != 0)
      throw new IllegalArgumentException("vec size must be power of 2");
  }
 
  public void set(int i, Complex c) {
    int ii = (i & mask) << 1;
    v[ii] = c.re();
    v[ii + 1] = c.im();
  }

  public Complex get(int i) {
    int ii = (i & mask) << 1;
    return new Complex(v[ii], v[ii + 1]);
  }

  public void setReal(int i, double rr) {
    v[(i & mask) << 1] = rr;
  }
  public double real(int i) {
    return v[(i & mask) << 1];
  }

  public void setImag(int i, double rr) {
    v[((i & mask) << 1) + 1] = rr;
  }
 
  public double imag(int i) {
    return v[((i & mask) << 1) + 1];
  }

  public double[] get() {
    return v;
  }

}
TOP

Related Classes of com.nr.fft.WrapVecDoub

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.