-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfdtd.cpp
More file actions
2183 lines (1662 loc) · 62.1 KB
/
fdtd.cpp
File metadata and controls
2183 lines (1662 loc) · 62.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************************************************
fdtd.cpp -
$Author: Wang Wen $
created at: Sun Dec 15 17:42:34 JST 2013
Copyright (C) 2013-2014 Wang Wen
*********************************************************************/
#include <iostream>
#include <sstream>
#include <fstream>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#include <blitz/array.h>
#include <Python.h>
#include <omp.h>
#define FDTD_PYTHON_MODULE
#define private public
#ifdef _WIN32
inline double round( double d )
{
return floor(d + 0.5);
}
#endif
namespace fdtd {
#ifdef __GNUG__
const double pi = M_PI;
#elif _WIN32
const double pi = 3.141592653589793238463;
#endif
#ifdef __GNUG__
const double inf = 1.0 / 0.0;
#elif _WIN32
const double inf = 1e100;
#endif
const double eps_0 = 8.854187817e-12;
const double mu_0 = 4e-7 * pi;
const double c = 2.998e8;
class vector_3 {
public:
double x;
double y;
double z;
vector_3(double x, double y, double z): x(x), y(y), z(z) {
}
#ifdef FDTD_PYTHON_MODULE
vector_3(PyObject *p) {
if(PySequence_Check(p)) {
x = PyFloat_AsDouble(PySequence_GetItem(p, 0));
y = PyFloat_AsDouble(PySequence_GetItem(p, 1));
z = PyFloat_AsDouble(PySequence_GetItem(p, 2));
}
else {
//std::cout << "Error vector initialized from python object, the argument is not a sequence...";
x = PyFloat_AsDouble(PyObject_GetAttrString(p, "x"));
y = PyFloat_AsDouble(PyObject_GetAttrString(p, "y"));
z = PyFloat_AsDouble(PyObject_GetAttrString(p, "z"));
}
}
PyObject *tuple() const {
PyObject *tuple = PyTuple_New(3);
PyTuple_SetItem(tuple, 0, PyFloat_FromDouble(x));
PyTuple_SetItem(tuple, 1, PyFloat_FromDouble(y));
PyTuple_SetItem(tuple, 2, PyFloat_FromDouble(z));
return tuple;
}
#endif
vector_3(): x(0), y(0), z(0) {
}
std::string str() const;
private:
};
std::ostream& operator<<(std::ostream& os, const vector_3 &pt) {
os << "(" << pt.x;
os << ", " << pt.y;
os << ", " << pt.z;
os << ")";
return os;
}
std::string vector_3::str() const {
std::stringstream ss;
ss << *this;
return ss.str();
}
inline vector_3 operator+(const vector_3 &vct1, const vector_3 &vct2) {
return vector_3(vct1.x + vct2.x,
vct1.y + vct2.y,
vct1.z + vct2.z
);
}
inline vector_3 operator+(const vector_3 &vct, double val) {
return vector_3(vct.x + val,
vct.y + val,
vct.z + val
);
}
inline vector_3 operator+(const vector_3 &vct1, PyObject *vct2) {
return vector_3(vct1.x + PyFloat_AsDouble(PySequence_GetItem(vct2, 0)),
vct1.y + PyFloat_AsDouble(PySequence_GetItem(vct2, 1)),
vct1.z + PyFloat_AsDouble(PySequence_GetItem(vct2, 2))
);
}
inline vector_3 operator+(PyObject *vct1, const vector_3 &vct2) {
return vector_3(PyFloat_AsDouble(PySequence_GetItem(vct1, 0)) + vct2.x,
PyFloat_AsDouble(PySequence_GetItem(vct1, 1)) + vct2.y,
PyFloat_AsDouble(PySequence_GetItem(vct1, 2)) + vct2.z
);
}
inline vector_3 operator-(const vector_3 &vct1, const vector_3 &vct2) {
return vector_3(vct1.x - vct2.x,
vct1.y - vct2.y,
vct1.z - vct2.z
);
}
inline vector_3 operator-(const vector_3 &vct1, PyObject *vct2) {
return vector_3(vct1.x - PyFloat_AsDouble(PySequence_GetItem(vct2, 0)),
vct1.y - PyFloat_AsDouble(PySequence_GetItem(vct2, 1)),
vct1.z - PyFloat_AsDouble(PySequence_GetItem(vct2, 2))
);
}
inline vector_3 operator-(PyObject *vct1, const vector_3 &vct2) {
return vector_3(PyFloat_AsDouble(PySequence_GetItem(vct1, 0)) - vct2.x,
PyFloat_AsDouble(PySequence_GetItem(vct1, 1)) - vct2.y,
PyFloat_AsDouble(PySequence_GetItem(vct1, 2)) - vct2.z
);
}
inline vector_3 operator-(const vector_3 &vct, double val) {
return vector_3(vct.x - val,
vct.y - val,
vct.z - val
);
}
inline vector_3 operator*(double k, const vector_3 &vct) {
return vector_3(k * vct.x,
k * vct.y,
k * vct.z
);
}
inline vector_3 operator*(const vector_3 &vct, double k) {
return vector_3(k * vct.x,
k * vct.y,
k * vct.z
);
}
inline vector_3 operator/(const vector_3 &vct, double k) {
return vector_3(vct.x / k,
vct.y / k,
vct.z / k
);
}
inline double norm(const vector_3 &vct) {
return sqrt(vct.x * vct.x +
vct.y * vct.y +
vct.z * vct.z);
}
inline double inner_product(const vector_3 &vct1, const vector_3 &vct2) {
return (vct1.x * vct2.x +
vct1.y * vct2.y +
vct1.z * vct2.z);
}
inline vector_3 cross_product(const vector_3 &vct1, const vector_3 &vct2) {
return vector_3(vct1.y * vct2.z - vct1.z * vct2.y,
vct1.z * vct2.x - vct1.x * vct2.z,
vct1.x * vct2.y - vct1.y * vct2.x);
}
typedef vector_3 point_3;
typedef vector_3 coord_3;
typedef blitz::TinyVector<int, 3> Index3;
const vector_3 VEC_ORIGIN = vector_3(0, 0, 0);
const vector_3 VEC_UNIT_X = vector_3(1, 0, 0);
const vector_3 VEC_UNIT_Y = vector_3(0, 1, 0);
const vector_3 VEC_UNIT_Z = vector_3(0, 0, 1);
void Assert(bool statement, std::string err) {
if(!statement) {
std::cout << err << std::endl;
exit(1);
}
}
bool IntValue(double f) {
return ((double)((int)(f)) == f);
}
bool ProperDivide(double a, double b, double h) {
return (a > b) && (IntValue((b - a) / h));
}
double GaussianPulse(double t, double tao) {
return exp(-pow(t / tao, 2));
}
double SinWave(double t, double omega = 2 * pi) {
return sin(omega * t);
}
double dd_gaussian(double t, double k) {
return pow(32.0 * pow(k, 2) / (9 * pi), 0.25)
* (1.0 - 2.0 * pow(k * t, 2))
* exp(- pow(k * t, 2));
}
double Min(double a, double b) {
return ((a < b) ? a: b);
}
int Min(int a, int b) {
return ((a < b) ? a: b);
}
double Max(double a, double b) {
return ((a > b) ? a: b);
}
int Max(int a, int b) {
return ((a > b) ? a: b);
}
struct Medium {
Medium(): eps(eps_0), mu(mu_0), sig(0) {
}
Medium(double eps, double mu, double sig):
eps(eps), mu(mu), sig(sig) {
}
double eps;
double mu;
double sig;
};
class Shape {
public:
virtual bool hasInnerPoint(point_3 pt) const = 0;
virtual double max_x() const = 0;
virtual double max_y() const = 0;
virtual double max_z() const = 0;
virtual double min_x() const = 0;
virtual double min_y() const = 0;
virtual double min_z() const = 0;
virtual ~Shape() {
}
};
class Brick: public Shape {
public:
Brick() {
}
Brick(const vector_3 &min, const vector_3 &max):
coord_min(min), coord_max(max) {
}
#ifdef FDTD_PYTHON_MODULE
Brick(PyObject *min, PyObject *max):
coord_min(min), coord_max(max) {
}
#endif
std::string str() const;
bool hasInnerPoint(point_3 pt) const override {
return (pt.x < coord_max.x && pt.x > coord_min.x &&
pt.y < coord_max.y && pt.y > coord_min.y &&
pt.z < coord_max.z && pt.z > coord_min.z );
}
double max_x() const override {
return coord_max.x;
}
double max_y() const override {
return coord_max.y;
}
double max_z() const override {
return coord_max.z;
}
double min_x() const override {
return coord_min.x;
}
double min_y() const override {
return coord_min.y;
}
double min_z() const override {
return coord_min.z;
}
private:
coord_3 coord_max;
coord_3 coord_min;
};
std::ostream& operator<<(std::ostream& os, Brick cub) {
os << "geometrical object cuboid with bounded field:" << std::endl;
os << " X axis in range (" << cub.min_x() << ", " << cub.max_x() << ")" << std::endl;
os << " Y axis in range (" << cub.min_y() << ", " << cub.max_y() << ")" << std::endl;
os << " Z axis in range (" << cub.min_z() << ", " << cub.max_z() << ")" << std::endl;
return os;
}
std::string Brick::str() const {
std::stringstream ss;
ss << *this;
return ss.str();
}
class Sphere: public Shape {
public:
Sphere(): radius(1), center() {
}
Sphere(const point_3 &cnt, double radi): radius(radi), center(cnt) {
}
#ifdef FDTD_PYTHON_MODULE
Sphere(PyObject *cnt, double radi): radius(radi), center(cnt) {
}
#endif
bool hasInnerPoint(point_3 pt) const override {
return norm(pt - center) < radius;
}
point_3 getCenter() const {
return center;
}
double getRadius() {
return radius;
}
double max_x() const override {
return center.x + radius;
}
double max_y() const override {
return center.y + radius;
}
double max_z() const override {
return center.z + radius;
}
double min_x() const override {
return center.x - radius;
}
double min_y() const override {
return center.y - radius;
}
double min_z() const override {
return center.z - radius;
}
std::string str() const;
private:
double radius;
point_3 center;
};
std::ostream& operator<<(std::ostream& os, Sphere sph) {
std::cout << "geometrical object sphere, with center at " << sph.getCenter()
<< " and radius of " << sph.getRadius() << "..."
<< std::endl;
return os;
}
std::string Sphere::str() const {
std::stringstream ss;
ss << *this;
return ss.str();
}
class Cartesian {
public:
Cartesian():coord_max(), coord_min(), resol(0) {
}
Cartesian(const coord_3 &max, const coord_3 &min, double resol);
Cartesian(const coord_3 &max, double resol);
Cartesian(PyObject *max, double resol) {
vector_3 max_v(max);
this->resol = resol;
this->coord_max = this->fit_resol(max);
this->coord_min = coord_3(0, 0, 0);
}
point_3 point_at(double x, double y, double z) const;
std::string str() const;
/**
Cartesian &addBrickMedium(const Brick &shp, const Medium &med) {
this->dlcf.insert(std::pair<boost::any, Medium>(shp, med));
return *this;
}
Cartesian &addSphereMedium(const Sphere &shp, const Medium &med) {
this->dlcf.insert(std::pair<boost::any, Medium>(shp, med));
return *this;
}
**/
double resolu() const {
return resol;
}
double max_x() const
{
return coord_max.x;
}
double max_y() const
{
return coord_max.y;
}
double max_z() const
{
return coord_max.z;
}
double min_x() const
{
return coord_min.x;
}
double min_y() const
{
return coord_min.y;
}
double min_z() const
{
return coord_min.z;
}
private:
coord_3 coord_max;
coord_3 coord_min;
double resol;
//std::map<boost::any, Medium> dlcf;
//std::vector<Shape> shl;
double fit_resol(double length) const;
coord_3 fit_resol(const coord_3 &coord) const;
};
double Cartesian::fit_resol(double length) const {
double base = (int)(length / resol) * resol;
double remain = length - base;
// std::cout << fabs(remain) / resol << std::endl;
if(fabs(remain) / resol > 0.5) {
if(remain > 0)
return base + resol;
return base - resol;
}
return base;
}
coord_3 Cartesian::fit_resol(const coord_3 &coord) const {
return coord_3(this->fit_resol(coord.x),
this->fit_resol(coord.y),
this->fit_resol(coord.z)
);
}
Cartesian::Cartesian(const coord_3 &max, const coord_3 &min, double resol) {
this->resol = resol;
this->coord_max = this->fit_resol(max);
this->coord_min = this->fit_resol(min);
}
Cartesian::Cartesian(const coord_3 &max, double resol) {
this->resol = resol;
this->coord_max = this->fit_resol(max);
this->coord_min = coord_3(0, 0, 0);
}
point_3 Cartesian::point_at(double x, double y, double z) const {
return this->fit_resol(coord_3(x, y, z));
}
std::ostream& operator<<(std::ostream& os, Cartesian ct) {
os << "cartesian coordinate system:" << std::endl;
os << " X axis in range (" << ct.min_x() << ", " << ct.max_x() << ")" << std::endl;
os << " Y axis in range (" << ct.min_y() << ", " << ct.max_y() << ")" << std::endl;
os << " Z axis in range (" << ct.min_z() << ", " << ct.max_z() << ")" << std::endl;
os << " resolution: " << ct.resolu() << std::endl;
return os;
}
std::string Cartesian::str() const {
std::stringstream ss;
ss << *this;
return ss.str();
}
/**
struct Source {
virtual double excitation(double t) = 0;
};
**/
struct PointSource {
PointSource(): index() {
}
PointSource(const vector_3 &point, double central_freq, double band_width):
pos(point), index(), band_width(band_width) {
omega_central = 2e9 * pi * central_freq;
tao = sqrt(2.3) / (pi * 0.5e9 * band_width);
}
#ifdef FDTD_PYTHON_MODULE
PointSource(PyObject *point, double central_freq, double band_width):
pos(point), index(), band_width(band_width) {
omega_central = 2e9 * pi * central_freq;
tao = sqrt(2.3) / (pi * 0.5e9 * band_width);
}
#endif
double excitation(double t) const {
return sin(omega_central * t) * GaussianPulse(t - 4.5 * tao, tao);
}
double bandWidth() const {
return this->band_width;
}
point_3 position() const {
return this->pos;
}
double centralFreq() const {
return (omega_central / (2 * pi * 1e9));
}
void setIndex(const Index3 &index) {
this->index = index;
}
private:
double band_width;
double omega_central;
double tao;
vector_3 pos;
Index3 index;
};
struct PmlGemp {
double Exy;
double Exz;
double Eyx;
double Eyz;
double Ezx;
double Ezy;
double Hxy;
double Hxz;
double Hyx;
double Hyz;
double Hzx;
double Hzy;
float sigma_pex;
float sigma_pey;
float sigma_pez;
float sigma_pmx;
float sigma_pmy;
float sigma_pmz;
};
struct Gemp { // general electro-magnetic properties
Gemp(): eps_x(eps_0), eps_y(eps_0), eps_z(eps_0),
mu_x(mu_0), mu_y(mu_0), mu_z(mu_0),
sig_x(0), sig_y(0), sig_z(0), pml(0),
f1(0), f2(0), f3(0), f4(0) {
}
vector_3 eps() const {
return vector_3(eps_x, eps_y, eps_z);
}
vector_3 mu() const {
return vector_3(mu_x, mu_y, mu_z);
}
vector_3 sig() const {
return vector_3(sig_x, sig_y, sig_z);
}
void assign_pml() {
if(pml == 0) {
pml = new PmlGemp();
}
}
void release_pml() {
if(pml != 0) {
delete pml;
pml = 0;
}
}
~Gemp() {
release_pml();
}
vector_3 E;
vector_3 H;
float eps_x;
float eps_y;
float eps_z;
float mu_x;
float mu_y;
float mu_z;
float sig_x;
float sig_y;
float sig_z;
PmlGemp *pml;
char f1;
char f2;
char f3;
char f4;
};
std::ostream &operator<<(std::ostream &os, const Gemp &phv) {
os << "eps_x: " << phv.eps_x << std::endl;
os << "eps_y: " << phv.eps_y << std::endl;
os << "eps_z: " << phv.eps_z << std::endl;
os << "mu_x: " << phv.mu_x << std::endl;
os << "mu_y: " << phv.mu_y << std::endl;
os << "mu_z: " << phv.mu_z << std::endl;
os << "sig_x: " << phv.sig_x << std::endl;
os << "sig_y: " << phv.sig_y << std::endl;
os << "sig_z: " << phv.sig_z << std::endl;
return os;
}
class Signal {
public:
Signal() {
}
Signal(const vector_3 &position, double time_pace, double time_begin)
: posi(position), dt(time_pace), time_begin(time_begin), sigv() {
}
Signal(const vector_3 &position, double time_pace)
: posi(position), dt(time_pace), time_begin(0), sigv() {
}
#ifdef FDTD_PYTHON_MODULE
Signal(PyObject *position, double time_pace, double time_begin)
: posi(position), dt(time_pace), time_begin(time_begin), sigv() {
}
Signal(PyObject *position, double time_pace)
: posi(position), dt(time_pace), time_begin(0), sigv() {
}
#endif
Signal subSignal(unsigned low, unsigned high) {
Signal sig(posi, dt, time_begin + low * dt);
for(unsigned i = low; i < high; i++) {
sig.pushValue(this->at(i));
}
return sig;
}
void pushValue(double vl) {
sigv.push_back(vl);
}
void setTimePace(double pace) {
this->dt = pace;
}
void setIndex(const Index3 &index) {
this->index = index;
}
double at(unsigned i) const {
return sigv.at(i);
}
double power() const {
double p = 0;
for(auto iter = sigv.begin(); iter != sigv.end(); ++iter) {
p += pow(*iter, 2) * dt;
}
return p;
}
Signal trim(double eps) {
int end;
for(int i = this->length() - 1; i >= 0; i--) {
//std::cout << i << std::endl;
if(fabs(this->at(i)) > eps) {
end = i + 1;
break;
}
}
//std::cout << end << std::endl;
return this->subSignal(0, end);
}
double meanExcessDelay() {
int f_delay;
double total = 0, den = 0, weigh = 0;
double tau_m;
for(int i = 0; i < this->length(); i++) {
if(this->at(i) != 0) {
f_delay = i;
break;
}
}
//std::cout << f_delay << std::endl;
for(int i = f_delay; i < this->length(); i++) {
weigh = pow(this->at(i), 2);
total += dt * (i - f_delay) * weigh;
den += weigh;
}
return total / den;
}
double RMS_DelaySpread() {
int f_delay;
double total = 0, den = 0, weigh = 0;
double tau_m;
for(int i = 0; i < this->length(); i++) {
if(this->at(i) != 0) {
f_delay = i;
break;
}
}
//std::cout << f_delay << std::endl;
for(int i = f_delay; i < this->length(); i++) {
weigh = pow(this->at(i), 2);
total += dt * (i - f_delay) * weigh;
den += weigh;
}
tau_m = total / den;
total = 0;
den = 0;
for(int i = f_delay; i < this->length(); i++) {
weigh = pow(this->at(i), 2);
total += pow((dt * (i - f_delay) - tau_m), 2) * weigh;
den += weigh;
}
return sqrt(total / den);
}
int multipathNumber_10dB() {
double peak = 0;
double count = 0;
double max = 0;
double power_10db;
double power_t = 0;
std::vector<int> mark;
int max_i;
for(int i = 0; i < this->length(); i++) {
if(this->at(i) > peak) {
peak = this->at(i);
}
}
power_10db = 10 * peak;
//std::cout << power_10db << std::endl;
while(power_t < power_10db) {
for(int i = 0; i < this->length(); i++) {
if(this->at(i) > max && this->at(i) < peak) {
max = this->at(i);
max_i = i;
}
else if(this->at(i) == peak && std::count(mark.begin(), mark.end(), i) == 0) {
max = this->at(i);
max_i = i;
}
}
peak = max;
mark.push_back(max_i);
power_t = power_t + max;
max = 0;
//std::cout << power_t << std::endl;
count ++;
}
return count - 1;
}
Signal parseCIR(const Signal &pulse, double eps) {
int p = 0, n = 0;
double p_max = 0.0, s_max = 0.0, coef;
Signal cir(this->posi, this->dt, this->time_begin);
Signal temp(this->posi, this->dt, this->time_begin);
for(int i = 0; i < this->length(); i++) {
cir.pushValue(0.0);
temp.pushValue(this->at(i));
}
for(int i = 0; i < pulse.length(); i++) {
if(fabs(pulse.at(i)) > fabs(p_max)) {
p = i;
p_max = pulse.at(p);
}
}
//std::cout << p << ": " << p_max << std::endl;
do {
s_max = 0;
for(int i = 0; i < temp.length(); i++) {
if(fabs(temp.at(i)) > fabs(s_max)) {
n = i;
s_max = temp.at(i);
}
}
//std::cout << n << ": " << s_max << std::endl;
coef = s_max / p_max;
//std::cout << n << ": " << s_max << std::endl;
cir.sigv[n] = coef;
for(int i = n - p; i < n + pulse.length() - p; i++)
if(i >= 0 && i < this->length()) {
temp.sigv[i] = temp.sigv[i] - coef * pulse.at(p + i - n);
}
} while(fabs(s_max) > eps);
return cir;
}
//double at(double t) const {
// unsigned i = round((t - time_begin) / dt);
// return this->at(i);
//}
double timeBegin() const {
return time_begin;
}
double timeEnd() const {
return time_begin + dt * sigv.size();
}
double timePace() const {
return dt;
}
bool timeValid(double t) const {
return (t >= time_begin && t <= timeEnd());
}
double timeValue(double t) const {
return sigv.at((int)((t - time_begin) / dt));
}
vector_3 position() const {
return posi;
}
const Index3 &index3() const {
return index;
}
unsigned length() const {
return sigv.size();
}