source: Sophya/trunk/Cosmo/RadioBeam/mbeamcyl.cc@ 3191

Last change on this file since 3191 was 3191, checked in by legoff, 19 years ago

Cylinders have different x positions (NS).
This is taken into account in the signal phase shift
and in the exp() term when combining cylinders.
We can have more bins in x than antennas in one cylinder
to see the gain in resolution along x due to several cylinders at different x

File size: 5.7 KB
Line 
1#include "mbeamcyl.h"
2#include "fftpserver.h"
3#include "vector3d.h"
4#include "matharr.h"
5#include "srandgen.h"
6
7//=================================================
8
9MultiBeamCyl::MultiBeamCyl(int nr, int ns, double posx, double posy)
10 : texact(ns) , tjitt(ns) , toffset(nr) ,
11 signal(ns), sigjitt(ns) , gain(nr)
12{
13 NR = nr;
14 NS = ns;
15 posY = posy;
16 posX = posx;
17
18 SetPrintLevel(0);
19
20 SetBaseFreqDa(2., 0.25);
21 SetNoiseSigma(0.);
22 SetTimeJitter(0.);
23 SetTimeOffsetSigma(0.);
24 SetGains(1., 0., 0);
25 adfg = false; src = NULL;
26 SetSources(new BRSourceGen, true);
27}
28
29MultiBeamCyl::~MultiBeamCyl()
30{
31 if (adfg && src) delete src;
32}
33
34void MultiBeamCyl::SetSources(BRSourceGen* brs, bool ad)
35{
36 if (brs == NULL) return;
37 if (adfg && src) delete src;
38 src = brs; adfg=ad;
39 if (PrtLev > 1)
40 cout << " MultiBeamCyl::SetSources(brs=" << brs <<" ,bool) NbSrc="
41 << src->NbSources() << endl;
42
43}
44
45void MultiBeamCyl::SetGains(double g, double sigg, int nzerogain)
46{
47 if (sigg < 1.e-6) gain = g;
48 else gain = RandomSequence(RandomSequence::Gaussian, g, sigg);
49 int k;
50 for (k=0; k<NR; k++) if (gain(k) < 0) gain(k) = 0.;
51 for(k=0; k<nzerogain; k++) {
52 int zg = random()%NR;
53 if ((zg >=0) && (zg < NR)) gain(zg) = 0.;
54 }
55 if (PrtLev > 1)
56 cout << " MultiBeamCyl::SetGains(g=" << g <<" ,sigg=" << sigg
57 << " ,nzg=" << nzerogain << " )" << endl;
58}
59
60void MultiBeamCyl::ComputeTimeVectors()
61{
62 texact = RegularSequence(0., 1.);
63 toffset = RandomSequence(RandomSequence::Gaussian, 0., toffsig);
64 NewTJitVector();
65}
66
67void MultiBeamCyl::NewTJitVector(int num)
68{
69 if (timejitter > 1.e-19) {
70 tjitt = RandomSequence(RandomSequence::Gaussian, 0., timejitter);
71 tjitt += texact;
72 }
73 else tjitt = texact;
74 if (num >= 0) tjitt += toffset(num);
75
76}
77
78int MultiBeamCyl::ComputeSignalVector(int num, bool fgsignojit)
79{
80 int nok = 0;
81 signal = 0.;
82 sigjitt = 0.;
83 for(int is=0; is<src->freq.Size(); is++) {
84 double fr = src->freq(is);
85 if ((fr < 0.) || (fr > 0.5)) continue;
86 nok++;
87 // Pour le dephasage entre recepteurs, on doit utiliser la frequence vraie,
88 // pas celle apres shift (freq-reduite)
89 // lambda = c T = c/freq avec c = 1, dephasage = 2*pi*num*Da*sin(ang)/lambda
90 double dephasage = (posX+num*Da)*sin(src->angX(is)) +
91 posY*sin(src->angY(is)) ;
92 dephasage *= (2*M_PI*(fr+freq0));
93 // On ajoute alors la phase propre de chaque source
94 dephasage += src->phase(is);
95 double amprep = src->amp(is)*AngResponse(src->angX(is), src->angY(is));
96 for(int k=0; k<NS; k++) {
97 sigjitt(k) += amprep*sin(2.*M_PI*fr*tjitt(k)+dephasage);
98 if (fgsignojit)
99 signal(k) += amprep*sin(2.*M_PI*fr*texact(k)+dephasage);
100 }
101 }
102 // Application du gain du detecteur
103 r_4 ga = gain(num);
104 if (fabs(ga-1.) > 1.e-9) {
105 signal *= ga;
106 sigjitt *= ga;
107 }
108 // Ajout de bruit (ampli ...)
109 if (signoise > 1.e-18) {
110 for(int k=0; k<NS; k++) {
111 sigjitt(k) += GauRnd(0., signoise);
112 if (fgsignojit) signal(k) += GauRnd(0., signoise);
113 }
114 }
115
116 FFTPackServer ffts;
117
118 ffts.FFTForward(sigjitt, f_sigjit);
119 if (fgsignojit) ffts.FFTForward(signal, f_sig);
120
121 return nok;
122}
123
124
125/* --- a supprimer ?
126inline float myZmodule(complex<r_4>& z)
127{
128 return (float)sqrt((double)(z.real()*z.real()+z.imag()*z.imag()));
129}
130----- */
131
132void MultiBeamCyl::ReconstructSourcePlane(bool fgzerocentre)
133{
134 ComputeTimeVectors();
135 int noksrc = ComputeSignalVector(0, false);
136 vector<TVector< complex<r_4> > > vvfc;
137 cout << "MultiBeamCyl::ReconstructSourcePlane() NR=" << NR
138 << " PosY=" << posY << " NFreq=" << f_sigjit.Size()-1 << " NOkSrc=" << noksrc << endl;
139 if (PrtLev > 0) {
140 cout << " ... posY= " << posY << " MeanGain=" << Mean(gain) << " MeanAmpSrc="
141 << Mean(src->amp) << endl;
142 cout << " ...SigNoise=" << signoise << " TimeJitter=" << timejitter
143 << " TOffSig=" << toffsig << " Da=" << Da << " Freq0=" << freq0 << endl;
144 }
145 // On ne s'occupe pas de la composante continue
146 for(int jf=1; jf<f_sigjit.Size(); jf++) {
147 TVector<complex<r_4> > cf(NR);
148 vvfc.push_back(cf);
149 }
150 cout << "ReconstructSourcePlane()/Info: computing s(t) for each receptor ..." << endl;
151 int pmod = NR/10;
152 for(int ir=0; ir<NR; ir++) {
153 if (timejitter > 1.e-19) NewTJitVector(ir);
154 noksrc = ComputeSignalVector(ir, false);
155 for(int jf=1; jf<f_sigjit.Size(); jf++)
156 vvfc[jf-1](ir) = f_sigjit(jf);
157 if ( (PrtLev>0) && (ir%pmod == 0) )
158 cout << " OK s(t) for ir=" << ir << " / NR=" << NR << " NOkSrc=" << noksrc << endl;
159 }
160
161 cout << "ReconstructSourcePlane()/Info: computing s(ang) for each freq by FFT" << endl;
162 cmplx_srcplane.SetSize(f_sigjit.Size()-1, NR);
163 // rec_srcplane.SetSize(f_sigjit.Size()-1, NR);
164 FFTPackServer ffts;
165 TVector<complex<r_4> > fcf;
166 pmod = vvfc.size()/10;
167 for(int jf=0; jf<vvfc.size(); jf++) {
168 ffts.FFTForward(vvfc[jf], fcf);
169 if (fcf.Size() != NR) {
170 cout << "ReconstructSourcePlane()/BUG jf=" << jf << " fcf.Size() != NR "
171 << fcf.Size() << " != " << NR << endl;
172 continue;
173 }
174 if (fgzerocentre) { // On veut avoir la direction angle=0 au milieu de la matrice
175 int milieu = (NR-1)/2;
176 if (NR%2 == 0) milieu++;
177 int decal = NR - milieu - 1;
178 for (int ir=0; ir<=milieu; ir++)
179 cmplx_srcplane(jf, ir+decal) = fcf(ir);
180 // rec_srcplane(jf, ir+decal) = myZmodule(fcf(ir));
181
182 for (int ir=milieu+1; ir<NR; ir++)
183 cmplx_srcplane(jf, decal-(NR-ir)) = fcf(ir);
184 // rec_srcplane(jf, decal-(NR-ir)) = myZmodule(fcf(ir));
185
186 }
187 else for (int ir=0; ir<NR; ir++)
188 cmplx_srcplane(jf, ir) = fcf(ir);
189 // rec_srcplane(jf, ir) = myZmodule(fcf(ir));
190
191 if ( (PrtLev > 0) && (jf%pmod == 0))
192 cout << " OK rec_srcplane(jf, ir) for jf=" << jf << endl;
193 }
194
195
196 cout << "ReconstructSourcePlane()/Info: rec_srcplane computed OK" << endl;
197}
198
199
Note: See TracBrowser for help on using the repository browser.