42 |
#include <string.h> |
#include <string.h> |
43 |
#include "discsignal.hh" |
#include "discsignal.hh" |
44 |
|
|
45 |
DiscSignal &DiscSignal::add ( DiscSignal &src1, DiscSignal &src2 ) |
DiscSignal &DiscSignal::add ( DiscSignal &src ) |
46 |
{ |
{ |
47 |
int it; |
int it; |
48 |
int length = maximum((src1.length()), (src2.length())); |
int length = maximum((this->length()), (src.length())); |
49 |
double *data = new double[length + 1]; |
double *data = new double[length + 1]; |
50 |
DiscSignal *res = new DiscSignal(data, length); |
DiscSignal *res = new DiscSignal(data, length); |
51 |
|
|
52 |
for (it = 0; src1[it] && src2[it] && it < length; ++it) |
for (it = 0; (*this)[it] && src[it] && it < length; ++it) |
53 |
(*res)[it] = src1[it] + src2[it]; |
(*res)[it] = (*this)[it] + src[it]; |
54 |
if ( !src2[it] ) |
if ( !src[it] ) |
55 |
for ( ;it < length; ++it) |
for ( ;it < length; ++it) |
56 |
(*res)[it] = src1[it]; |
(*res)[it] = (*this)[it]; |
57 |
if ( !src1[it] ) |
if ( !(*this)[it] ) |
58 |
for ( ;it < length; ++it) |
for ( ;it < length; ++it) |
59 |
(*res)[it] = src2[it]; |
(*res)[it] = src[it]; |
60 |
res[it] = '\0'; |
return *res; |
61 |
|
} |
62 |
|
|
63 |
|
DiscSignal &DiscSignal::sub ( DiscSignal &src ) |
64 |
|
{ |
65 |
|
int it; |
66 |
|
int length = maximum((this->length()), (src.length())); |
67 |
|
double *data = new double[length + 1]; |
68 |
|
DiscSignal *res = new DiscSignal(data, length); |
69 |
|
|
70 |
|
for (it = 0; (*this)[it] && src[it] && it < length; ++it) |
71 |
|
(*res)[it] = (*this)[it] - src[it]; |
72 |
|
if ( !src[it] ) |
73 |
|
for ( ;it < length; ++it) |
74 |
|
(*res)[it] = (*this)[it]; |
75 |
|
if ( !(*this)[it] ) |
76 |
|
for ( ;it < length; ++it) |
77 |
|
(*res)[it] = -src[it]; |
78 |
return *res; |
return *res; |
79 |
} |
} |
80 |
|
|
122 |
return *res; |
return *res; |
123 |
} |
} |
124 |
|
|
125 |
DiscSignal &DiscSignal::hamming (DiscSignal &src) |
DiscSignal &DiscSignal::hamming () const |
126 |
{ |
{ |
127 |
int it; |
int it; |
128 |
int length = src.length(); |
int length = this->length(); |
129 |
double *data = new double[length + 1]; |
double *data = new double[length + 1]; |
130 |
DiscSignal *res = new DiscSignal(data, length); |
DiscSignal *res = new DiscSignal(data, length); |
131 |
for (it = 0; it < src.length(); ++it) |
for (it = 0; it < this->length(); ++it) |
132 |
(*res)[it] = src[it] * (0.54 - 0.46 * cos(2 * PI * it / (src.length() - 1))); |
(*res)[it] = (*this)[it] * (0.54 - 0.46 * cos(2 * PI * it / |
133 |
|
(this->length() - 1))); |
134 |
res[it] = '\0'; |
res[it] = '\0'; |
135 |
return *res; |
return *res; |
136 |
} |
} |