2017-04-21 129 views
0

我有一个输入信号,我计算了它的FFT。之后,我只需要在频率带宽上计算其均方根值,而不是针对所有频谱。获得每个频率的RMS

我使用Parseval定理求解了整个频谱的RMS计算,但是如何计算这种RMS“选择性”?我已经正确地计算了索引以获得三个感兴趣的频率(F0,FC,F1),但是当将RMS应用于该频带时,似乎Parseval的定理不是完整的。

我收到一个独特的10 KHz频率,从FFT总频谱的RMS是正确的,但其RMS选择性在10 KHz频率给我一个错误的结果(-0.4V从RMS正确的一个),应该给我几乎相同因为我在频谱中只有一个频率。在这里,您可以看到我的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; 

    } 
+0

你以前没有问过这个问题吗? [从FFT获取RMS](http://stackoverflow.com/questions/43452138/getting-rms-from-fft)和[从FFT获取RMS](http://stackoverflow.com/questions/43363860/get-rms -from-fft)? –

回答

0

功率谱密度PSD的估计值由FFT的幅度的平方给出。

具有一定带宽的部分的RMS是该部分的PSD区域的根。

因此,实际上,只需将FFT的绝对值积分在较低和较高频率之间即可。

MATLAB example

+0

请看我的回答 –