protected:
virtual QwtText trackerText( const QwtDoublePoint& p ) const
{
- QwtText t(QString("%1 %2, %3 dB").arg(p.x(), 0, 'f', GetFrequencyPrecision()).arg( (GetFrequencyPrecision() == 0) ? "Hz" : "kHz").arg(p.y(), 0, 'f', 2));
+ QString strunits = (GetFrequencyPrecision() == 0) ? "Hz" : "kHz";
+ QwtText t(QString("%1 %2, %3 dB").arg(p.x(), 0, 'f',
+ GetFrequencyPrecision()).arg(strunits).arg(p.y(), 0, 'f', 2));
return t;
}
_stopFrequency = stopFreq;
_resetXAxisPoints();
+ double display_units = ceil(log10(units)/2.0);
setAxisScale(QwtPlot::xBottom, _startFrequency, _stopFrequency);
- setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(2));
+ setAxisScaleDraw(QwtPlot::xBottom, new FreqDisplayScaleDraw(display_units));
setAxisTitle(QwtPlot::xBottom, QString("Frequency (%1)").arg(strunits.c_str()));
- ((FreqDisplayZoomer*)_zoomer)->SetFrequencyPrecision(2);
+ ((FreqDisplayZoomer*)_zoomer)->SetFrequencyPrecision(display_units);
// Load up the new base zoom settings
_zoomer->setZoomBase();
ClearMaxData();
ClearMinData();
}
+
memcpy(_dataPoints, dataPoints, numDataPoints*sizeof(double));
for(int64_t point = 0; point < numDataPoints; point++){
if(dataPoints[point] < _minFFTPoints[point]){
FrequencyDisplayPlot::ClearMaxData()
{
for(int64_t number = 0; number < _numPoints; number++){
- _maxFFTPoints[number] = _maxYAxis;
+ _maxFFTPoints[number] = _minYAxis;
}
}
FrequencyDisplayPlot::ClearMinData()
{
for(int64_t number = 0; number < _numPoints; number++){
- _minFFTPoints[number] = _minYAxis;
+ _minFFTPoints[number] = _maxYAxis;
}
}
_startFrequency = newStartFrequency;
_stopFrequency = newStopFrequency;
-#warning SPECIFY THIS LATER...
_windowType = 5;
timespec_reset(&_lastGUIUpdateTime);
_imagDataPoints = new double[_numPoints];
_xAxisPoints = new double[_numPoints];
+ _zoomer = new TimeDomainDisplayZoomer(canvas());
+
// Disable polygon clipping
QwtPainter::setDeviceClipping(false);
canvas()->setPalette(palette);
setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
- setAxisScale(QwtPlot::xBottom, 0, _numPoints);
+ set_xaxis(0, _numPoints);
setAxisTitle(QwtPlot::xBottom, "Sample Number");
setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
replot();
- _zoomer = new TimeDomainDisplayZoomer(canvas());
#if QT_VERSION < 0x040000
_zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);
TimeDomainDisplayPlot::set_yaxis(double min, double max)
{
setAxisScale(QwtPlot::yLeft, min, max);
+ _zoomer->setZoomBase();
+}
+
+void
+TimeDomainDisplayPlot::set_xaxis(double min, double max)
+{
+ setAxisScale(QwtPlot::xBottom, min, max);
+ _zoomer->setZoomBase();
}
+
void TimeDomainDisplayPlot::replot(){
const timespec startTime = get_highres_clock();
}
}
-void TimeDomainDisplayPlot::PlotNewData(const double* realDataPoints, const double* imagDataPoints, const int64_t numDataPoints){
+void TimeDomainDisplayPlot::PlotNewData(const double* realDataPoints,
+ const double* imagDataPoints,
+ const int64_t numDataPoints){
if(numDataPoints > 0){
if(numDataPoints != _numPoints){
_real_plot_curve->setRawData(_xAxisPoints, _realDataPoints, _numPoints);
_imag_plot_curve->setRawData(_xAxisPoints, _imagDataPoints, _numPoints);
+ set_xaxis(0, numDataPoints);
+
_resetXAxisPoints();
}
memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double));
virtual void replot();
void set_yaxis(double min, double max);
+ void set_xaxis(double min, double max);
protected slots:
void LegendEntryChecked(QwtPlotItem *plotItem, bool on);
d_fft = new gri_fft_complex (d_fftsize, true);
- d_fftdata = new gr_complex[d_fftsize];
-
d_index = 0;
d_residbuf = new gr_complex[d_fftsize];
qtgui_sink_c::~qtgui_sink_c()
{
delete d_object;
- delete [] d_fftdata;
delete [] d_residbuf;
delete d_fft;
}
+void
+qtgui_sink_c::forecast(int noutput_items, gr_vector_int &ninput_items_required)
+{
+ unsigned int ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = std::min(d_fftsize, 8191);
+ }
+}
+
void qtgui_sink_c::lock()
{
pthread_mutex_lock(&d_pmutex);
}
void
-qtgui_sink_c::fft(const gr_complex *data_in, int size, gr_complex *data_out)
+qtgui_sink_c::fft(const gr_complex *data_in, int size)
{
if (d_window.size()) {
gr_complex *dst = d_fft->get_inbuf();
}
d_fft->execute (); // compute the fft
-
- for(int i=0; i < size; i++) {
- d_fft->get_outbuf()[i] /= size;
- }
-
- // copy result to our output
- if(d_shift) { // apply a fft shift on the data
- unsigned int len = (unsigned int)(ceil(size/2.0));
- memcpy(&data_out[0], &d_fft->get_outbuf()[len], sizeof(gr_complex)*(size - len));
- memcpy(&data_out[size - len], &d_fft->get_outbuf()[0], sizeof(gr_complex)*len);
- }
- else {
- memcpy(data_out, d_fft->get_outbuf(), sizeof(gr_complex)*size);
- }
}
void
if(newfftsize != d_fftsize) {
- // Resize the fftdata buffer; no need to preserve old data
- delete [] d_fftdata;
- d_fftdata = new gr_complex[newfftsize];
-
// Resize residbuf and replace data
delete [] d_residbuf;
d_residbuf = new gr_complex[newfftsize];
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
- int i=0, j=0;
+ int j=0;
const gr_complex *in = (const gr_complex*)input_items[0];
pthread_mutex_lock(&d_pmutex);
// Update the FFT size from the application
fftresize();
windowreset();
-
- const timespec currentTime = get_highres_clock();
- const timespec lastUpdateGUITime = d_main_gui->GetLastGUIUpdateTime();
- if(diff_timespec(currentTime, lastUpdateGUITime) > 0.05) {
+ for(int i=0; i < noutput_items; i+=d_fftsize) {
+ unsigned int datasize = noutput_items - i;
+ unsigned int resid = d_fftsize-d_index;
- if(d_index) {
- int filler = std::min(d_fftsize - d_index, noutput_items);
+ // If we have enough input for one full FFT, do it
+ if(datasize >= resid) {
+ const timespec currentTime = get_highres_clock();
- memcpy(&d_residbuf[d_index], &in[0], sizeof(gr_complex)*filler);
- d_index += filler;
- i = filler;
- j = filler;
- }
-
- if(d_index == d_fftsize) {
+ // Fill up residbuf with d_fftsize number of items
+ memcpy(d_residbuf+d_index, &in[j], sizeof(gr_complex)*resid);
d_index = 0;
- fft(d_residbuf, d_fftsize, d_fftdata);
+
+ j += resid;
+ fft(d_residbuf, d_fftsize);
- d_main_gui->UpdateWindow(true, d_fftdata, d_fftsize, NULL, 0,
- (float*)d_residbuf, d_fftsize,
- 1.0/4.0, convert_to_timespec(0.0), true);
- }
-
- for(; i < noutput_items; i+=d_fftsize) {
- if(noutput_items - i > d_fftsize) {
- j += d_fftsize;
- fft(&in[i], d_fftsize, d_fftdata);
-
- d_main_gui->UpdateWindow(true, d_fftdata, d_fftsize, NULL, 0,
- (float*)&in[i], d_fftsize,
- 1.0/4.0, convert_to_timespec(0.0), true);
- }
- }
-
- if(noutput_items > j) {
- d_index = noutput_items - j;
- memcpy(d_residbuf, &in[j], sizeof(gr_complex)*d_index);
+ d_main_gui->UpdateWindow(true, d_fft->get_outbuf(), d_fftsize,
+ NULL, 0, (float*)d_residbuf, d_fftsize,
+ 1.0/4.0, currentTime, true);
}
+ // Otherwise, copy what we received into the residbuf for next time
+ else {
+ memcpy(d_residbuf+d_index, &in[j], sizeof(gr_complex)*datasize);
+ d_index += datasize;
+ j += datasize;
+ }
}
pthread_mutex_unlock(&d_pmutex);
- consume_each(noutput_items);
- return noutput_items;
+ consume_each(j);
+ return j;
}
bool use_openGL,
QWidget *parent);
+ void forecast(int noutput_items, gr_vector_int &ninput_items_required);
+
// use opengl to force OpenGL on or off
// this might be necessary for sessions over SSH
void initialize(const bool opengl=true);
bool d_shift;
gri_fft_complex *d_fft;
- gr_complex *d_fftdata;
int d_index;
gr_complex *d_residbuf;
void windowreset();
void buildwindow();
void fftresize();
- void fft(const gr_complex *data_in, int size, gr_complex *data_out);
+ void fft(const gr_complex *data_in, int size);
public:
~qtgui_sink_c();
d_fft = new gri_fft_complex (d_fftsize, true);
- d_fftdata = new gr_complex[d_fftsize];
-
d_index = 0;
d_residbuf = new float[d_fftsize];
qtgui_sink_f::~qtgui_sink_f()
{
delete d_object;
- delete [] d_fftdata;
delete [] d_residbuf;
delete d_fft;
}
+void
+qtgui_sink_f::forecast(int noutput_items, gr_vector_int &ninput_items_required)
+{
+ unsigned int ninputs = ninput_items_required.size();
+ for (unsigned int i = 0; i < ninputs; i++) {
+ ninput_items_required[i] = std::min(d_fftsize, 8191);
+ }
+}
+
void qtgui_sink_f::lock()
{
pthread_mutex_lock(&d_pmutex);
}
void
-qtgui_sink_f::fft(const float *data_in, int size, gr_complex *data_out)
+qtgui_sink_f::fft(const float *data_in, int size)
{
if (d_window.size()) {
gr_complex *dst = d_fft->get_inbuf();
}
d_fft->execute (); // compute the fft
-
- for(int i=0; i < size; i++) {
- d_fft->get_outbuf()[i] /= size;
- }
-
- // copy result to our output
- if(d_shift) { // apply a fft shift on the data
- unsigned int len = (unsigned int)(ceil(size/2.0));
- memcpy(&data_out[0], &d_fft->get_outbuf()[len], sizeof(gr_complex)*(size - len));
- memcpy(&data_out[size - len], &d_fft->get_outbuf()[0], sizeof(gr_complex)*len);
- }
- else {
- memcpy(data_out, d_fft->get_outbuf(), sizeof(gr_complex)*size);
- }
}
void
if(newfftsize != d_fftsize) {
- // Resize the fftdata buffer; no need to preserve old data
- delete [] d_fftdata;
- d_fftdata = new gr_complex[newfftsize];
-
// Resize residbuf and replace data
delete [] d_residbuf;
d_residbuf = new float[newfftsize];
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
- int i=0, j=0;
+ int j=0;
const float *in = (const float*)input_items[0];
pthread_mutex_lock(&d_pmutex);
- if(d_index) {
- int filler = std::min(d_fftsize - d_index, noutput_items);
- memcpy(&d_residbuf[d_index], &in[0], sizeof(float)*filler);
- d_index += filler;
- i = filler;
- j = filler;
- }
+ // Update the FFT size from the application
+ fftresize();
+ windowreset();
- if(d_index == d_fftsize) {
- d_index = 0;
- fft(d_residbuf, d_fftsize, d_fftdata);
-
- d_main_gui->UpdateWindow(true, d_fftdata, d_fftsize,
- d_residbuf, d_fftsize, NULL, 0,
- 1.0/4.0, convert_to_timespec(0.0), true);
- }
-
- for(; i < noutput_items; i+=d_fftsize) {
- if(noutput_items - i > d_fftsize) {
- j += d_fftsize;
- fft(&in[i], d_fftsize, d_fftdata);
+ for(int i=0; i < noutput_items; i+=d_fftsize) {
+ unsigned int datasize = noutput_items - i;
+ unsigned int resid = d_fftsize-d_index;
+
+ // If we have enough input for one full FFT, do it
+ if(datasize >= resid) {
+ const timespec currentTime = get_highres_clock();
- d_main_gui->UpdateWindow(true, d_fftdata, d_fftsize, &in[i],
- d_fftsize, NULL, 0, 1.0/4.0,
- convert_to_timespec(0.0), true);
- }
- }
+ // Fill up residbuf with d_fftsize number of items
+ memcpy(d_residbuf+d_index, &in[j], sizeof(float)*resid);
+ d_index = 0;
- if(noutput_items > j) {
- d_index = noutput_items - j;
- memcpy(d_residbuf, &in[j], sizeof(float)*d_index);
+ j += resid;
+ fft(d_residbuf, d_fftsize);
+
+ d_main_gui->UpdateWindow(true, d_fft->get_outbuf(), d_fftsize,
+ (float*)d_residbuf, d_fftsize, NULL, 0,
+ 1.0/4.0, currentTime, true);
+ }
+ // Otherwise, copy what we received into the residbuf for next time
+ else {
+ memcpy(d_residbuf+d_index, &in[j], sizeof(float)*datasize);
+ d_index += datasize;
+ j += datasize;
+ }
}
pthread_mutex_unlock(&d_pmutex);
- consume_each(noutput_items);
- return noutput_items;
+ consume_each(j);
+ return j;
}
bool use_openGL,
QWidget *parent);
+ void forecast(int noutput_items, gr_vector_int &ninput_items_required);
+
void initialize(const bool opengl=true);
int d_fftsize;
bool d_shift;
gri_fft_complex *d_fft;
- gr_complex *d_fftdata;
int d_index;
float *d_residbuf;
void windowreset();
void buildwindow();
void fftresize();
- void fft(const float *data_in, int size, gr_complex *data_out);
+ void fft(const float *data_in, int size);
public:
~qtgui_sink_f();
void
SpectrumDisplayForm::newFrequencyData( const SpectrumUpdateEvent* spectrumUpdateEvent)
{
+ //_lastSpectrumEvent = (SpectrumUpdateEvent)(*spectrumUpdateEvent);
const std::complex<float>* complexDataPoints = spectrumUpdateEvent->getFFTPoints();
const uint64_t numFFTDataPoints = spectrumUpdateEvent->getNumFFTDataPoints();
const double* realTimeDomainDataPoints = spectrumUpdateEvent->getRealTimeDomainPoints();
ResizeBuffers(numFFTDataPoints, numTimeDomainDataPoints);
// Calculate the Magnitude of the complex point
- const std::complex<float>* complexDataPointsPtr = complexDataPoints;
+ const std::complex<float>* complexDataPointsPtr = complexDataPoints+numFFTDataPoints/2;
double* realFFTDataPointsPtr = _realFFTDataPoints;
- for(uint64_t point = 0; point < numFFTDataPoints; point++){
+
+ // Run this twice to perform the fftshift operation on the data here as well
+ for(uint64_t point = 0; point < numFFTDataPoints/2; point++){
// Calculate dBm
// 50 ohm load assumption
// 10 * log10 (v^2 / (2 * 50.0 * .001)) = 10 * log10( v^2 * 10)
// 75 ohm load assumption
// 10 * log10 (v^2 / (2 * 75.0 * .001)) = 10 * log10( v^2 * 15)
-
- *realFFTDataPointsPtr = 10.0*log10((((*complexDataPointsPtr).real() * (*complexDataPointsPtr).real()) +
- ((*complexDataPointsPtr).imag()*(*complexDataPointsPtr).imag())) + 1e-20);
+
+ // perform scaling here
+ std::complex<float> pt = (*complexDataPointsPtr) / std::complex<float>((float)numFFTDataPoints);
+ *realFFTDataPointsPtr = 10.0*log10((pt.real() * pt.real() + pt.imag()*pt.imag()) + 1e-20);
+
+ complexDataPointsPtr++;
+ realFFTDataPointsPtr++;
+ }
+
+ // This loop takes the first half of the input data and puts it in the second half of the plotted data
+ complexDataPointsPtr = complexDataPoints;
+ for(uint64_t point = 0; point < numFFTDataPoints/2; point++){
+ std::complex<float> pt = (*complexDataPointsPtr) / std::complex<float>((float)numFFTDataPoints);
+ *realFFTDataPointsPtr = 10.0*log10((pt.real() * pt.real() + pt.imag()*pt.imag()) + 1e-20);
complexDataPointsPtr++;
realFFTDataPointsPtr++;
}
-
- int tabindex = SpectrumTypeTab->currentIndex();
// Don't update the averaging history if this is repeated data
if(!repeatDataFlag){
for(uint64_t number = 0; number < numFFTDataPoints; number++){
// find peak
if(_realFFTDataPoints[number] > _peakAmplitude){
- _peakFrequency = (static_cast<float>(number) * fft_bin_size); // Calculate the frequency relative to the local bw, adjust for _startFrequency later
+ // Calculate the frequency relative to the local bw, adjust for _startFrequency later
+ _peakFrequency = (static_cast<float>(number) * fft_bin_size);
_peakAmplitude = _realFFTDataPoints[number];
// _peakBin = number;
}
}
if(lastOfMultipleUpdatesFlag){
+ int tabindex = SpectrumTypeTab->currentIndex();
if(tabindex == d_plot_fft) {
_frequencyDisplayPlot->PlotNewData(_averagedValues, numFFTDataPoints,
_noiseFloorAmplitude, _peakFrequency,
}
}
+
// Tell the system the GUI has been updated
if(_systemSpecifiedFlag){
_system->SetLastGUIUpdateTime(generatedTimestamp);
}
+void
+SpectrumDisplayForm::TabChanged(int index)
+{
+ _frequencyDisplayPlot->replot();
+
+}
+
void
SpectrumDisplayForm::PowerLineEdit_textChanged( const QString &valueString )
{
void MinHoldCheckBox_toggled( bool newState );
void MinHoldResetBtn_clicked();
void MaxHoldResetBtn_clicked();
+ void TabChanged(int index);
+
void PowerLineEdit_textChanged( const QString& valueString );
void SetFrequencyRange( const double newCenterFrequency,
const double newStartFrequency,
double _peakAmplitude;
static int _openGLWaterfall3DFlag;
double _stopFrequency;
-
+
+ //SpectrumUpdateEvent _lastSpectrumEvent;
+
// whether or not to use a particular display
int d_plot_fft;
int d_plot_waterfall;
<slot>MaxHoldCheckBox_toggled(bool)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>22</x>
+ <y>324</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>MaxHoldResetBtn_clicked()</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>107</x>
+ <y>324</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>MinHoldCheckBox_toggled(bool)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>22</x>
+ <y>349</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>MinHoldResetBtn_clicked()</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>107</x>
+ <y>349</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>AvgLineEdit_textChanged(QString)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>552</x>
+ <y>344</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>PowerLineEdit_textChanged(QString)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>482</x>
+ <y>344</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>waterfallMaximumIntensityChangedCB(double)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>217</x>
+ <y>44</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>waterfallMinimumIntensityChangedCB(double)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>217</x>
+ <y>349</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>waterfall3DMaximumIntensityChangedCB(double)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>217</x>
+ <y>44</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>waterfall3DMinimumIntensityChangedCB(double)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>217</x>
+ <y>349</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>WaterfallAutoScaleBtnCB()</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>22</x>
+ <y>349</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>Waterfall3DAutoScaleBtnCB()</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>22</x>
+ <y>349</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>WaterfallIntensityColorTypeChanged(int)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>92</x>
+ <y>44</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
<slot>Waterfall3DIntensityColorTypeChanged(int)</slot>
<hints>
<hint type="sourcelabel" >
- <x>20</x>
- <y>20</y>
+ <x>92</x>
+ <y>44</y>
</hint>
<hint type="destinationlabel" >
<x>20</x>
</hint>
</hints>
</connection>
+ <connection>
+ <sender>SpectrumTypeTab</sender>
+ <signal>currentChanged(int)</signal>
+ <receiver>SpectrumDisplayForm</receiver>
+ <slot>TabChanged(int)</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>314</x>
+ <y>189</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>316</x>
+ <y>217</y>
+ </hint>
+ </hints>
+ </connection>
</connections>
</ui>