1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008-2011 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef FREQUENCY_DISPLAY_PLOT_HPP
24 #define FREQUENCY_DISPLAY_PLOT_HPP
25 
26 #include <gnuradio/qtgui/DisplayPlot.h>
27 #include <stdint.h>
28 #include <cstdio>
29 #include <vector>
30 
31 /*!
32  * \brief QWidget for displaying frequency domain (PSD) plots.
33  * \ingroup qtgui_blk
34  */
35 class FrequencyDisplayPlot : public DisplayPlot
36 {
37     Q_OBJECT
38 
39     Q_PROPERTY(QColor min_fft_color READ getMinFFTColor WRITE setMinFFTColor)
40     Q_PROPERTY(QColor max_fft_color READ getMaxFFTColor WRITE setMaxFFTColor)
41     Q_PROPERTY(bool min_fft_visible READ getMinFFTVisible WRITE setMinFFTVisible)
42     Q_PROPERTY(bool max_fft_visible READ getMaxFFTVisible WRITE setMaxFFTVisible)
43     Q_PROPERTY(QColor marker_lower_intensity_color READ getMarkerLowerIntensityColor WRITE
44                    setMarkerLowerIntensityColor)
45     Q_PROPERTY(bool marker_lower_intensity_visible READ getMarkerLowerIntensityVisible
46                    WRITE setMarkerLowerIntensityVisible)
47     Q_PROPERTY(QColor marker_upper_intensity_color READ getMarkerUpperIntensityColor WRITE
48                    setMarkerUpperIntensityColor)
49     Q_PROPERTY(bool marker_upper_intensity_visible READ getMarkerUpperIntensityVisible
50                    WRITE setMarkerUpperIntensityVisible)
51     Q_PROPERTY(QColor marker_peak_amplitude_color READ getMarkerPeakAmplitudeColor WRITE
52                    setMarkerPeakAmplitudeColor)
53     Q_PROPERTY(
54         QColor marker_noise_floor_amplitude_color READ getMarkerNoiseFloorAmplitudeColor
55             WRITE setMarkerNoiseFloorAmplitudeColor)
56     Q_PROPERTY(
57         bool marker_noise_floor_amplitude_visible READ getMarkerNoiseFloorAmplitudeVisible
58             WRITE setMarkerNoiseFloorAmplitudeVisible)
59     Q_PROPERTY(QColor marker_CF_color READ getMarkerCFColor WRITE setMarkerCFColor)
60 
61 public:
62     FrequencyDisplayPlot(int nplots, QWidget*);
63     virtual ~FrequencyDisplayPlot();
64 
65     void setFrequencyRange(const double,
66                            const double,
67                            const double units = 1000.0,
68                            const std::string& strunits = "kHz");
69     double getStartFrequency() const;
70     double getStopFrequency() const;
71 
72     void plotNewData(const std::vector<double*> dataPoints,
73                      const int64_t numDataPoints,
74                      const double noiseFloorAmplitude,
75                      const double peakFrequency,
76                      const double peakAmplitude,
77                      const double timeInterval);
78 
79     // Old method to be removed
80     void plotNewData(const double* dataPoints,
81                      const int64_t numDataPoints,
82                      const double noiseFloorAmplitude,
83                      const double peakFrequency,
84                      const double peakAmplitude,
85                      const double timeInterval);
86 
87     void replot();
88 
89     void setYaxis(double min, double max);
90     double getYMin() const;
91     double getYMax() const;
92 
93     void setTraceColour(QColor);
94     void setBGColour(QColor c);
95     void showCFMarker(const bool);
96 
97     const bool getMaxFFTVisible() const;
98     const bool getMinFFTVisible() const;
99     const QColor getMinFFTColor() const;
100     const QColor getMaxFFTColor() const;
101     const QColor getMarkerLowerIntensityColor() const;
102     const bool getMarkerLowerIntensityVisible() const;
103     const QColor getMarkerUpperIntensityColor() const;
104     const bool getMarkerUpperIntensityVisible() const;
105     const QColor getMarkerPeakAmplitudeColor() const;
106     const bool getMarkerNoiseFloorAmplitudeVisible() const;
107     const QColor getMarkerNoiseFloorAmplitudeColor() const;
108     const QColor getMarkerCFColor() const;
109 
110 public slots:
111     void setMaxFFTVisible(const bool);
112     void setMinFFTVisible(const bool);
113     void setMinFFTColor(QColor c);
114     void setMaxFFTColor(QColor c);
115     void setMarkerLowerIntensityColor(QColor c);
116     void setMarkerLowerIntensityVisible(bool visible);
117     void setMarkerUpperIntensityColor(QColor c);
118     void setMarkerUpperIntensityVisible(bool visible);
119     void setMarkerPeakAmplitudeColor(QColor c);
120     void setMarkerNoiseFloorAmplitudeVisible(bool visible);
121     void setMarkerNoiseFloorAmplitudeColor(QColor c);
122     void setMarkerCFColor(QColor c);
123 
124     void setLowerIntensityLevel(const double);
125     void setUpperIntensityLevel(const double);
126 
127     void onPickerPointSelected(const QwtDoublePoint& p);
128     void onPickerPointSelected6(const QPointF& p);
129 
130     void setAutoScale(bool state);
131     void setAutoScaleShot();
132 
133     void setPlotPosHalf(bool half);
134 
135     void setYLabel(const std::string& label, const std::string& unit);
136 
137     void clearMaxData();
138     void clearMinData();
139 
140     void attachTriggerLine(bool en);
141     void setTriggerLine(double value);
142 
143 private:
144     void _resetXAxisPoints();
145     void _autoScale(double bottom, double top);
146 
147     std::vector<double*> d_ydata;
148 
149     QwtPlotCurve* d_min_fft_plot_curve;
150     QwtPlotCurve* d_max_fft_plot_curve;
151     QColor d_min_fft_color;
152     bool d_min_fft_visible;
153     QColor d_max_fft_color;
154     bool d_max_fft_visible;
155     QColor d_marker_lower_intensity_color;
156     bool d_marker_lower_intensity_visible;
157     QColor d_marker_upper_intensity_color;
158     bool d_marker_upper_intensity_visible;
159     QColor d_marker_peak_amplitude_color;
160     QColor d_marker_noise_floor_amplitude_color;
161     bool d_marker_noise_floor_amplitude_visible;
162     QColor d_marker_cf_color;
163 
164     double d_start_frequency;
165     double d_stop_frequency;
166     double d_center_frequency;
167     double d_ymax;
168     double d_ymin;
169     bool d_half_freq;
170 
171     QwtPlotMarker* d_lower_intensity_marker;
172     QwtPlotMarker* d_upper_intensity_marker;
173 
174     QwtPlotMarker* d_marker_peak_amplitude;
175     QwtPlotMarker* d_marker_noise_floor_amplitude;
176     QwtPlotMarker* d_marker_cf;
177 
178     double* d_xdata;
179     int d_xdata_multiplier;
180 
181     double* d_min_fft_data;
182     double* d_max_fft_data;
183 
184     double d_peak_frequency;
185     double d_peak_amplitude;
186 
187     double d_noise_floor_amplitude;
188 
189     bool d_autoscale_shot;
190 
191     QwtPlotMarker* d_trigger_line;
192 };
193 
194 #endif /* FREQUENCY_DISPLAY_PLOT_HPP */
195