summaryrefslogtreecommitdiff
path: root/gr-qtgui/src/lib/spectrumdisplayform.cc
diff options
context:
space:
mode:
authorTom Rondeau2010-05-10 19:47:02 -0400
committerTom Rondeau2010-05-10 19:47:02 -0400
commita45e2a94328fee03910e9dbfa04b48bf9ba15f61 (patch)
tree04193ce9bc144e4d3836f3fba49ead7a4d731c2e /gr-qtgui/src/lib/spectrumdisplayform.cc
parent8f1340102fa181a470dd5ec89a92bdb33dc3e288 (diff)
downloadgnuradio-a45e2a94328fee03910e9dbfa04b48bf9ba15f61.tar.gz
gnuradio-a45e2a94328fee03910e9dbfa04b48bf9ba15f61.tar.bz2
gnuradio-a45e2a94328fee03910e9dbfa04b48bf9ba15f61.zip
Remove one of the loop when posting new data; calculations are done the same time the fft shift and scaling operations happen.
Diffstat (limited to 'gr-qtgui/src/lib/spectrumdisplayform.cc')
-rw-r--r--gr-qtgui/src/lib/spectrumdisplayform.cc42
1 files changed, 24 insertions, 18 deletions
diff --git a/gr-qtgui/src/lib/spectrumdisplayform.cc b/gr-qtgui/src/lib/spectrumdisplayform.cc
index 91abbd36f..f52a63d1f 100644
--- a/gr-qtgui/src/lib/spectrumdisplayform.cc
+++ b/gr-qtgui/src/lib/spectrumdisplayform.cc
@@ -134,11 +134,24 @@ SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdate
const std::complex<float>* complexDataPointsPtr = complexDataPoints+numFFTDataPoints/2;
double* realFFTDataPointsPtr = _realFFTDataPoints;
+ double sumMean, localPeakAmplitude, localPeakFrequency;
+ const double fftBinSize = (_stopFrequency-_startFrequency) /
+ static_cast<double>(numFFTDataPoints);
+ localPeakAmplitude = -HUGE_VAL;
+ sumMean = 0.0;
+
// Run this twice to perform the fftshift operation on the data here as well
+ std::complex<float> scaleFactor = std::complex<float>((float)numFFTDataPoints);
for(uint64_t point = 0; point < numFFTDataPoints/2; point++){
- std::complex<float> pt = (*complexDataPointsPtr) / (float)numFFTDataPoints;
+ std::complex<float> pt = (*complexDataPointsPtr) / scaleFactor;
*realFFTDataPointsPtr = 10.0*log10((pt.real() * pt.real() + pt.imag()*pt.imag()) + 1e-20);
+ if(*realFFTDataPointsPtr > localPeakAmplitude) {
+ localPeakFrequency = static_cast<float>(point) * fftBinSize;
+ localPeakAmplitude = *realFFTDataPointsPtr;
+ }
+ sumMean += *realFFTDataPointsPtr;
+
complexDataPointsPtr++;
realFFTDataPointsPtr++;
}
@@ -147,9 +160,15 @@ SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdate
// second half of the plotted data
complexDataPointsPtr = complexDataPoints;
for(uint64_t point = 0; point < numFFTDataPoints/2; point++){
- std::complex<float> pt = (*complexDataPointsPtr) / (float)numFFTDataPoints;
+ std::complex<float> pt = (*complexDataPointsPtr) / scaleFactor;
*realFFTDataPointsPtr = 10.0*log10((pt.real() * pt.real() + pt.imag()*pt.imag()) + 1e-20);
+ if(*realFFTDataPointsPtr > localPeakAmplitude) {
+ localPeakFrequency = static_cast<float>(point) * fftBinSize;
+ localPeakAmplitude = *realFFTDataPointsPtr;
+ }
+ sumMean += *realFFTDataPointsPtr;
+
complexDataPointsPtr++;
realFFTDataPointsPtr++;
}
@@ -158,22 +177,9 @@ SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdate
if(!repeatDataFlag){
_AverageHistory(_realFFTDataPoints);
- double sumMean;
- const double fft_bin_size = (_stopFrequency-_startFrequency) /
- static_cast<double>(numFFTDataPoints);
-
- // find the peak, sum (for mean), etc
- _peakAmplitude = -HUGE_VAL;
- sumMean = 0.0;
- for(uint64_t number = 0; number < numFFTDataPoints; number++){
- // find peak
- if(_realFFTDataPoints[number] > _peakAmplitude){
- // Calculate the frequency relative to the local bw, adjust for _startFrequency later
- _peakFrequency = (static_cast<float>(number) * fft_bin_size);
- _peakAmplitude = _realFFTDataPoints[number];
- }
- sumMean += _realFFTDataPoints[number];
- }
+ // Only use the local info if we are not repeating data
+ _peakAmplitude = localPeakAmplitude;
+ _peakFrequency = localPeakFrequency;
// calculate the spectral mean
// +20 because for the comparison below we only want to throw out bins