Response.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2002 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Signal/General/dsp/Response.h
10 
11 #ifndef __Response_h
12 #define __Response_h
13 
14 #include <vector>
15 #include <complex>
16 #include <string>
17 
18 #include "dsp/Shape.h"
19 #include "Callback.h"
20 #include "Jones.h"
21 #include "Rational.h"
22 
23 namespace dsp {
24 
25  class Observation;
26  class OptimalFFT;
27 
29  class Response : public Shape {
30 
31  public:
32 
34  static unsigned ndat_max;
35 
37  Response();
38 
40  virtual ~Response ();
41 
43  Response (const Response&);
44 
46  const Response& operator = (const Response&);
47 
49  const Response& operator *= (const Response&);
50 
52  virtual void prepare (const Observation* input, unsigned channels=0);
53 
55  virtual void match (const Observation* input, unsigned channels=0);
56 
58  virtual void match (const Response* response);
59 
61  unsigned get_input_nchan () const { return input_nchan; }
62 
64  void set_input_nchan (unsigned _input_nchan) { input_nchan = _input_nchan; }
65 
67 
69  unsigned get_impulse_pos () const { return impulse_pos; }
70 
72 
74  unsigned get_impulse_neg () const { return impulse_neg; }
75 
77 
79  void set_impulse_pos (unsigned _impulse_pos) { impulse_pos =_impulse_pos; }
80 
82 
84  void set_impulse_neg (unsigned _impulse_neg) { impulse_neg =_impulse_neg; }
85 
87  virtual void set_dc_centred (bool dc_centred);
88 
90  bool get_dc_centred () const { return dc_centred; }
91 
93  virtual void set_swap (bool flag) { whole_swapped = flag; }
94 
96  bool get_swap () const { return whole_swapped; }
97 
99  unsigned get_minimum_ndat () const;
100 
102  void set_optimal_ndat ();
103 
105  void set_optimal_fft (OptimalFFT*);
106  OptimalFFT* get_optimal_fft () const;
107  bool has_optimal_fft () const;
108 
110  void check_ndat () const;
111 
113  std::vector<float> get_passband (unsigned ipol, int ichan=-1) const;
114 
116  void set (const std::vector<std::complex<float> >& phasors);
117 
119  void set (const std::vector<Jones<float> >& jones);
120 
122  void operate (float* spectrum, unsigned poln=0, int ichan=-1) const;
123 
125  void operate (float* spectrum, unsigned poln,
126  int ichan_start, unsigned nchan_op) const;
127 
129  void operate (float* input_spectrum, float * output_spectrum,
130  unsigned poln, int ichan_start, unsigned nchan_op) const;
131 
133  void operate (float* spectrum1, float* spectrum2, int ichan=-1) const;
134 
136  void integrate (float* spectrum, unsigned poln=0, int ichan=-1);
137 
139  void integrate (float* spectrum1, float* spectrum2, int ichan=-1);
140 
142  virtual bool matches (const Shape* response);
143 
145  virtual void mark (Observation* output);
146 
148  void naturalize ();
149 
151  virtual bool state_is_valid (std::string& reason) { return true; }
152 
155 
157  void flagswap (unsigned divisions = 1);
158 
160  float get_nbyte () const { return 0; }
161 
163  void check_finite (const char* name);
164 
165  protected:
166 
167  void calc_lcf (unsigned a, unsigned b, const Rational& osf, std::vector<unsigned>& result);
168 
169  void calc_oversampled_discard_region(
170  unsigned* _discard_neg,
171  unsigned* _discard_pos,
172  unsigned _nchan,
173  const Rational& osf);
174 
175  void calc_oversampled_fft_length(
176  unsigned* _fft_length,
177  unsigned _nchan,
178  const Rational& osf,
179  int direction=-1);
180 
181 
182  mutable unsigned step;
183 
184  Reference::To<OptimalFFT> optimal_fft;
185 
187  void doswap (unsigned divisions = 1);
188 
190  unsigned impulse_pos;
191 
193  unsigned impulse_neg;
194 
196  bool whole_swapped;
197 
199  unsigned swap_divisions;
200 
202  bool dc_centred;
203 
205  unsigned input_nchan;
206  };
207 
208 }
209 
210 #endif
virtual void set_swap(bool flag)
Set the flag for a band-swapped spectrum.
Definition: Response.h:98
bool whole_swapped
Toggled every time Response::doswap(1) is called (default: false)
Definition: Response.h:201
unsigned swap_divisions
Toggled every time Response::doswap(divisions > 1) is called.
Definition: Response.h:204
void set_optimal_fft(OptimalFFT *)
Set the policy used to compute the optimal FFT length.
Definition: Response.C:353
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
unsigned ndim
Dimension of each datum.
Definition: Shape.h:121
void set_impulse_pos(unsigned _impulse_pos)
Set the size of the positive half of the impulse response, .
Definition: Response.h:84
bool get_dc_centred() const
Get the flag for a bin-centred spectrum.
Definition: Response.h:95
Chooses the optimal FFT length for Filterbank and/or Convolution.
Definition: OptimalFFT.h:24
Callback< Response > changed
Called when the Response has been changed.
Definition: Response.h:159
Describes a frequency (or impulse) response.
Definition: Response.h:34
virtual void prepare(const Observation *input, unsigned channels=0)
Calculate the impulse_pos and impulse_neg attributes.
Definition: Response.C:131
Shape()
Default constructor.
Definition: Shape.C:34
void set_optimal_ndat()
Resize with ndat set to the optimal value.
Definition: Response.C:322
Response()
Default constructor.
Definition: Response.C:29
Represents a rational number.
Definition: Rational.h:15
unsigned get_minimum_ndat() const
Return the minimum useable ndat.
Definition: Response.C:299
virtual ~Response()
Destructor.
Definition: Response.C:44
unsigned npol
Number of polarizations.
Definition: Shape.h:112
float get_nbyte() const
Requires zero bytes per time sample.
Definition: Response.h:165
unsigned nchan
Number of frequency divisions (channels)
Definition: Shape.h:115
const Response & operator=(const Response &)
Assignment operator.
Definition: Response.C:56
Stores information about digital, band-limited, time-varying signals.
Definition: Observation.h:33
void integrate(float *spectrum, unsigned poln=0, int ichan=-1)
Integrate the power of spectrum into self.
Definition: Response.C:563
unsigned get_impulse_neg() const
Get the size of the negative half of the impulse response, .
Definition: Response.h:79
void doswap(unsigned divisions=1)
Swap halves of bandpass(es)
Definition: Response.C:758
virtual bool state_is_valid(std::string &reason)
Enable Response to be used in Transformation template.
Definition: Response.h:156
unsigned input_nchan
number of input channels. Used by some derived classes
Definition: Response.h:210
unsigned get_ndat() const
Get the number of datum in each of the nchan*npol divisions.
Definition: Shape.h:58
virtual bool matches(const Shape *response)
Returns true if the dimension and ordering match.
Definition: Response.C:220
void naturalize()
Re-organize frequency bins to reflect natural ordering (DC->Nyq)
Definition: Response.C:267
virtual void match(const Observation *input, unsigned channels=0)
Match the frequency response to the input Observation.
Definition: Response.C:154
virtual void set_dc_centred(bool dc_centred)
Set the flag for a bin-centred spectrum.
Definition: Response.C:262
static unsigned ndat_max
Maximum ndat allowed.
Definition: Response.h:39
unsigned get_nchan() const
Get the number of frequency channels.
Definition: Shape.h:55
void check_finite(const char *name)
Worker function checks that every value in response is finite.
Definition: Response.C:918
unsigned get_impulse_pos() const
Get the size of the positive half of the impulse response, .
Definition: Response.h:74
unsigned get_input_nchan() const
Get the number of input channels.
Definition: Response.h:66
Base class of objects that Shape data in the time or frequency domain.
Definition: Shape.h:28
unsigned impulse_pos
Complex time samples in t>0 half of corresponding impulse response.
Definition: Response.h:195
void set_input_nchan(unsigned _input_nchan)
Set the number of input channels.
Definition: Response.h:69
unsigned impulse_neg
Complex time samples in t<0 half of corresponding impulse response.
Definition: Response.h:198
unsigned ndat
Number of datum in each of the npol*nchan divisions.
Definition: Shape.h:118
void operate(float *spectrum, unsigned poln=0, int ichan=-1) const
Multiply spectrum by complex frequency response.
Definition: Response.C:416
void flagswap(unsigned divisions=1)
Set flags that response should be swapped.
Definition: Response.C:812
void set_impulse_neg(unsigned _impulse_neg)
Set the size of the negative half of the impulse response, .
Definition: Response.h:89
bool dc_centred
Toggled when built for a bin-centred spectrum.
Definition: Response.h:207
void check_ndat() const
Given impulse_pos and impulse_neg, check that ndat is large enough.
Definition: Response.C:368
const Response & operator*=(const Response &)
Multiplication operator.
Definition: Response.C:76
bool get_swap() const
Get the flag for a band-swapped spectrum.
Definition: Response.h:101
virtual void mark(Observation *output)
Modify the out Observation information as seen fit by sub-classes.
Definition: Response.C:256
std::vector< float > get_passband(unsigned ipol, int ichan=-1) const
Get the passband.
Definition: Response.C:387
void set(const std::vector< std::complex< float > > &phasors)
Construct frequency response from complex phasors.
Definition: Response.C:603

Generated using doxygen 1.8.17