【发布时间】:2017-04-21 07:01:01
【问题描述】:
我有一个输入信号,我计算了它的 FFT。之后,我只需要在一个频率带宽上计算它的 RMS,而不是针对所有频谱。
我应用 Parseval 定理解决了整个频谱的 RMS 计算,但我如何计算这种“选择性”的 RMS?我已经正确计算了索引以获得三个感兴趣的频率(F0、FC、F1),但是当将 RMS 应用于此带宽时,似乎 Parseval 定理不成立。
我收到一个独特的 10 KHz 频率,来自 FFT 总频谱的 RMS 是正确的,但它在 10 KHz 频率下的 RMS 选择性给了我一个错误的结果(从 RMS 正确的一个 -0.4V),应该给我几乎相同的结果因为我在频谱中只有一个频率。在这里你可以看到我的 RMS 选择性计算:
public static double RMSSelectiveCalculation(double[] trama, double samplingFreq, double F0, double Fc, double F1)
{
//Frequency of interest
double fs = samplingFreq; // Sampling frequency
double t1 = 1 / fs; // Sample time
int l = trama.Length; // Length of signal
double rmsSelective = 0;
double ParsevalB = 0;
double scalingFactor = fs;
double dt = 1 / fs;
// 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));
double df = fs / nFFT;
if (nFFT > 655600)
{ }
// Create complex array for FFT transformation. Use 0s for imaginary part
Complex[] samples = new Complex[nFFT];
Complex[] reverseSamples = new Complex[nFFT];
double[] frecuencies = new double[nFFT];
for (int i = 0; i < nFFT; i++)
{
frecuencies[i] = i * (fs / nFFT);
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);
//The indexes will get the index of each frecuency
int f0Index, fcIndex, f1Index;
double k = nFFT / fs;
f0Index = (int)Math.Floor(k * F0);
fcIndex = (int)Math.Floor(k * Fc);
f1Index = (int)Math.Ceiling(k * F1);
for (int i = f0Index; i <= f1Index; i++)
{
ParsevalB += Math.Pow(Math.Abs(s[i].Modulus / scalingFactor), 2.0);
}
ParsevalB = ParsevalB * df;
double ownSF = fs / l; //This is a own scale factor used to take the square root after
rmsSelective = Math.Sqrt(ParsevalB * ownSF);
samples = null;
s = null;
return rmsSelective;
}
【问题讨论】:
-
您之前不是多次问过同样的问题吗? Getting RMS from FFT 和 Get RMS from FFT ?
标签: c# indexing fft frequency rms