34 #include <boost/format.hpp> 38 static unsigned int ipow(
unsigned int x,
unsigned int y) __attribute__ ((unused));
39 static unsigned int ipow(
unsigned int x,
unsigned int y)
45 for(i = 0; i < y; i++) {
53 unsigned int filter_length) :
58 M = inout_buffer_length;
61 N = 4 * filter_length;
62 while(
N < (
M + filter_length)) {
71 std::complex<float> htu[
N], htl[
N];
76 HTu_filter = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) *
N);
77 HTl_filter = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) *
N);
78 Pass_U_filter = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) *
N);
79 Pass_L_filter = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) *
N);
80 fftwf_plan HTu_plan = fftwf_plan_dft_1d(
N,
81 (fftwf_complex *) htu, (fftwf_complex *)
HTu_filter,
82 FFTW_FORWARD, FFTW_ESTIMATE);
83 if(HTu_plan == NULL) {
84 throw SoDaException(
"Hilbert had trouble creating HT upper plan...\n");
86 fftwf_plan HTl_plan = fftwf_plan_dft_1d(
N,
87 (fftwf_complex *) htl, (fftwf_complex *)
HTl_filter,
88 FFTW_FORWARD, FFTW_ESTIMATE);
89 if(HTl_plan == NULL) {
90 throw SoDaException(
"Hilbert had trouble creating HT lower plan...\n");
95 for(i = 0; i <
N; i++) {
96 htu[i] = htl[i] = std::complex<float>(0.0, 0.0);
99 for(i = 0, j = (
Q / 2); i < (
Q / 2); i++) {
101 htu[j + i] = std::complex<float>(1.0 / ((float) i), 0.0);
102 htu[j - i] = std::complex<float>(-1.0 / ((float) i), 0.0);
103 htl[j + i] = std::complex<float>(-1.0 / ((float) i), 0.0);
104 htl[j - i] = std::complex<float>(1.0 / ((float) i), 0.0);
107 fftwf_execute(HTu_plan);
108 fftwf_execute(HTl_plan);
110 fftwf_destroy_plan(HTu_plan);
111 fftwf_destroy_plan(HTl_plan);
114 fftwf_plan dly_plan = fftwf_plan_dft_1d(N,
116 FFTW_FORWARD, FFTW_ESTIMATE);
118 for(i = 0; i < N; i++) htu[i] = std::complex<float>(0.0, 0.0);
119 htu[
Q/2] = std::complex<float>(1.0, 0.0);
121 fftwf_execute(dly_plan);
122 fftwf_destroy_plan(dly_plan);
126 for(i = 0; i <
N; i++) {
127 float tumag = abs(HTu_filter[i]);
128 float tlmag = abs(HTl_filter[i]);
129 float pmag = abs(Pass_U_filter[i]);
135 if (uadj > 2) uadj = 1.0;
136 if (ladj > 2) ladj = 1.0;
139 Pass_U_filter[i] = uadj * Pass_U_filter[i];
147 for(i = 0; i <
N; i++) {
148 hmag += HTu_filter[i].real() * HTu_filter[i].real()
149 + HTu_filter[i].imag() * HTu_filter[i].imag();
150 pmag += Pass_U_filter[i].real() * Pass_U_filter[i].real()
151 + Pass_U_filter[i].imag() * Pass_U_filter[i].imag();
155 fft_I_input = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) * (N + 128));
156 fft_Q_input = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) * (N + 128));
157 fft_I_output = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) * (N + 128));
158 fft_Q_output = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) * (N + 128));
159 ifft_I_input = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) * (N + 128));
160 ifft_Q_input = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) * (N + 128));
161 ifft_I_output = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) * (N + 128));
162 ifft_Q_output = (std::complex<float> *) fftwf_malloc(
sizeof(std::complex<float>) * (N + 128));
167 FFTW_FORWARD, FFTW_ESTIMATE);
169 throw SoDaException(
"Hilbert had trouble creating forward I plan...\n");
175 FFTW_FORWARD, FFTW_ESTIMATE);
177 throw SoDaException(
"Hilbert had trouble creating forward Q plan...\n");
182 FFTW_BACKWARD, FFTW_ESTIMATE);
184 throw SoDaException(
"Hilbert had trouble creating backward I plan...\n");
188 FFTW_BACKWARD, FFTW_ESTIMATE);
190 throw SoDaException(
"Hilbert had trouble creating backward Q plan...\n");
193 for(i = 0; i <=
Q-1; i++) {
194 fft_I_input[i] = 0.0;
195 fft_Q_input[i] = 0.0;
206 std::complex<float> * outbuf,
207 bool pos_sided,
float gain)
211 std::complex<float> *HT_F;
212 std::complex<float> *PA_F;
225 memcpy(&(
fft_I_input[
Q-1]), inbuf,
sizeof(std::complex<float>) *
M);
231 memcpy(
fft_I_input, &(inbuf[1 + (M -
Q)]),
sizeof(std::complex<float>) * (
Q - 1));
234 for(i = 0; i <
N; i++) {
246 for(i = 0, j =
Q-1; i <
M; i++, j++) {
260 std::complex<float> * outbuf,
261 bool pos_sided,
float gain)
268 std::complex<float> cinbuf[
M];
272 for(i = 0; i <
M; i++) {
273 cinbuf[i] = std::complex<float>(inbuf[i], 0.0);
277 return apply(cinbuf, outbuf, pos_sided, gain);
285 std::complex<float> * outbuf,
296 for(i = 0; i <
M; i++) {
297 fft_I_input[i + (
Q-1)] = std::complex<float>(inbuf[i].real(), 0.0);
298 fft_Q_input[i + (
Q-1)] = std::complex<float>(inbuf[i].imag(), 0.0);
307 for(i = 0; i < (
Q - 1); i++) {
308 fft_I_input[i] = std::complex<float>(inbuf[i + 1 + (M -
Q)].real(), 0.0);
309 fft_Q_input[i] = std::complex<float>(inbuf[i + 1 + (M -
Q)].imag(), 0.0);
313 for(i = 0; i <
N; i++) {
325 for(i = 0, j =
Q-1; i <
M; i++, j++) {
340 for(i = 0; i <
N; i++) {
346 os << boost::format(
"%d %f %f %f %f %f %f %f %f\n")
The SoDa Exception class.