1 | //--------------------------------------------------------------------------
|
---|
2 | // File and Version Information:
|
---|
3 | // $Id: gaussfilt.cc,v 1.4 1999-11-29 14:16:04 ansari Exp $
|
---|
4 | //
|
---|
5 | // Description:
|
---|
6 | //
|
---|
7 | // History (add to end):
|
---|
8 | // Sophie Oct, 1999 - creation
|
---|
9 | //
|
---|
10 | //------------------------------------------------------------------------
|
---|
11 |
|
---|
12 | //---------------
|
---|
13 | // C++ Headers --
|
---|
14 | //---------------
|
---|
15 | #include "machdefs.h"
|
---|
16 | #include <iostream.h>
|
---|
17 | #include <math.h>
|
---|
18 |
|
---|
19 | #include "gaussfilt.h"
|
---|
20 |
|
---|
21 | //----------------
|
---|
22 | // Constructor --
|
---|
23 | //----------------
|
---|
24 | GaussianFilter::GaussianFilter()
|
---|
25 | : SpectralResponse()
|
---|
26 | {
|
---|
27 | setParams(100, 10., 1.);
|
---|
28 | }
|
---|
29 |
|
---|
30 | GaussianFilter::GaussianFilter(double nu0, double s, double a, double numin, double numax)
|
---|
31 | : SpectralResponse(numin, numax)
|
---|
32 | {
|
---|
33 | setParams(nu0, s, a);
|
---|
34 | }
|
---|
35 |
|
---|
36 |
|
---|
37 | //--------------
|
---|
38 | // Destructor --
|
---|
39 | //--------------
|
---|
40 | GaussianFilter::~GaussianFilter()
|
---|
41 | {
|
---|
42 | }
|
---|
43 |
|
---|
44 | // ---------------------------
|
---|
45 | // -- Function Definitions --
|
---|
46 | // ---------------------------
|
---|
47 |
|
---|
48 |
|
---|
49 | double
|
---|
50 | GaussianFilter::transmission(double nu) const
|
---|
51 | {
|
---|
52 | if ((nu < _numin) || (nu > _numax)) return(0.);
|
---|
53 | else {
|
---|
54 | double tmp = (nu-_nu0)/_s;
|
---|
55 | return(_a * exp(-tmp*tmp));
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | double
|
---|
60 | GaussianFilter::peakFreq() const
|
---|
61 | {
|
---|
62 | return(_nu0);
|
---|
63 | }
|
---|
64 |
|
---|
65 | double
|
---|
66 | GaussianFilter::peakTransmission() const
|
---|
67 | {
|
---|
68 | return(_a);
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 |
|
---|
73 | void
|
---|
74 | GaussianFilter::setParams(double nu0, double s, double a)
|
---|
75 | {
|
---|
76 | if (s < 1.e-19) s = 1.e-19;
|
---|
77 | _s = s;
|
---|
78 | _nu0 = nu0;
|
---|
79 | _a = a;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 |
|
---|
84 | void
|
---|
85 | GaussianFilter::Print(ostream& os) const
|
---|
86 | {
|
---|
87 | os << "GaussianFilter::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
88 | os << " T = A * Exp(-((nu-nu0)/s)^2) : " << " nu0= " << _nu0 << " sig= "
|
---|
89 | << _s << " A= " << _a << endl;
|
---|
90 | os << "PeakFreq= " << peakFreq() << " Transmission= " << transmission(peakFreq()) << endl;
|
---|
91 |
|
---|
92 |
|
---|
93 | }
|
---|
94 |
|
---|
95 | void
|
---|
96 | ObjFileIO<GaussianFilter>::WriteSelf(POutPersist& s) const
|
---|
97 | {
|
---|
98 | if(dobj == NULL)
|
---|
99 | {
|
---|
100 | cout << " ObjFileIO<GaussianFilter>::WriteSelf:: dobj= null " << endl;
|
---|
101 | return;
|
---|
102 | }
|
---|
103 | int_4 version, nothing;
|
---|
104 | version = 1;
|
---|
105 | nothing = 0; // Reserved for future use
|
---|
106 | s.PutI4(version);
|
---|
107 | s.PutI4(nothing);
|
---|
108 |
|
---|
109 | s.PutR8(dobj->minFreq());
|
---|
110 | s.PutR8(dobj->maxFreq());
|
---|
111 | s.PutR8(dobj->giveNorm());
|
---|
112 | s.PutR8(dobj->giveNu0());
|
---|
113 | s.PutR8(dobj->giveDNu());
|
---|
114 | }
|
---|
115 |
|
---|
116 | void
|
---|
117 | ObjFileIO<GaussianFilter>::ReadSelf(PInPersist& s)
|
---|
118 | {
|
---|
119 | int_4 version, nothing;
|
---|
120 | version = 1;
|
---|
121 | nothing = 0; // Reserved for future use
|
---|
122 | s.GetI4(version);
|
---|
123 | s.GetI4(nothing);
|
---|
124 |
|
---|
125 | if(dobj == NULL)
|
---|
126 | {
|
---|
127 | dobj= new GaussianFilter();
|
---|
128 | ownobj= true;
|
---|
129 | }
|
---|
130 |
|
---|
131 | r_8 a, nu0, dnu, numin, numax;
|
---|
132 | s.GetR8(numin);
|
---|
133 | s.GetR8(numax);
|
---|
134 | s.GetR8(a);
|
---|
135 | s.GetR8(nu0);
|
---|
136 | s.GetR8(dnu);
|
---|
137 | dobj->setMinMaxFreq(numin, numax);
|
---|
138 | dobj->setParams(nu0, dnu, a);
|
---|
139 | // cout << " Norm - Nu0 - DNu - minFreq - maxFreq " << endl;
|
---|
140 | // cout << _a << "-" << _nu0 << "-" << _s << "-" << _numin << "-" << _numax << endl;
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
145 | #pragma define_template ObjFileIO<GaussianFilter>
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
149 | template class ObjFileIO<GaussianFilter>;
|
---|
150 | #endif
|
---|