Apodization.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 #ifndef __Apodization_h
10 #define __Apodization_h
11 
12 #include <map>
13 #include <string>
14 
15 #include "dsp/Shape.h"
16 
17 namespace dsp {
18 
20  /* The Apodization class implements apodizing functions that may be used
21  in the time domain before performing an FFT, in order to improve
22  the spectral leakage characteristics */
23  class Apodization : public Shape
24  {
25 
26  public:
27 
28  enum Type { none, hanning, welch, bartlett, tukey, top_hat };
29 
31  Apodization();
32 
34  void set_type (const std::string&);
35 
37  void set_analytic (bool f = true) { analytic = f; }
38  bool get_analytic () const { return analytic; }
39 
41  void set_size (unsigned);
42 
44  void set_transition_start (unsigned n) { transition_start = n; }
46  void set_transition_end (unsigned n) { transition_end = n; }
47  void set_transition (unsigned n) { transition_end = transition_start = n; }
48 
50  void build ();
51 
53  void Hanning ();
54 
56  void Welch ();
57 
59  void Bartlett ();
60 
62 
65  void Tukey ();
66 
68  void TopHat ();
69 
71  void normalize();
72 
73  Type getType () { return type; };
74 
75  Type get_type () { return getType(); };
76 
78  void operate (float* indata, float* outdata = 0) const;
79 
81  void swap ();
82 
84  double integrated_product (float* data, unsigned incr=1) const;
85 
87 
88  void dump (const std::string& filename);
89 
90  private:
91 
92  static std::map<std::string, Type> type_map;
93 
95  Type type;
96 
98  bool analytic;
99 
101  bool swapped;
102 
104  unsigned zero_start;
106  unsigned zero_end;
107 
109  unsigned transition_start;
111  unsigned transition_end;
112 
113  static std::map<std::string, Type> init_type_map ()
114  {
115  static std::map<std::string, Type> _type_map;
116  _type_map["no_window"] = none;
117  _type_map["none"] = none;
118  _type_map["bartlett"] = bartlett;
119  _type_map["hanning"] = hanning;
120  _type_map["tukey"] = tukey;
121  _type_map["welch"] = welch;
122  _type_map["top_hat"] = top_hat;
123  return _type_map;
124  }
125 
126  };
127 }
128 
129 #endif
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
void set_transition_end(unsigned n)
Number of samples in the transition region on the end.
Definition: Apodization.h:56
void normalize()
make the integrated total of the window equal to one
Definition: Apodization.C:181
void set_type(const std::string &)
Set the type of window function by name.
Definition: Apodization.C:34
void swap()
Swap the two halves of the window.
Definition: Apodization.C:169
void Tukey()
Create Tukey window function.
Definition: Apodization.C:123
void set_transition_start(unsigned n)
Number of samples in the transition region on the start.
Definition: Apodization.h:54
void build()
Build the specified window.
Definition: Apodization.C:44
void dump(const std::string &filename)
Write the window to a text file.
Definition: Apodization.C:208
void Welch()
Create a Welch window function.
Definition: Apodization.C:95
Apodization()
Null constructor.
Definition: Apodization.C:16
void TopHat()
Create top hat window function.
Definition: Apodization.C:74
void Bartlett()
Create a Bartlett window function.
Definition: Apodization.C:108
void set_size(unsigned)
Set the number of samples in the window.
Definition: Apodization.C:29
void Hanning()
Create a Hanning window function.
Definition: Apodization.C:85
void set_analytic(bool f=true)
Set true when the data to be tapered are complex-valued.
Definition: Apodization.h:47
void operate(float *indata, float *outdata=0) const
Multiply indata by the window function.
Definition: Apodization.C:148
double integrated_product(float *data, unsigned incr=1) const
Returns SUM i=1..N {window[i] * data[i]}.
Definition: Apodization.C:191

Generated using doxygen 1.8.17