Advertisement
Guest User

Untitled

a guest
May 22nd, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1.         private float getPeakSignal()
  2.         {
  3.             // attempts to determine the peak signal dB from the currently tuned frequency,
  4.             // and within the currently defined filter bandwidth          
  5.             lock (_fftResolutionLockObject)
  6.             {
  7.                 if (_fftSpectrum.Length != _controlInterface.FFTResolution)
  8.                 {
  9.                     _fftSpectrum = new byte[_controlInterface.FFTResolution];
  10.                 }
  11.                 _controlInterface.GetSpectrumSnapshot(_fftSpectrum);
  12.                 int bw = _controlInterface.FilterBandwidth;
  13.                 int rfbw = _controlInterface.RFBandwidth;
  14.                 long freq = _controlInterface.Frequency;
  15.                 long minFrequency = freq - (bw / 2);
  16.                 long maxFrequency = freq + (bw / 2);
  17.                 float peak = -120000; // testing
  18.                 float current = 0;
  19.                 float hzPerBin = (rfbw / _fftSpectrum.Length);
  20.                 for (long i = minFrequency; i <= maxFrequency; i = (i + (long)hzPerBin))
  21.                 {
  22.                     current = _fftSpectrum[convertFrequencyToBin(i)];
  23.                     if (current > peak)
  24.                     {
  25.                         peak = current;
  26.                     }
  27.                 }
  28.  
  29.                 return (float)Math.Round(-((130 / 255.0f) * (255 - peak)),1);
  30.             }
  31.         }
  32.  
  33.         private int convertFrequencyToBin(long frequency)
  34.         {
  35.             //converts frequency to fft bin
  36.             int bin = 0;
  37.             long center = _controlInterface.CenterFrequency;
  38.             int bandwidth = _controlInterface.RFBandwidth;
  39.             long minFrequency = center - (bandwidth / 2);
  40.             long maxFrequency = center + (bandwidth / 2);
  41.             if (frequency > minFrequency && frequency < maxFrequency)
  42.             {
  43.                 float hzPerBin = bandwidth / _controlInterface.FFTResolution;
  44.                 bin = (int)((frequency - minFrequency) / hzPerBin);
  45.             }
  46.             return bin;
  47.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement