3 * Copyright 2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <gcp_fft_1d_r2.h>
30 init_jd(gc_job_desc *jd,
32 unsigned log2_fft_length,
34 std::complex<float> *out,
35 const std::complex<float> *in,
36 const std::complex<float> *W)
38 jd->proc_id = proc_id;
43 jd->input.arg[0].u32 = log2_fft_length;
44 jd->input.arg[1].u32 = forward;
45 unsigned int fft_length = 1 << log2_fft_length;
47 jd->eaa.arg[0].ea_addr = ptr_to_ea(out);
48 jd->eaa.arg[0].direction = GCJD_DMA_PUT;
49 jd->eaa.arg[0].put_size = sizeof(std::complex<float>) * fft_length;
51 jd->eaa.arg[1].ea_addr = ptr_to_ea(const_cast<std::complex<float>*>(in));
52 jd->eaa.arg[1].direction = GCJD_DMA_GET;
53 jd->eaa.arg[1].get_size = sizeof(std::complex<float>) * fft_length;
55 jd->eaa.arg[2].ea_addr = ptr_to_ea(const_cast<std::complex<float>*>(W));
56 jd->eaa.arg[2].direction = GCJD_DMA_GET;
57 jd->eaa.arg[2].get_size = sizeof(std::complex<float>) * fft_length / 4;
62 gcp_fft_1d_r2_submit(gc_job_manager_sptr mgr,
63 unsigned int log2_fft_length,
65 std::complex<float> *out,
66 const std::complex<float> *in,
67 const std::complex<float> *W)
69 unsigned int fft_length = 1 << log2_fft_length;
70 if (fft_length > 4096)
71 throw std::invalid_argument("fft_length > 4096");
73 if ((intptr_t)out & 0xf)
74 throw gc_bad_align("out");
75 if ((intptr_t)in & 0xf)
76 throw gc_bad_align("in");
77 if ((intptr_t)W & 0xf)
78 throw gc_bad_align("W");
80 gc_proc_id_t fft_id = mgr->lookup_proc("fft_1d_r2");
81 gc_job_desc *jd = mgr->alloc_job_desc();
82 init_jd(jd, fft_id, log2_fft_length, forward, out, in, W);
83 if (!mgr->submit_job(jd)){
84 gc_job_status_t s = jd->status;
85 mgr->free_job_desc(jd);
86 throw gc_bad_submit("fft_1d_r2", s);
92 gcp_fft_1d_r2_forward_twiddle(unsigned int log2_fft_length, std::complex<float> *W)
94 unsigned int n = 1 << log2_fft_length;
98 for (unsigned i=1; i < n/4; i++){
99 W[i].real() = cos(i * 2*M_PI/n);
100 W[n/4 - i].imag() = -W[i].real();
106 gcp_fft_1d_r2_reverse_twiddle(unsigned int log2_fft_length, std::complex<float> *W)
108 // FIXME this is wrong/insufficient. inverse is still incorrect
110 // reverse factors are the conjugate of the forward factors
111 gcp_fft_1d_r2_forward_twiddle(log2_fft_length, W);
113 unsigned int n = 1 << log2_fft_length;
114 for (unsigned i=0; i < n/4; i++)