java 频域滤波算法
时间: 2024-01-23 19:03:18 浏览: 153
以下是Java中频域滤波的算法示例:
```javaimport org.apache.commons.math3.complex.Complex;
import org.apache.commons.math3.transform.DftNormalization org.apache.commons.math3.transform.FastFourierTransformer;
import org.apache.math3.transform.TransformType;
public class FrequencyDomainFilter {
public static void main(String[] args) {
// 输入信号
double[] inputSignal = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// 进行快速傅里叶变换
FastFourierTransformer transformer = new FastFourierTransformer(DftNormalization.STANDARD);
Complex[] frequencyDomain = transformer.transform(inputSignal, TransformType.FORWARD);
// 频域滤波,将不需要的频率置零
int cutoffFrequency = 3; // 截止频率
for (int i = 0; i < frequencyDomain.length; i++) {
if (i > cutoffFrequency && i < frequencyDomain.length - cutoffFrequency) {
frequencyDomain[i] = Complex.ZERO;
}
}
// 进行反傅里叶变换,得到滤波后的时域信号
Complex[] filteredSignal = transformer.transform(frequencyDomain, TransformType.INVERSE);
// 输出滤波后的时域信号
for (Complex value : filteredSignal) {
System.out.println(value.getReal());
}
}
}
```
阅读全文