Logo coherent WaveBurst  
Library Reference Guide
Logo
Window.hh
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 /***************************************************************************
20  Window.hh - description
21  -------------------
22  begin : Wen Dec 21 2011
23  copyright : (C) 2011 by Gabriele Vedovato
24  email : vedovato@lnl.infn.it
25  ***************************************************************************/
26 
27 /***************************************************************************
28  * *
29  * This program is free software; you can redistribute it and/or modify *
30  * it under the terms of the GNU General Public License as published by *
31  * the Free Software Foundation; either version 2 of the License, or *
32  * (at your option) any later version. *
33  * *
34  ***************************************************************************/
35 
36 #ifndef CWBWINDOW_H
37 #define CWBWINDOW_H
38 
39 
40 /**
41  *@author Gabriele Vedovato
42  */
43 
44 /* Reference:
45  * Oppenheim, A. V. and Schafer, R. W., ``Discrete-Time Signal Processing.''
46  * ISBN 0-13-216771-9, Prentice-Hall, Inc., 1989, pp. 447--448
47  *
48  * http://www.mathworks.com/access/helpdesk/help/toolbox/signal/signal.shtml
49  */
50 
51 /* this is a c++ porting of the window package in the "Sonic Flow" tool box
52  The homepage of Sonic Flow is at http://sonicflow.sourceforge.net/.
53  */
54 
55 #include <time.h>
56 #include <stdlib.h>
57 #include <math.h>
58 #include <ctype.h>
59 #include <string>
60 #include <iostream>
61 #include <fstream>
62 #include "TROOT.h"
63 #include "TObjArray.h"
64 #include "TObjString.h"
65 #include "TString.h"
66 
67 using namespace std;
68 
69 namespace CWB {
70 
71 class Window {
72 public:
73  Window(char* formula, unsigned n, double fParameter=0);
74  ~Window();
75 
76  TString GetVersion(char c='s') {
77  if(c=='s') return TString("window101");
78  if(c=='d') return TString("101");
79  else return TString("window-1.0.1");
80  }
81 
82  double GetValue(unsigned i);
83  double GetSize() {return size;}
84 
85 private:
86 
87  double* window;
88  unsigned size;
89  void Normalize (double* out_window, unsigned n);
90  double fParameter;
91 
92  /* Compute a modified Bartlett-Hann window.
93  * Like Bartlett, Hann, and Hamming windows, this window has a
94  * mainlobe at the origin and asymptotically decaying sidelobes on
95  * both sides. It is a linear combination of weighted Bartlett and
96  * Hann windows with near sidelobes lower than both Bartlett and Hann
97  * and with far sidelobes lower than both Bartlett and Hamming
98  * windows. The mainlobe width of the modified Bartlett-Hann window is
99  * not increased relative to either Bartlett or Hann window mainlobes.
100  */
101  void
102  barthann (double* out_window, unsigned n);
103 
104  /* Compute a Bartlett window.
105  * The Bartlett window is very similar to a triangular window as
106  * returned by the triangular function. The Bartlett
107  * window always ends with zeros at samples 0 and n -1, however,
108  * while the triangular window is nonzero at those points. For length
109  * odd, the center n-2 points of bartlett(,n) are equivalent
110  * to those of sf_window_triangular(,n-2).
111  */
112  void
113  bartlett (double* out_window, unsigned n);
114 
115  /* Compute a Blackman window
116  * Blackman windows have slightly wider central lobes and less sideband
117  * leakage than equivalent length Hamming and Hann windows.
118  */
119  void
120  blackman (double* out_window, unsigned n);
121 
122  /* Compute a minimum 4-term Blackman-harris window.
123  * The window is minimum in the sense that its maximum sidelobes are
124  * minimized.
125  */
126  void
127  blackmanharris (double* out_window, unsigned n);
128 
129  /* Compute a Bohman window.
130  * A Bohman window is the convolution of two half-duration cosine
131  * lobes. In the time domain, it is the product of a triangular window
132  * and a single cycle of a cosine with a term added to set the first
133  * derivative to zero at the boundary. Bohman windows fall off as 1/w^4.
134  */
135  void
136  bohman (double* out_window, unsigned n);
137 
138  /* [UNIMPLEMENTED] */
139  /* void */
140  /* chebyshev (double * out_window, unsigned n, */
141  /* double r = 100.0); */
142 
143  /* Compute a Flat Top weighted window
144  * Flat Top windows have very low passband ripple (< 0.01 dB) and are
145  * used primarily for calibration purposes. Their bandwidth is
146  * approximately 2.5 times wider than a Hann window.
147  */
148  void
149  flattop (double* out_window, unsigned n);
150 
151  /* Compute a Gaussian window where alpha >= 2 is the reciprocal of the
152  * standard deviation. The width of the window is inversely related to
153  * the value of alpha; a larger value of alpha produces a more narrow
154  * window. Default value for alpha : 2.5
155  */
156  void
157  gauss (double* out_window, unsigned n,
158  double alpha);
159 
160  /* Compute a Hamming window
161  */
162  void
163  hamming (double* out_window, unsigned n);
164 
165  /* Compute a Hann (Hanning) window
166  */
167  void
168  hann (double* out_window, unsigned n);
169 
170  /* [UNIMPLEMENTED] */
171  /* void */
172  /* kaiser (double * out_window, unsigned n, */
173  /* SF_Real beta = 0.5); */
174 
175  /* Compute a minimum 4-term Blackman-Harris window, as defined by Nuttall
176  * The window is minimum in the sense that its maximum sidelobes are
177  * minimized. The coefficients for this window differ from the
178  * Blackman-Harris window coefficients computed with
179  * blackmanharris and produce slightly lower sidelobes.
180  */
181  void
182  nuttall (double* out_window, unsigned n);
183 
184  /* [UNIMPLEMENTED] */
185  /* void */
186  /* parzen (double* out_window, unsigned n); */
187 
188  /* Compute a rectangular window
189  */
190  void
191  rectangular (double* out_window, unsigned n);
192 
193  /* [UNIMPLEMENTED] */
194  /* void */
195  /* saramaki (double* out_window, unsigned n); */
196 
197  /* [UNIMPLEMENTED] */
198  /* void */
199  /* transversal (double* out_window, unsigned n); */
200 
201  /* Compute a triangular window.
202  */
203  void
204  triangular (double* out_window, unsigned n);
205 
206  /* Compute a Tukey window
207  * Tukey windows are cosine-tapered windows. r is the ratio of taper to
208  * constant sections and is between 0 and 1. r <= 0 is a
209  * rectangular window and r>= 1 is a hann window.
210  * default value for r : 0.5
211  */
212  void
213  tuckey (double* out_window, unsigned n,
214  double r);
215 
216  /* Compute a welch window.
217  */
218  void
219  welch (double* out_window, unsigned n);
220 };
221 
222 } // end namespace
223 
224 #endif
225 
Definition: ced.hh:42
int n
Definition: cwb_net.C:28
TString("c")
STL namespace.
Long_t size
i drho i
TString GetVersion(char c='s')
Definition: Window.hh:76
double fParameter
Definition: Window.hh:90
unsigned size
Definition: Window.hh:88
regression r
Definition: Regression_H1.C:44
double GetSize()
Definition: Window.hh:83
char formula[256]
double * window
Definition: Window.hh:87