Home
Install
Use
Develop
Support
News
Credits
hosted by
|
11 #ifndef __fft_BandpassPlotter_h
12 #define __fft_BandpassPlotter_h
14 #include "templates.h"
22 template< class Data, class Info>
23 class BandpassPlotter {
30 user_max = user_min = 0;
31 user_fmax = user_fmin = 0;
33 ignore_fraction = 0.0;
39 title = "Original Bandpass";
43 virtual ~BandpassPlotter() { }
46 virtual void plot (Data* data, Info* info) const;
50 void plot (std::vector< std::vector<T> >& data, double timespan, Info* info) const;
53 virtual void preprocess (std::vector<float>& bandpass) const { }
56 void set_minmax ( float min, float max)
57 { user_min = min; user_max = max; }
60 void set_fminmax ( float min, float max)
62 if (!myfinite(min) || !myfinite(max))
63 throw Error (InvalidParam, "BandpassPlotter::set_fminmax", "min=%f max=%f", min, max);
69 float ignore_fraction;
83 float user_min, user_max;
84 float user_fmin, user_fmax;
90 void log (std::vector<float>& data)
92 for ( unsigned i=0; i<data.size(); i++)
94 data[i] = log10 (data[i]);
99 template< class Data, class Info>
100 void fft::BandpassPlotter<Data,Info>::plot (Data* data, Info* info) const
102 unsigned ipol, npol = data->get_npol ();
107 for (ipol=0; ipol<npol; ipol++)
109 std::vector<float> pband = data->get_passband (ipol);
111 this->preprocess (pband);
116 nchan = pband.size();
118 minmax (pband, min, max, ipol);
121 if (user_min != user_max)
127 double freq = info->get_centre_frequency();
128 double bw = info->get_bandwidth();
130 double fmin = freq - bw/2;
131 double fmax = freq + bw/2;
133 std::string xlabel = "Frequency (MHz)";
139 xlabel = "Frequency channel";
145 if (user_fmin != user_fmax)
147 std::cerr << "BandpassPlotter set min=" << user_fmin << " max=" << user_fmax << std::endl;
152 float fbuf = fabs(0.05 * ( wfmax - wfmin ));
155 cpgswin (wfmin-fbuf, wfmax+fbuf, min, max);
159 for ( unsigned ipol=0; ipol<npol; ipol++)
161 std::vector<float> pband = data->get_passband (ipol);
162 this->preprocess (pband);
168 double fstep = bw/(nchan-1);
174 std::vector<float> xaxis (nchan);
179 for ( unsigned ichan=0; ichan<nchan; ichan++)
180 xaxis[ichan] = fmin + (ichan+offset)*fstep;
182 float* x = &xaxis[0];
183 float* y = &pband[0];
186 cpgbin (nchan, x, y, true);
188 cpgline (nchan, x, y);
195 cpgbox( "BCNST", 0.0, 0, "BCNSTL2", 0.0, 0);
196 cpglab(xlabel.c_str(), "Logarithmic Scale", title.c_str());
200 cpgbox( "BCNST", 0.0, 0, "BCNST", 0.0, 0);
201 cpglab(xlabel.c_str(), "Linear Scale", title.c_str());
206 template< class Data, class Info>
208 void fft::BandpassPlotter<Data,Info>::plot (std::vector< std::vector<T> >& data,
209 double timespan, Info* info) const
211 unsigned ntime = data.size();
212 unsigned nchan = data[0].size();
214 std::vector<float> plotarray (ntime * nchan);
221 unsigned ignore_ichan = (unsigned) (ignore_fraction * nchan);
223 for ( unsigned itime=0; itime<ntime; itime++) {
224 std::vector<float>& pband = data[itime];
225 this->preprocess (pband);
227 minmax (pband.begin()+ignore_ichan, pband.end()-ignore_ichan,
230 for ( unsigned ichan=0; ichan<nchan; ichan++)
231 plotarray[ichan+jchan] = pband[ichan];
237 float diff = max - min;
245 double freq = info->get_centre_frequency();
246 double bw = info->get_bandwidth();
248 double fmin = freq - bw/2;
249 double fmax = freq + bw/2;
252 cpgswin(fmin, fmax, 0, timespan);
253 cpgbox( "BCNST", 0.0, 0, "BCNST", 0.0, 0);
254 cpglab( "Frequency (MHz)", "Time (s)", "Dynamic Spectrum");
256 float fstep = bw/nchan;
257 float tstep = timespan/ntime;
260 float offset_fmin = fmin - 0.5*fstep;
261 float offset_tmin = tmin - 0.5*tstep;
262 float trf[6] = {offset_fmin, fstep, 0.0,
263 offset_tmin, 0.0, tstep};
265 cpgimag(&plotarray[0], nchan, ntime, 1, nchan, 1, ntime, min, max, trf);
const ScalarMath log(const ScalarMath &x)
Generated using doxygen 1.8.17
|