38 |
* E-mail : |
* E-mail : |
39 |
* |
* |
40 |
*******************************************************************/ |
*******************************************************************/ |
41 |
|
#include <iostream> |
42 |
#include "discsignal.hh" |
#include "discsignal.hh" |
43 |
|
|
44 |
void DiscSignal::add ( ) |
DiscSignal &DiscSignal::add ( DiscSignal &src1, DiscSignal &src2 ) |
45 |
{ |
{ |
46 |
|
int it; |
47 |
|
int length = maximum((src1.length()), (src2.length())); |
48 |
|
double *data = new double[length + 1]; |
49 |
|
DiscSignal *res = new DiscSignal(data, length); |
50 |
|
|
51 |
|
for (it = 0; it < length; ++it) |
52 |
|
(*res)[it] = src1[it] + src2[it]; |
53 |
|
res[it] = '\0'; |
54 |
|
return *res; |
55 |
|
} |
56 |
|
|
57 |
|
DiscSignal &DiscSignal::mult ( DiscSignal &src1, DiscSignal &src2 ) |
58 |
|
{ |
59 |
|
int it; |
60 |
|
int length = maximum((src1.length()), (src2.length())); |
61 |
|
double *data = new double[length + 1]; |
62 |
|
DiscSignal *res = new DiscSignal(data, length); |
63 |
|
|
64 |
|
for (it = 0; it < length; ++it) |
65 |
|
(*res)[it] = src1[it] * src2[it]; |
66 |
|
res[it] = '\0'; |
67 |
|
return *res; |
68 |
} |
} |
69 |
|
|
70 |
void DiscSignal::mult ( ) |
DiscSignal &DiscSignal::concat ( DiscSignal &src1, DiscSignal &src2 ) |
71 |
{ |
{ |
72 |
|
int it1, it2; |
73 |
|
int length = src1.length() + src2.length(); |
74 |
|
double *data = new double[length + 1]; |
75 |
|
DiscSignal *res = new DiscSignal(data, length); |
76 |
|
for (it1 = 0; it1 < src1.length(); ++it1) |
77 |
|
(*res)[it1] = src1[it1]; |
78 |
|
for (it2 = 0; it2 < src2.length(); ++it2, ++it1) |
79 |
|
(*res)[it1] = src2[it2]; |
80 |
|
res[it1] = '\0'; |
81 |
|
return *res; |
82 |
} |
} |
83 |
|
|
84 |
void DiscSignal::concat ( ) |
DiscSignal &DiscSignal::haming (DiscSignal &src) |
85 |
{ |
{ |
86 |
|
int it; |
87 |
|
int length = src.length(); |
88 |
|
double *data = new double[length + 1]; |
89 |
|
DiscSignal *res = new DiscSignal(data, length); |
90 |
|
for (it = 0; it < src.length(); ++it) |
91 |
|
(*res)[it] = src[it] * (0.54 - 0.46 * cos(2 * PI * it / src.length())); |
92 |
|
res[it] = '\0'; |
93 |
|
return *res; |
94 |
} |
} |
95 |
|
|
96 |
void DiscSignal::Haming ( ) |
DiscSignal &DiscSignal::truncate ( DiscSignal &src, const int begin, const int end ) |
97 |
{ |
{ |
98 |
|
assert (end < begin); |
99 |
|
int it; |
100 |
|
int length = end - begin; |
101 |
|
double *data = new double[length + 1]; |
102 |
|
DiscSignal *res = new DiscSignal(data, length); |
103 |
|
for (it = 0; it < length; ++it) |
104 |
|
(*res)[it] = src[begin + it]; |
105 |
|
res[it] = '\0'; |
106 |
|
return *res; |
107 |
} |
} |
108 |
|
|
109 |
void DiscSignal::truncate ( ) |
int DiscSignal::min ( DiscSignal &src ) |
110 |
{ |
{ |
111 |
|
double min = DBL_MAX; |
112 |
|
int res = -1; |
113 |
|
|
114 |
|
for (int i = 0; src[i]; ++i) |
115 |
|
if (src[i] < min) |
116 |
|
{ |
117 |
|
res = i; |
118 |
|
min = src[i]; |
119 |
|
} |
120 |
|
return res; |
121 |
|
} |
122 |
|
|
123 |
|
double DiscSignal::min_val ( DiscSignal &src ) |
124 |
|
{ |
125 |
|
double min = DBL_MAX; |
126 |
|
|
127 |
|
for (int i = 0; src[i]; ++i) |
128 |
|
if (src[i] < min) |
129 |
|
min = src[i]; |
130 |
|
return min; |
131 |
} |
} |
132 |
|
|
133 |
void DiscSignal::min ( ) |
int DiscSignal::max ( DiscSignal &src ) |
134 |
{ |
{ |
135 |
|
double max = DBL_MIN; |
136 |
|
int res = -1; |
137 |
|
|
138 |
|
for (int i = 0; src[i]; ++i) |
139 |
|
if ( src[i] > max ) |
140 |
|
{ |
141 |
|
res = i; |
142 |
|
max = src[i]; |
143 |
|
} |
144 |
|
return res; |
145 |
} |
} |
146 |
|
|
147 |
void DiscSignal::max ( ) |
double DiscSignal::max_val ( DiscSignal &src ) |
148 |
{ |
{ |
149 |
|
double max = DBL_MIN; |
150 |
|
|
151 |
|
for (int i = 0; src[i]; ++i) |
152 |
|
if (src[i] > max ) |
153 |
|
max = src[i]; |
154 |
|
return max; |
155 |
} |
} |
156 |
|
|