41 #define Swap(a,b) { nr_double_t t; t = a; a = b; b = t; }
45 using namespace fourier;
56 for (i = 0; i <
n; i += 2) {
58 Swap (data[j], data[i]);
59 Swap (data[j+1], data[i+1]);
62 while (m >= 2 && j >= m) {
71 nr_double_t wt, th, wr, wi, wpr, wpi, ti, tr;
75 th = isign * (2 *
M_PI / mmax);
81 for (m = 1; m < mmax; m += 2) {
82 for (i = m; i <=
n; i += istep) {
84 tr = wr * data[j] - wi * data[j-1];
85 ti = wr * data[j-1] + wi * data[j];
86 data[j] = data[
i] - tr;
87 data[j-1] = data[i-1] - ti;
91 wr = (wt = wr) * wpr - wi * wpi + wr;
92 wi = wi * wpr + wt * wpi + wi;
102 nr_double_t rep, rem, aip, aim;
103 n3 = 1 + (n2 = len + len);
106 for (j = 1; j <=
n2; j += 2) {
116 for (j = 2; j <= len; j += 2) {
118 rep = 0.5 * (r1[j] + r1[n2-j]);
119 rem = 0.5 * (r1[j] - r1[n2-j]);
120 aip = 0.5 * (r1[j+1] + r1[n3-j]);
121 aim = 0.5 * (r1[j+1] - r1[n3-j]);
125 r1[j] = r1[n2-j] = rep;
126 r2[j] = r2[n2-j] = aip;
137 int j, jj, nn = len + len;
140 for (j = 0, jj = 0; j < nn; j += 2) {
151 for (j = 0; j < nn; j += 2) {
153 r1[j+1] = r2[j+1] = 0.0;
162 int i,
n, len = var.getSize ();
166 while (size < len) size <<= 1;
170 data = (nr_double_t *) calloc (2 * size *
sizeof (nr_double_t), 1);
171 for (n = i = 0; i < len; i++, n += 2) {
172 data[
n] =
real (var (i)); data[n+1] =
imag (var (i));
179 vector res = vector (size);
180 for (n = i = 0; i <
size; i++, n += 2) {
182 if (isign < 0) res (i) /=
size;
194 int k,
n, size = 2 * len *
sizeof (nr_double_t);
195 nr_double_t * res = (nr_double_t *) calloc (size, 1);
196 nr_double_t th,
c,
s;
197 for (n = 0; n < 2 * len; n += 2) {
198 th = n *
M_PI / 2 / len;
199 for (k = 0; k < 2 * len; k += 2) {
201 s = isign *
sin (k * th);
202 res[
n] += data[k] * c + data[k+1] *
s;
203 res[n+1] += data[k+1] * c - data[k] *
s;
206 memcpy (data, res, size);
214 int k,
n, len = var.getSize ();
215 vector res = vector (len);
216 for (n = 0; n < len; n++) {
217 nr_double_t th = - isign * 2 *
M_PI * n / len;
219 for (k = 0; k < len; k++)
221 res (n) = isign < 0 ? val / (nr_double_t) len : val;
246 int i,
i1,
i2, i3, i2rev, i3rev, ip1, ip2, ip3, ifp1, ifp2;
247 int ibit, k1, k2,
n, np, nr, nt;
250 for (nt = 1, i = 0; i < nd; i++) nt *= len[i];
253 for (np = 1, i = nd - 1; i >= 0; i--) {
261 for (i2rev = 1, i2 = 1; i2 <= ip2; i2 += ip1) {
263 for (i1 = i2; i1 <= i2 + ip1 - 2; i1 += 2) {
264 for (i3 = i1; i3 <= ip3; i3 += ip2) {
265 i3rev = i2rev + i3 -
i2;
266 Swap (data[i3-1], data[i3rev-1]);
267 Swap (data[i3], data[i3rev]);
272 while (ibit >= ip1 && i2rev > ibit) {
280 nr_double_t ti, tr, wt, th, wr, wi, wpi, wpr;
284 th = isign * 2 *
M_PI / (ifp2 / ip1);
286 wpr = -2.0 * wt * wt;
290 for (i3 = 1; i3 <= ifp1; i3 += ip1) {
291 for (i1 = i3; i1 <= i3 + ip1 - 2; i1 += 2) {
292 for (i2 = i1; i2 <= ip3; i2 += ifp2) {
295 tr = wr * data[k2-1] - wi * data[k2];
296 ti = wr * data[k2] + wi * data[k2-1];
297 data[k2-1] = data[k1-1] - tr;
298 data[k2] = data[k1] - ti;
303 wr = (wt = wr) * wpr - wi * wpi + wr;
304 wi = wi * wpr + wt * wpi + wi;
319 int i,
n, len = var.getSize ();
320 vector res = vector (len);
322 for (i = 0; i < len / 2; i++) {
323 res (i) =
var (n + i);
324 res (i + n) =
var (i);
std::complex< nr_double_t > nr_complex_t
void _fft_1d(nr_double_t *, int, int isign=1)
matrix real(matrix a)
Real part matrix.
void _ifft_1d_2r(nr_double_t *, nr_double_t *, int)
void _ifft_1d(nr_double_t *, int)
qucs::vector fft_1d(qucs::vector, int isign=1)
nr_complex_t cos(const nr_complex_t z)
Compute complex cosine.
qucs::vector ifft_1d(qucs::vector)
void _fft_1d_2r(nr_double_t *, nr_double_t *, int)
void _ifft_nd(nr_double_t *, int[], int)
matrix imag(matrix a)
Imaginary part matrix.
nr_complex_t sin(const nr_complex_t z)
Compute complex sine.
Global math constants header file.
#define M_PI
Archimedes' constant ( )
void _idft_1d(nr_double_t *, int)
void _fft_nd(nr_double_t *, int[], int, int isign=1)
qucs::vector fftshift(qucs::vector)
nr_complex_t polar(const nr_double_t mag, const nr_double_t ang)
Construct a complex number using polar notation.
qucs::vector idft_1d(qucs::vector)
void _dft_1d(nr_double_t *, int, int isign=1)
qucs::vector dft_1d(qucs::vector, int isign=1)