资源简介
java实现FFT算法,关于快速傅里叶变换(FFT)和傅里叶变换的理论知识这里我就不提了,本文主要讲解FFT实现:
之前想找一个FFT代码,在网上找了很多都是有问题的,下面我完善了一个供大家学习交流;
代码片段和文件信息
import java.util.objects;
public class Complex {
private final double re; // the real part
private final double im; // the imaginary part
// create a new object with the given real and imaginary parts
public Complex(double real double imag) {
re = real;
im = imag;
}
// return a string representation of the invoking Complex object
public String toString() {
if (im == 0) return re + ““;
if (re == 0) return im + “i“;
if (im < 0) return re + “ - “ + (-im) + “i“;
return re + “ + “ + im + “i“;
}
// return abs/modulus/magnitude
public double abs() {
return Math.hypot(re im);
}
// return angle/phase/argument normalized to be between -pi and pi
public double phase() {
return Math.atan2(im re);
}
// return a new Complex object whose value is (this + b)
public Complex plus(Complex b) {
Complex a = this; // invoking object
double real = a.re + b.re;
double imag = a.im + b.im;
return new Complex(real imag);
}
// return a new Complex object whose value is (this - b)
public Complex minus(Complex b) {
Complex a = this;
double real = a.re - b.re;
double imag = a.im - b.im;
return new Complex(real imag);
}
// return a new Complex object whose value is (this * b)
public Complex times(Complex b) {
Complex a = this;
double real = a.re * b.re - a.im * b.im;
double imag = a.re * b.im + a.im * b.re;
return new Complex(real imag);
}
// return a new object whose value is (this * alpha)
public Complex scale(double alpha) {
return new Complex(alpha * re alpha * im);
}
// return a new Complex object whose value is the conjugate of this
public Complex conjugate() {
return new Complex(re -im);
}
// return a new Complex object whose value is the reciprocal of this
public Complex reciprocal() {
double scale = re*re + im*im;
return new Complex(re / scale -im / scale);
}
// return the real or imaginary part
public double re() { return re; }
public double im() { return im; }
// return a / b
public Complex divides(Complex b) {
Complex a = this;
return a.times(b.reciprocal());
}
// return a new Complex object whose value is the complex exponential of this
public Complex exp() {
return new Complex(Math.exp(re) * Math.cos(im) Math.exp(re) * Math.sin(im));
}
// return a new Complex object whose value is the complex sine of this
public Complex sin() {
return new Complex(Math.sin(re) * Math.cosh(im) Math.cos(re) * Math.sinh(im));
}
// return a new Complex object whose value is the complex
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-12-14 15:17 Test\
文件 377 2019-01-02 17:39 Test\.classpath
文件 380 2018-12-14 15:17 Test\.project
目录 0 2018-12-14 15:17 Test\.settings\
文件 598 2018-12-14 15:17 Test\.settings\org.eclipse.jdt.core.prefs
目录 0 2019-01-03 17:24 Test\bin\
文件 4456 2019-01-03 17:24 Test\bin\Complex.class
文件 3114 2019-01-03 17:24 Test\bin\FFT.class
目录 0 2019-01-02 17:39 Test\src\
文件 4920 2019-01-02 17:31 Test\src\Complex.java
文件 6807 2019-01-02 18:50 Test\src\FFT.java
- 上一篇:利用Java程序把多张图片合成一张图片
- 下一篇:java与蓝牙通信
评论
共有 条评论