Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private float getPeakSignal()
- {
- // attempts to determine the peak signal dB from the currently tuned frequency,
- // and within the currently defined filter bandwidth
- lock (_fftResolutionLockObject)
- {
- if (_fftSpectrum.Length != _controlInterface.FFTResolution)
- {
- _fftSpectrum = new byte[_controlInterface.FFTResolution];
- }
- _controlInterface.GetSpectrumSnapshot(_fftSpectrum);
- int bw = _controlInterface.FilterBandwidth;
- int rfbw = _controlInterface.RFBandwidth;
- long freq = _controlInterface.Frequency;
- long minFrequency = freq - (bw / 2);
- long maxFrequency = freq + (bw / 2);
- float peak = -120000; // testing
- float current = 0;
- float hzPerBin = (rfbw / _fftSpectrum.Length);
- for (long i = minFrequency; i <= maxFrequency; i = (i + (long)hzPerBin))
- {
- current = _fftSpectrum[convertFrequencyToBin(i)];
- if (current > peak)
- {
- peak = current;
- }
- }
- return (float)Math.Round(-((130 / 255.0f) * (255 - peak)),1);
- }
- }
- private int convertFrequencyToBin(long frequency)
- {
- //converts frequency to fft bin
- int bin = 0;
- long center = _controlInterface.CenterFrequency;
- int bandwidth = _controlInterface.RFBandwidth;
- long minFrequency = center - (bandwidth / 2);
- long maxFrequency = center + (bandwidth / 2);
- if (frequency > minFrequency && frequency < maxFrequency)
- {
- float hzPerBin = bandwidth / _controlInterface.FFTResolution;
- bin = (int)((frequency - minFrequency) / hzPerBin);
- }
- return bin;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement