使用 JTransform 或 JWave 的输出,应如何计算相位谱?
我是否只需编写一个类似的方法,但我使用以下方法计算相位:
Math.atan2(im/re) * Math.PI * 180
?
我使用以下方法来计算幅度谱:
@Override
public void computeSpectrum()
{
// The spectrum into which we store the data
super.spectrum = new double[signal.getSampledAmplitudes().length >> 1];
// Compute the magnitude spectrum of the signal
double re = 0, im = 0;
for (int bin = 0; bin < spectrum.length - 1; ++bin) {
re = super.frequencyDomain[2 * bin];
im = super.frequencyDomain[2 * bin + 1];
super.spectrum[bin] = Math.sqrt(re * re + im * im);
}
}
最佳答案
事实上,您可以使用与计算幅度谱类似的循环来计算以弧度为单位的相位谱:
double re = 0, im = 0;
for (int bin = 0; bin < spectrum.length - 1; ++bin) {
re = super.frequencyDomain[2 * bin];
im = super.frequencyDomain[2 * bin + 1];
super.spectrum[bin] = Math.atan2(im, re);
}
如果您更喜欢以度为单位的结果,只需使用 toDegrees()
转换相位即可
...
super.spectrum[bin] = Math.toDegrees(Math.atan2(im, re));
关于java - 计算信号的相位谱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55345939/