我希望在对数据执行fft之后获取RMS,以便直接获得与数据RMS相同的结果。
我遵循了这个主题https://fr.mathworks.com/matlabcentral/answers/131353-relation-between-fft-and-rms,但我得不到相同的结果,这是一个很大的区别。
根据Parseval定理“信号的总能量在傅里叶变换(Parseval定理)下保留,因此函数的平方和(或积分)等于平方的平方和(或积分)它的变换.RMS将是该值的平方根。“
因此,将“_tempMonitorChannelValues”作为我的数据,使用lenght = 400000个样本,首先我按如下方式计算数据的RMS:
for (int i = 0; i < _tempMonitorChannelValues.Length; i++)
{
RMSTIME += Math.Pow(_tempMonitorChannelValues[i], 2.0);
}
RMSTIME = RMSTIME / _tempMonitorChannelValues.Length;
RMSTIME = Math.Sqrt(RMSTIME);
之后,我按如下方式计算“_tempMonitorChannelValues”的fft:
public static VectorDPoint FFT(double[] trama, double samplingFreq)
{
double fs = samplingFreq; // Sampling frequency
double t1 = 1 / fs; // Sample time
int l = trama.Length; // Length of signal
// Time vector
//Vector t = Normal(0, l, 1) * t1;
//// Values vector
//Vector y = new Vector(trama);
// We just use half of the data as the other half is simetric. The middle is found in NFFT/2 + 1
int nFFT = (int)Math.Pow(2, NextPow2(l));
if (nFFT > 655600)
{ }
// Create complex array for FFT transformation. Use 0s for imaginary part
Complex[] samples = new Complex[nFFT];
for (int i = 0; i < nFFT; i++)
{
if (i >= trama.Length)
{
samples[i] = new MathNet.Numerics.Complex(0, 0);
}
else
{
samples[i] = new MathNet.Numerics.Complex(trama[i], 0);
}
}
ComplexFourierTransformation fft = new ComplexFourierTransformation(TransformationConvention.Matlab);
fft.TransformForward(samples);
ComplexVector s = new ComplexVector(samples);
s = s / l;
Vector f = (fs / 2.0) * Linspace(0, 1, (nFFT / 2) + 1);
VectorDPoint result = new VectorDPoint();
for (int i = 0; i < (nFFT / 2) + 1; i++)
{
result.Add(new DPoint(f[i], 2 * s[i].Modulus));
}
s = null;
f = null;
samples = null;
return result;
}
最后我计算了fft中模数的RMS:
VectorDPoint fftVector = MathPlus.FFT(_tempMonitorChannelValues, _sampleRate);
double[] fftX, fftY;
fftVector.GetDoubleArrays(out fftX, out fftY);
for (int i = 0; i < (fftY.Length / 2) + 1; i++)
{
RMSFFT2 += Math.Pow((fftY[i]), 2.0);
}
RMSFFT2 = Math.Sqrt(RMSFFT2);
我不知道他们为什么会有如此不同的结果...